summaryrefslogtreecommitdiff
path: root/funcs
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2019-03-15 16:53:51 -0400
committerDave Henderson <dhenderson@gmail.com>2019-03-31 09:55:56 -0400
commit0f6bdb8654bb74283c064956cc6edbb9332647a8 (patch)
treede14080b9923cdff3adf485d2741ed4f855261e7 /funcs
parente991f3ec7d502702e176aa57247826881ea031ab (diff)
AWS STS functions
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'funcs')
-rw-r--r--funcs/aws.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/funcs/aws.go b/funcs/aws.go
index ef612055..ebc36f43 100644
--- a/funcs/aws.go
+++ b/funcs/aws.go
@@ -38,9 +38,11 @@ type Funcs struct {
meta *aws.Ec2Meta
info *aws.Ec2Info
kms *aws.KMS
+ sts *aws.STS
metaInit sync.Once
infoInit sync.Once
kmsInit sync.Once
+ stsInit sync.Once
awsopts aws.ClientOptions
}
@@ -80,6 +82,29 @@ func (a *Funcs) KMSDecrypt(ciphertext interface{}) (string, error) {
return a.kms.Decrypt(conv.ToString(ciphertext))
}
+// UserID - Gets the unique identifier of the calling entity. The exact value
+// depends on the type of entity making the call. The values returned are those
+// listed in the aws:userid column in the Principal table
+// (http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#principaltable)
+// found on the Policy Variables reference page in the IAM User Guide.
+func (a *Funcs) UserID() (string, error) {
+ a.stsInit.Do(a.initSTS)
+ return a.sts.UserID()
+}
+
+// Account - Gets the AWS account ID number of the account that owns or
+// contains the calling entity.
+func (a *Funcs) Account() (string, error) {
+ a.stsInit.Do(a.initSTS)
+ return a.sts.Account()
+}
+
+// ARN - Gets the AWS ARN associated with the calling entity
+func (a *Funcs) ARN() (string, error) {
+ a.stsInit.Do(a.initSTS)
+ return a.sts.Arn()
+}
+
func (a *Funcs) initMeta() {
if a.meta == nil {
a.meta = aws.NewEc2Meta(a.awsopts)
@@ -97,3 +122,9 @@ func (a *Funcs) initKMS() {
a.kms = aws.NewKMS(a.awsopts)
}
}
+
+func (a *Funcs) initSTS() {
+ if a.sts == nil {
+ a.sts = aws.NewSTS(a.awsopts)
+ }
+}