Skip to content

Commit

Permalink
Add more emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasfrahm committed May 17, 2021
1 parent 743aa18 commit 1ce0932
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
indent_size = 4
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Project-specific ###
.env
bin/

### Go ###
# Binaries for programs and plugins
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BIN_DIR := ./bin
TARGET := scp-action

$(BIN_DIR)/$(TARGET): main.go
@mkdir -p $(@D)
go build -o $@ $^

.PHONY: all clean

all: $(BIN_DIR)/$(TARGET)

clean:
-rm -rf $(BIN_DIR)
30 changes: 15 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ func main() {
// Parse timeout.
actionTimeout, err := time.ParseDuration(os.Getenv("ACTION_TIMEOUT"))
if err != nil {
log.Fatalf("Failed to parse action timeout: %v", err)
log.Fatalf("Failed to parse action timeout: %v", err)
}

// Stop the action if it takes longer that the specified timeout.
actionTimeoutTimer := time.NewTimer(actionTimeout)
go func() {
<-actionTimeoutTimer.C
log.Fatalf("Failed to run action: %v", errors.New("action timed out"))
log.Fatalf("Failed to run action: %v", errors.New("action timed out"))
os.Exit(1)
}()

// Parse direction.
direction := os.Getenv("DIRECTION")
if direction != DirectionDownload && direction != DirectionUpload {
log.Fatalf("Failed to parse direction: %v", errors.New("direction must be either upload or download"))
log.Fatalf("Failed to parse direction: %v", errors.New("direction must be either upload or download"))
}

// Parse timeout.
timeout, err := time.ParseDuration(os.Getenv("TIMEOUT"))
if err != nil {
log.Fatalf("Failed to parse timeout: %v", err)
log.Fatalf("Failed to parse timeout: %v", err)
}

// Parse target host.
targetHost := os.Getenv("HOST")
if targetHost == "" {
log.Fatalf("Failed to parse target host: %v", errors.New("target host must not be empty"))
log.Fatalf("Failed to parse target host: %v", errors.New("target host must not be empty"))
}

// Create signer for public key authentication method.
targetSigner, err := ssh.ParsePrivateKey([]byte(os.Getenv("KEY")))
if err != nil {
log.Fatalf("Failed to parse proxy key: %v", err)
log.Fatalf("Failed to parse target key: %v", err)
}

// Create configuration for SSH target.
Expand All @@ -83,7 +83,7 @@ func main() {
// Create signer for public key authentication method.
proxySigner, err := ssh.ParsePrivateKey([]byte(os.Getenv("PROXY_KEY")))
if err != nil {
log.Fatalf("Failed to parse proxy key: %v", err)
log.Fatalf("Failed to parse proxy key: %v", err)
}

// Create SSH config for SSH proxy.
Expand All @@ -100,25 +100,25 @@ func main() {
proxyAddress := proxyHost + ":" + os.Getenv("PROXY_PORT")
proxyClient, err := ssh.Dial("tcp", proxyAddress, proxyConfig)
if err != nil {
log.Fatalf("Failed to connect to proxy: %v", err)
log.Fatalf("Failed to connect to proxy: %v", err)
}
defer proxyClient.Close()

// Create a TCP connection to from the proxy host to the target.
netConn, err := proxyClient.Dial("tcp", targetAddress)
if err != nil {
log.Fatalf("Failed to dial to target: %v", err)
log.Fatalf("Failed to dial to target: %v", err)
}

targetConn, channel, req, err := ssh.NewClientConn(netConn, targetAddress, targetConfig)
if err != nil {
log.Fatalf("new target conn error: %v", err)
log.Fatalf("❌ Failed to connect to target: %v", err)
}

targetClient = ssh.NewClient(targetConn, channel, req)
} else {
if targetClient, err = ssh.Dial("tcp", targetAddress, targetConfig); err != nil {
log.Fatalf("Failed to connect to target: %v", err)
log.Fatalf("Failed to connect to target: %v", err)
}
}
defer targetClient.Close()
Expand Down Expand Up @@ -159,9 +159,9 @@ func Copy(client *ssh.Client) {
if len(sourceFiles) == 1 {
// Rename file if there is only one source file.
if _, err := copy(client, sourceFiles[0], targetFileOrFolder); err != nil {
log.Fatalf("Failed to %s file from remote: %v", os.Getenv("DIRECTION"), err)
log.Fatalf("Failed to %s file from remote: %v", os.Getenv("DIRECTION"), err)
}
log.Println(sourceFiles[0] + " >> " + targetFileOrFolder)
log.Println("📑 " + sourceFiles[0] + " >> " + targetFileOrFolder)

log.Println("📡 Transferred 1 file")
} else {
Expand All @@ -172,9 +172,9 @@ func Copy(client *ssh.Client) {
targetFile := path.Join(targetFileOrFolder, file)

if _, err := copy(client, sourceFile, targetFile); err != nil {
log.Fatalf("Failed to %s file from remote: %v", os.Getenv("DIRECTION"), err)
log.Fatalf("Failed to %s file from remote: %v", os.Getenv("DIRECTION"), err)
}
log.Println(sourceFile + " >> " + targetFile)
log.Println("📑 " + sourceFile + " >> " + targetFile)

transferredFiles += 1
}
Expand Down

0 comments on commit 1ce0932

Please sign in to comment.