Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
chore: add get expiry method for sts auth
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzhao98 committed Jul 22, 2019
1 parent b252c79 commit bcfc767
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions auth/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ func (a *STSAuth) GetToken(*os.File) (string, error) {
return a.token, err
}

// GetExpiry returns the expiry time of the token if it already exists. Otherwise,
// it returns a zero-valued time.Time struct and an error.
func (a *STSAuth) GetExpiry(*os.File) (time.Time, error) {
if len(a.token) > 0 {
return a.expiry, nil
}
return time.Time{}, fmt.Errorf("Expiry time not set.")
}

func (a *STSAuth) authenticate() error {
builtURL := *a.baseURL
builtURL.Path = "v2/auth/sts-identity"
Expand Down
25 changes: 25 additions & 0 deletions auth/sts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,31 @@ func TestGetTokenSTS(t *testing.T) {
}))
}

func TestGetExpiry(t *testing.T) {
Convey("A valid STSAuth", t, func() {
a, err := NewSTSAuth("https://test.example.com", "us-west-2")
So(err, ShouldBeNil)
So(a, ShouldNotBeNil)
a.expiry = time.Now()
a.token = "token"
Convey("Should return an expiry time", func() {
exp, err := a.GetExpiry(nil)
So(exp, ShouldNotBeNil)
So(err, ShouldBeNil)
})
})
Convey("An unauthenticated STSAuth", t, func() {
a, err := NewSTSAuth("https://test.example.com", "us-west-2")
So(err, ShouldBeNil)
So(a, ShouldNotBeNil)
Convey("Should return an error", func() {
exp, err := a.GetExpiry(nil)
So(exp, ShouldBeZeroValue)
So(err, ShouldNotBeNil)
})
})
}

func TestIsAuthenticated(t *testing.T) {
Convey("A valid STSAuth", t, func() {
a, err := NewSTSAuth("https://test.example.com", "us-west-2")
Expand Down

0 comments on commit bcfc767

Please sign in to comment.