-
Notifications
You must be signed in to change notification settings - Fork 1
/
saml.go
68 lines (50 loc) · 1.94 KB
/
saml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/cfn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/iam"
)
func (p *identityProvider) createSAMLProvider(event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) {
data = map[string]interface{}{"ProviderArn": p.providerARN}
req := &iam.CreateSAMLProviderInput{
Name: &p.providerName,
SAMLMetadataDocument: &p.samlMetadataDocument,
}
// handle already exist provider to implement idempotent function
_, err = p.client.CreateSAMLProvider(req)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case iam.ErrCodeEntityAlreadyExistsException:
return p.providerName, data, nil
default:
return event.PhysicalResourceID, map[string]interface{}{}, fmt.Errorf("error creating SAML provider: %v", err)
}
}
}
return p.providerName, data, nil
}
func (p *identityProvider) updateSAMLProvider(event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) {
data = map[string]interface{}{"ProviderArn": p.providerARN}
req := &iam.UpdateSAMLProviderInput{
SAMLProviderArn: &p.providerARN,
SAMLMetadataDocument: &p.samlMetadataDocument,
}
_, err = p.client.UpdateSAMLProvider(req)
if err != nil {
return event.PhysicalResourceID, map[string]interface{}{}, fmt.Errorf("error updating SAML provider: %v", err)
}
return event.PhysicalResourceID, data, nil
}
func (p *identityProvider) deleteSAMLProvider(event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) {
data = map[string]interface{}{"ProviderArn": p.providerARN}
req := &iam.DeleteSAMLProviderInput{
SAMLProviderArn: &p.providerARN,
}
_, err = p.client.DeleteSAMLProvider(req)
if err != nil {
return event.PhysicalResourceID, map[string]interface{}{}, fmt.Errorf("error deleting SAML provider: %v", err)
}
return event.PhysicalResourceID, data, nil
}