Skip to content

Commit e264c00

Browse files
committed
fix: bump version and improve util test
1 parent ca31be7 commit e264c00

File tree

9 files changed

+33
-21
lines changed

9 files changed

+33
-21
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OWNER := dnitsch
22
NAME := aws-cli-auth
3-
VERSION := v0.8.0
3+
VERSION := v0.8.1
44
REVISION := $(shell git rev-parse --short HEAD)
55

66
LDFLAGS := -ldflags="-s -w -X \"github.com/dnitsch/aws-cli-auth/cmd.Version=$(VERSION)\" -X \"github.com/dnitsch/aws-cli-auth/cmd.Revision=$(REVISION)\" -extldflags -static"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ By default the tool creates the session name - which can be audited including th
2020

2121
- As the process of re-requesting new credentials is **by design** and should be used in places where it cannot be automated - it is good idea **IF POSSIBLE** to use longer sessions for ***NON LIVE*** AWS accounts so that the prompt is not too frequent.
2222

23+
- Prior to `v0.8.0` you might be need to manually kill the `aws-cli-auth` process manually from your OS's process manager.
24+
2325
## Install
2426

2527
MacOS

cmd/clear.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func clear(cmd *cobra.Command, args []string) {
3636
}
3737
secretStore.ClearAll()
3838

39-
if err := os.Remove(util.ConfigIniFile()); err != nil {
39+
if err := os.Remove(util.ConfigIniFile("")); err != nil {
4040
util.Exit(err)
4141
}
4242

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ func init() {
4040

4141
func initConfig() {
4242
util.IsTraceEnabled = verbose
43-
if _, err := os.Stat(util.ConfigIniFile()); err != nil {
43+
if _, err := os.Stat(util.ConfigIniFile("")); err != nil {
4444
// creating a file
4545
rolesInit := []byte(fmt.Sprintf("[%s]\n", config.INI_CONF_SECTION))
46-
err := os.WriteFile(util.ConfigIniFile(), rolesInit, 0644)
46+
err := os.WriteFile(util.ConfigIniFile(""), rolesInit, 0644)
4747
cobra.CheckErr(err)
4848
}
4949
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/dnitsch/aws-cli-auth
33
go 1.17
44

55
require (
6-
github.com/aws/aws-sdk-go v1.43.12
6+
github.com/aws/aws-sdk-go v1.44.14
77
github.com/mitchellh/go-ps v1.0.0
88
github.com/pkg/errors v0.9.1
99
github.com/spf13/cobra v1.3.0
@@ -25,7 +25,7 @@ require (
2525
)
2626

2727
require (
28-
github.com/go-rod/rod v0.105.1
28+
github.com/go-rod/rod v0.106.6
2929
github.com/inconshreveable/mousetrap v1.0.0 // indirect
3030
github.com/jmespath/go-jmespath v0.4.0 // indirect
3131
github.com/spf13/pflag v1.0.5 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ github.com/avelino/slugify v0.0.0-20180501145920-855f152bd774/go.mod h1:5wi5YYOp
9191
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
9292
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
9393
github.com/aws/aws-sdk-go v1.37.32/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
94-
github.com/aws/aws-sdk-go v1.43.12 h1:wOdx6+reSDpUBFEuJDA6edCrojzy8rOtMzhS2rD9+7M=
95-
github.com/aws/aws-sdk-go v1.43.12/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
94+
github.com/aws/aws-sdk-go v1.44.14 h1:qd7/muV1rElsbvkK9D1nHUzBoDlEw2etfeo4IE82eSQ=
95+
github.com/aws/aws-sdk-go v1.44.14/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
9696
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
9797
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
9898
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
@@ -199,8 +199,8 @@ github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL9
199199
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
200200
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
201201
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
202-
github.com/go-rod/rod v0.105.1 h1:r0bNmO9siOe13lG6Vbkaak11u48rYmWGl/Hk4MJdOiE=
203-
github.com/go-rod/rod v0.105.1/go.mod h1:Wrnn6HokFHskwaIVke3ML1y/NBVp7XPIeB8eDzR9vuw=
202+
github.com/go-rod/rod v0.106.6 h1:zJorVPG7s8Xgbh7PkSySP4FNoo0OiougKaMb3j6zT6w=
203+
github.com/go-rod/rod v0.106.6/go.mod h1:xkZOchuKqTOkMOBkrzb7uJpbKZRab1haPCWDvuZkS2U=
204204
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
205205
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
206206
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@@ -584,8 +584,8 @@ github.com/werf/logboek v0.5.1/go.mod h1:1RKvhO4ulmpD5sUN/9a2XsRjt+Xh8CxJjMbmya8
584584
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
585585
github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ=
586586
github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18=
587-
github.com/ysmood/got v0.23.2 h1:U2U0vyQ/gDaawkKJZK/hyza8UUXbWCurbmazK7AcAfY=
588-
github.com/ysmood/got v0.23.2/go.mod h1:pE1l4LOwOBhQg6A/8IAatkGp7uZjnalzrZolnlhhMgY=
587+
github.com/ysmood/got v0.29.1 h1:7TNTm3Bw5kdBGXFp04qnZ9DqlZ1XS1z1JdeobeJY6Mo=
588+
github.com/ysmood/got v0.29.1/go.mod h1:pE1l4LOwOBhQg6A/8IAatkGp7uZjnalzrZolnlhhMgY=
589589
github.com/ysmood/gotrace v0.6.0 h1:SyI1d4jclswLhg7SWTL6os3L1WOKeNn/ZtzVQF8QmdY=
590590
github.com/ysmood/gotrace v0.6.0/go.mod h1:TzhIG7nHDry5//eYZDYcTzuJLYQIkykJzCRIo4/dzQM=
591591
github.com/ysmood/gson v0.7.1 h1:zKL2MTGtynxdBdlZjyGsvEOZ7dkxaY5TH6QhAbTgz0Q=

internal/auth/saml.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@ func GetSamlCreds(conf config.SamlConfig) {
2828

2929
t, err := webBrowser.GetSamlLogin(conf)
3030
if err != nil {
31-
util.Writeln("Err: %v", err)
31+
util.Exit(err)
3232
}
3333
user, err := user.Current()
3434
if err != nil {
35-
util.Writeln(err.Error())
35+
util.Exit(err)
3636
}
3737

3838
roleObj := &util.AWSRole{RoleARN: conf.BaseConfig.Role, PrincipalARN: conf.PrincipalArn, Name: util.SessionName(user.Username, config.SELF_NAME), Duration: conf.Duration}
3939

4040
awsCreds, err = LoginStsSaml(t, roleObj)
4141
if err != nil {
42-
util.Writeln("%v", err)
4342
util.Exit(err)
4443
}
4544

internal/util/helper.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ func HomeDir() string {
2424
return home
2525
}
2626

27-
func ConfigIniFile() string {
28-
return path.Join(HomeDir(), fmt.Sprintf(".%s.ini", config.SELF_NAME))
27+
func ConfigIniFile(basePath string) string {
28+
var base = ""
29+
if basePath != "" {
30+
base = basePath
31+
} else {
32+
base = HomeDir()
33+
}
34+
return path.Join(base, fmt.Sprintf(".%s.ini", config.SELF_NAME))
2935
}
3036

3137
func WriteDataDir(datadir string) {
@@ -41,6 +47,7 @@ func SetCredentials(creds *AWSCredentials, config config.SamlConfig) {
4147
if config.BaseConfig.StoreInProfile {
4248
if err := storeCredentialsInProfile(*creds, config.BaseConfig.CfgSectionName); err != nil {
4349
Traceln("Error: %s", err.Error())
50+
Exit(err)
4451
}
4552
return
4653
}
@@ -128,9 +135,10 @@ func IsValid(cred *AWSCredentials) bool {
128135
return err == nil
129136
}
130137

138+
// WriteIniSection update ini sections in own config file
131139
func WriteIniSection(role string) error {
132140
section := fmt.Sprintf("%s.%s", config.INI_CONF_SECTION, RoleKeyConverter(role))
133-
cfg, err := ini.Load(ConfigIniFile())
141+
cfg, err := ini.Load(ConfigIniFile(""))
134142
if err != nil {
135143
Writeln("Fail to read Ini file: %v", err)
136144
Exit(err)
@@ -141,15 +149,15 @@ func WriteIniSection(role string) error {
141149
return err
142150
}
143151
sct.Key("name").SetValue(role)
144-
cfg.SaveTo(ConfigIniFile())
152+
cfg.SaveTo(ConfigIniFile(""))
145153
}
146154

147155
return nil
148156
}
149157

150158
func GetAllIniSections() ([]string, error) {
151159
sections := []string{}
152-
cfg, err := ini.Load(ConfigIniFile())
160+
cfg, err := ini.Load(ConfigIniFile(""))
153161
if err != nil {
154162
return nil, err
155163
}

internal/util/helper_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package util
22

33
import (
44
"fmt"
5+
"os"
56
"testing"
67

78
"github.com/dnitsch/aws-cli-auth/internal/config"
@@ -25,8 +26,10 @@ func TestGetEntryInIni(t *testing.T) {
2526

2627
//
2728
func TestCreateEntryInIni(t *testing.T) {
29+
dir, _ := os.Getwd()
30+
cfg, err := ini.Load(ConfigIniFile(dir))
31+
// config.INI_CONF_SECTION = "unitTestRole"
2832

29-
cfg, err := ini.Load(ConfigIniFile())
3033
if err != nil {
3134
Writeln("Fail to read Ini file: %v", err)
3235
Exit(err)

0 commit comments

Comments
 (0)