Skip to content

Commit

Permalink
use default region in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas.labarussias committed Jul 27, 2020
1 parent 09475ad commit c173a9c
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 10 deletions.
8 changes: 8 additions & 0 deletions dist/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


## Changelog

09475ad Merge pull request #4 from claranet/fix-forced-region
5d29af5 fix override of region
9a68700 fix wrong env var

4 changes: 4 additions & 0 deletions dist/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fe120ec1502c02a1cf1b14989c40176dffaba226e32f38886e1b817ad11c2042 sshm_1.2.1_Linux_i386.tar.gz
6fe0a6e1ce32bbb750446a54ec4e4c1522e4bc1af764eac276d0a5327f3ef24d sshm_1.2.1_Linux_x86_64.tar.gz
509fb2a4e7df20c369d984581cf4cde753a5c54aaed94b6e9a5cf8775767acdf sshm_1.2.1_Darwin_x86_64.tar.gz
bf8e072508d34fde28eda11b533e3c6bd1730402d3044cebd989ec36513f71a3 sshm_1.2.1_Darwin_i386.tar.gz
77 changes: 77 additions & 0 deletions dist/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
project_name: sshm
release:
github:
owner: claranet
name: sshm
name_template: '{{.Tag}}'
scoop:
name: sshm
commit_author:
name: goreleaserbot
email: goreleaser@carlosbecker.com
builds:
- id: sshm
goos:
- linux
- darwin
goarch:
- amd64
- "386"
goarm:
- "6"
targets:
- linux_amd64
- linux_386
- darwin_amd64
- darwin_386
dir: .
main: .
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
-X main.builtBy=goreleaser
binary: sshm
env:
- CGO_ENABLED=0
lang: go
archives:
- id: default
builds:
- sshm
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm
}}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
replacements:
"386": i386
amd64: x86_64
darwin: Darwin
linux: Linux
windows: Windows
format: tar.gz
files:
- licence*
- LICENCE*
- license*
- LICENSE*
- readme*
- README*
- changelog*
- CHANGELOG*
snapshot:
name_template: '{{ .Tag }}-next'
checksum:
name_template: checksums.txt
algorithm: sha256
changelog:
filters:
exclude:
- '^docs:'
- '^test:'
sort: asc
dist: dist
env_files:
github_token: ~/.config/goreleaser/github_token
gitlab_token: ~/.config/goreleaser/gitlab_token
gitea_token: ~/.config/goreleaser/gitea_token
github_urls:
download: https://github.com
gitlab_urls:
download: https://gitlab.com
Binary file added dist/sshm_1.2.1_Darwin_i386.tar.gz
Binary file not shown.
Binary file added dist/sshm_1.2.1_Darwin_x86_64.tar.gz
Binary file not shown.
Binary file added dist/sshm_1.2.1_Linux_i386.tar.gz
Binary file not shown.
Binary file added dist/sshm_1.2.1_Linux_x86_64.tar.gz
Binary file not shown.
29 changes: 19 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"regexp"
Expand Down Expand Up @@ -60,24 +61,32 @@ func main() {
*profile = selectProfile(p)
}
}
if *region == "" {
if os.Getenv("AWS_REGION") != "" {
*region = os.Getenv("AWS_REGION")
} else if os.Getenv("AWS_DEFAULT_REGION") != "" {
*region = os.Getenv("AWS_DEFAULT_PROFILE")
} else {
*region = "eu-west-1"
}
}

// Create session (credentials from ~/.aws/config)
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable, //enable use of ~/.aws/config
AssumeRoleTokenProvider: stscreds.StdinTokenProvider, //ask for MFA if needed
Profile: string(*profile),
Config: aws.Config{Region: aws.String(*region)},
// Config: aws.Config{Region: aws.String(*region)},
}))

R:
switch {
case *region != "":
sess.Config.Region = aws.String(*region)
case os.Getenv("AWS_REGION") != "":
sess.Config.Region = aws.String(os.Getenv("AWS_REGION"))
case os.Getenv("AWS_DEFAULT_REGION") != "":
sess.Config.Region = aws.String(os.Getenv("AWS_DEFAULT_REGION"))
case *sess.Config.Region != "":
break R
default:
sess.Config.Region = aws.String("eu-west-1")
}

fmt.Println(*sess.Config.Region)
os.Exit(0)

if *instance != "" {
startSSH(*instance, region, profile, portNumber, localPortNumber, source, destination, sess)
} else {
Expand Down

0 comments on commit c173a9c

Please sign in to comment.