Skip to content

Commit

Permalink
Merge pull request #1010 from synfinatic/fix-time-cmd
Browse files Browse the repository at this point in the history
Fix crash with `time` command
  • Loading branch information
synfinatic authored Jul 30, 2024
2 parents 647bc5f + 1ec6206 commit 11478d8
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 70 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [v2.0.0] - ????-??-??

### Bugs

* Fix fatal error with `time` command #1008

### Changes

* No longer show help for sub-commands by default
Expand Down Expand Up @@ -761,7 +767,8 @@

Initial release

[Unreleased]: https://github.com/synfinatic/aws-sso-cli/compare/v1.17.0...main
[Unreleased]: https://github.com/synfinatic/aws-sso-cli/compare/v2.0.0...main
[v2.0.0]: https://github.com/synfinatic/aws-sso-cli/compare/v2.0.0...v1.17.0
[v1.17.0]: https://github.com/synfinatic/aws-sso-cli/releases/tag/v1.17.0
[v1.16.1]: https://github.com/synfinatic/aws-sso-cli/releases/tag/v1.16.1
[v1.16.0]: https://github.com/synfinatic/aws-sso-cli/releases/tag/v1.16.0
Expand Down
8 changes: 0 additions & 8 deletions internal/ecs/server/testdata/config.ssl

This file was deleted.

2 changes: 1 addition & 1 deletion internal/ecs/server/testdata/gen_certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keyUsage=digitalSignature
extendedKeyUsage=serverAuth
EOF

openssl req -x509 -out localhost.crt -keyout localhost.key \
openssl req -x509 -out localhost.crt -keyout localhost.key -days 3065 \
-newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config config.ssl

rm config.ssl
32 changes: 16 additions & 16 deletions internal/ecs/server/testdata/localhost.crt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDFTCCAf2gAwIBAgIUaCLt3LBmowSA1M5l18uClR6gEowwDQYJKoZIhvcNAQEL
BQAwFDESMBAGA1UEAwwJbG9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BgNVHREE
EzARgglsb2NhbGhvc3SHBH8AAAEwCwYDVR0PBAQDAgeAMBMGA1UdJQQMMAoGCCsG
AQUFBwMBMB0GA1UdDgQWBBRdOEFXAt/YgKN/7K/CFkOavjXmDTANBgkqhkiG9w0B
AQsFAAOCAQEAcAbC/5tr69pLAJrqMnMsnwxFw+N/1R23w52iU53N7fIt1Sxbjm0m
uMwGtbZUIwrjEU/rOkvOxVriWy+MS3Jdv87rM3XfXA6H152rsdLU+Gq5EWICgxf6
5dzBpKYq3lJ2xvCqGKFFpPDSji9gs836CNyEsBiAiZZrk+BXc7htJI4htQNIBx+G
fiSKTpXGSJgxlTZ30gtiCQeHtqNMHJwwD5uygjcE84lC9HWmCKFOIeMv14jb5bD2
8CLN1diSoIe14K4O4jLCmauOVCkpGc2yLM8Vr/cSLXoIDRVr92y/JAqH7ojZ22mx
J+JADQUtWA1QorM5BSqpx+V1fRPNqJ603A==
AQUFBwMBMB0GA1UdDgQWBBQP6i7LzlC037icQfsUG7nQ33YBDTANBgkqhkiG9w0B
AQsFAAOCAQEAx0Hg2QKIfyLyXQXDeOPYhYWul1eF6Zmf4K2oGGoHydrAeCTPn2N+
PZtfhSvvHCAoxkKaHwL4OfwF8HEK+JPVGAnvobBWudymcu7oWxuSd6cTKIJ65bWl
Ms0XZMFmC3lj922Cf3ncFvb4WlCWUK4fGZoRzIDDD1oySWZaFPLrFpFdC3oOPtoE
aboycKPkVNP08MdOxj56tm7FaHw7KlOGZrT/tniwiXLal42KhuJjEact5r9i6ThN
mSjKxrbkUu5MR3Pf03ckXLecVEXYPjPOzxRJJK2als71DDqCUXWU32J1zOJqPpGN
2AHH0K5+K7/wyQ62pjVhSlj30FqKP4yt1w==
-----END CERTIFICATE-----
52 changes: 26 additions & 26 deletions internal/ecs/server/testdata/localhost.key
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIB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z9cEpqiIZsPFaYDmD+yygl+r
LsTUuAPYRrjFw8ixKS/QtQZ2
-----END PRIVATE KEY-----
3 changes: 1 addition & 2 deletions internal/sso/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ import (
)

const (
AWS_SSO_SESSION_EXPIRATION_FORMAT = "2006-01-02 15:04:05 -0700 MST"
NIX_STORE_PREFIX = "/nix/store/"
NIX_STORE_PREFIX = "/nix/store/"
)

type Settings struct {
Expand Down
30 changes: 15 additions & 15 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func ParseRoleARN(arn string) (int64, string, error) {
accountid = s[4]
s = strings.Split(s[5], "/")
if len(s) != 2 {
return 0, "", fmt.Errorf("Unable to parse ARN: %s", arn)
return 0, "", fmt.Errorf("unable to parse ARN: %s", arn)
}
role = s[1]
default:
return 0, "", fmt.Errorf("Unable to parse ARN: %s", arn)
return 0, "", fmt.Errorf("unable to parse ARN: %s", arn)
}

aId, err := strconv.ParseInt(accountid, 10, 64)
if err != nil {
return 0, "", fmt.Errorf("Unable to parse ARN: %s", arn)
return 0, "", fmt.Errorf("unable to parse ARN: %s", arn)
}
if aId < 0 {
return 0, "", fmt.Errorf("Invalid AccountID: %d", aId)
return 0, "", fmt.Errorf("invalid AccountID: %d", aId)
}
return aId, role, nil
}
Expand All @@ -97,7 +97,7 @@ func ParseUserARN(arn string) (int64, string, error) {
func MakeRoleARN(account int64, name string) string {
a, err := AccountIdToString(account)
if err != nil {
log.WithError(err).Panicf("Unable to MakeRoleARN")
log.WithError(err).Panicf("unable to MakeRoleARN")
}
return fmt.Sprintf("arn:aws:iam::%s:role/%s", a, name)
}
Expand All @@ -106,7 +106,7 @@ func MakeRoleARN(account int64, name string) string {
func MakeUserARN(account int64, name string) string {
a, err := AccountIdToString(account)
if err != nil {
log.WithError(err).Panicf("Unable to MakeUserARN")
log.WithError(err).Panicf("unable to MakeUserARN")
}
return fmt.Sprintf("arn:aws:iam::%s:user/%s", a, name)
}
Expand All @@ -115,7 +115,7 @@ func MakeUserARN(account int64, name string) string {
func MakeRoleARNs(account, name string) string {
x, err := AccountIdToInt64(account)
if err != nil {
log.WithError(err).Panicf("Unable to AccountIdToInt64 in MakeRoleARNs")
log.WithError(err).Panicf("unable to AccountIdToInt64 in MakeRoleARNs")
}

a, _ := AccountIdToString(x)
Expand All @@ -129,27 +129,27 @@ func EnsureDirExists(filename string) error {
f, err := os.Open(storeDir)
if os.IsNotExist(err) {
if err := os.MkdirAll(storeDir, 0700); err != nil {
return fmt.Errorf("Unable to create %s: %s", storeDir, err.Error())
return fmt.Errorf("unable to create %s: %s", storeDir, err.Error())
}
return nil
} else if err != nil {
return err
}
info, err := f.Stat()
if err != nil {
return fmt.Errorf("Unable to stat %s: %s", storeDir, err.Error())
return fmt.Errorf("unable to stat %s: %s", storeDir, err.Error())
}
if !info.IsDir() {
return fmt.Errorf("%s exists and is not a directory!", storeDir)
return fmt.Errorf("%s exists and is not a directory", storeDir)
}
return nil
}

// ParseTimeString converts a standard time string to Unix Epoch
// ParseTimeString converts a standard RFC3339 time string to Unix Epoch
func ParseTimeString(t string) (int64, error) {
i, err := time.Parse("2006-01-02 15:04:05 -0700 MST", t)
i, err := time.Parse(time.RFC3339, t)
if err != nil {
return 0, fmt.Errorf("Unable to parse %s: %s", t, err.Error())
return 0, fmt.Errorf("unable to parse %s: %s", t, err.Error())
}
return i.Unix(), nil
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func TimeRemain(expires int64, space bool) (string, error) {
// AccountIdToString returns a string version of AWS AccountID
func AccountIdToString(a int64) (string, error) {
if a < 0 || a > MAX_AWS_ACCOUNTID {
return "", fmt.Errorf("Invalid AWS AccountId: %d", a)
return "", fmt.Errorf("invalid AWS AccountId: %d", a)
}
return fmt.Sprintf("%012d", a), nil
}
Expand All @@ -198,7 +198,7 @@ func AccountIdToInt64(a string) (int64, error) {
return 0, err
}
if x < 0 {
return 0, fmt.Errorf("Invalid AWS AccountId: %s", a)
return 0, fmt.Errorf("invalid AWS AccountId: %s", a)
}
return x, nil
}
Expand Down
13 changes: 12 additions & 1 deletion internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestUtilsSuite(t *testing.T) {

func (suite *UtilsTestSuite) TestParseRoleARN() {
t := suite.T()
t.Parallel()

a, r, err := ParseRoleARN("arn:aws:iam::11111:role/Foo")
assert.NoError(t, err)
Expand Down Expand Up @@ -84,6 +85,7 @@ func (suite *UtilsTestSuite) TestParseRoleARN() {

func (suite *UtilsTestSuite) TestMakeRoleARN() {
t := suite.T()
t.Parallel()

assert.Equal(t, "arn:aws:iam::000000011111:role/Foo", MakeRoleARN(11111, "Foo"))
assert.Equal(t, "arn:aws:iam::000000711111:role/Foo", MakeRoleARN(711111, "Foo"))
Expand All @@ -94,6 +96,7 @@ func (suite *UtilsTestSuite) TestMakeRoleARN() {

func (suite *UtilsTestSuite) TestMakeUserARN() {
t := suite.T()
t.Parallel()

assert.Equal(t, "arn:aws:iam::000000011111:user/Foo", MakeUserARN(11111, "Foo"))
assert.Equal(t, "arn:aws:iam::000000711111:user/Foo", MakeUserARN(711111, "Foo"))
Expand All @@ -104,6 +107,7 @@ func (suite *UtilsTestSuite) TestMakeUserARN() {

func (suite *UtilsTestSuite) TestMakeRoleARNs() {
t := suite.T()
t.Parallel()

assert.Equal(t, "arn:aws:iam::000000011111:role/Foo", MakeRoleARNs("11111", "Foo"))
assert.Equal(t, "arn:aws:iam::000000711111:role/Foo", MakeRoleARNs("711111", "Foo"))
Expand All @@ -115,6 +119,7 @@ func (suite *UtilsTestSuite) TestMakeRoleARNs() {

func (suite *UtilsTestSuite) TestEnsureDirExists() {
t := suite.T()
t.Parallel()

defer os.RemoveAll("./does_not_exist_dir")
assert.NoError(t, EnsureDirExists("./testdata/role_tags.yaml"))
Expand All @@ -133,6 +138,7 @@ func (suite *UtilsTestSuite) TestEnsureDirExists() {

func (suite *UtilsTestSuite) TestGetHomePath() {
t := suite.T()
t.Parallel()

assert.Equal(t, "/", GetHomePath("/"))
assert.Equal(t, ".", GetHomePath("."))
Expand All @@ -146,6 +152,7 @@ func (suite *UtilsTestSuite) TestGetHomePath() {

func (suite *UtilsTestSuite) TestAccountToString() {
t := suite.T()
t.Parallel()

a, err := AccountIdToString(0)
assert.NoError(t, err)
Expand All @@ -171,6 +178,7 @@ func (suite *UtilsTestSuite) TestAccountToString() {

func (suite *UtilsTestSuite) TestAccountToInt64() {
t := suite.T()
t.Parallel()

_, err := AccountIdToInt64("")
assert.Error(t, err)
Expand All @@ -195,8 +203,9 @@ func (suite *UtilsTestSuite) TestAccountToInt64() {

func (suite *UtilsTestSuite) TestParseTimeString() {
t := suite.T()
t.Parallel()

x, e := ParseTimeString("1970-01-01 00:00:00 +0000 GMT")
x, e := ParseTimeString("1970-01-01T00:00:00Z")
assert.NoError(t, e)
assert.Equal(t, int64(0), x)

Expand All @@ -206,6 +215,7 @@ func (suite *UtilsTestSuite) TestParseTimeString() {

func (suite *UtilsTestSuite) TestTimeRemain() {
t := suite.T()
t.Parallel()

x, e := TimeRemain(0, false)
assert.NoError(t, e)
Expand Down Expand Up @@ -246,6 +256,7 @@ func (suite *UtilsTestSuite) TestTimeRemain() {
}

func TestStrListContains(t *testing.T) {
t.Parallel()
x := []string{"yes", "no"}
assert.True(t, StrListContains("yes", x))
assert.False(t, StrListContains("nope", x))
Expand Down

0 comments on commit 11478d8

Please sign in to comment.