-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new/appcreds: added NewWithOptions (#74)
Also add option to define the max issued token validity
- Loading branch information
1 parent
d8f3a2a
commit b49628f
Showing
5 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package appcreds | ||
|
||
import "time" | ||
|
||
type config struct { | ||
subnets []string | ||
maxValidity time.Duration | ||
} | ||
|
||
func newConfig() config { | ||
return config{} | ||
} | ||
|
||
// An Option can be used to configure a new appcred. | ||
type Option func(*config) | ||
|
||
// OptionSubnets configures the appcred to only | ||
// work when used from one of the provided subnet. | ||
func OptionSubnets(subnets []string) Option { | ||
return func(c *config) { | ||
c.subnets = subnets | ||
} | ||
} | ||
|
||
// OptionMaxValidity configures the appcred to only capable | ||
// of delivering token with the provided max validity. | ||
func OptionMaxValidity(max time.Duration) Option { | ||
return func(c *config) { | ||
c.maxValidity = max | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package appcreds | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestOptions(t *testing.T) { | ||
|
||
Convey("calling newConfig should work", t, func() { | ||
cfg := newConfig() | ||
So(cfg.subnets, ShouldBeNil) | ||
So(cfg.maxValidity, ShouldEqual, 0) | ||
}) | ||
|
||
Convey("calling OptionSubnets should work", t, func() { | ||
cfg := newConfig() | ||
OptionSubnets([]string{"1.2.3.4/4"})(&cfg) | ||
So(cfg.subnets, ShouldResemble, []string{"1.2.3.4/4"}) | ||
}) | ||
|
||
Convey("calling OptionMaxValidity should work", t, func() { | ||
cfg := newConfig() | ||
OptionMaxValidity(3 * time.Minute)(&cfg) | ||
So(cfg.maxValidity, ShouldEqual, 3*time.Minute) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters