-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathschema_identity.go
61 lines (52 loc) · 1.56 KB
/
schema_identity.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
package octopusdeploy
import (
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandIdentities(identities []interface{}) []octopusdeploy.Identity {
expandedIdentities := make([]octopusdeploy.Identity, 0, len(identities))
for _, identity := range identities {
if identity != nil {
rawIdentity := identity.(map[string]interface{})
identityProviderName := ""
if rawIdentity["provider"] != nil {
identityProviderName = rawIdentity["provider"].(string)
}
i := octopusdeploy.Identity{
IdentityProviderName: identityProviderName,
Claims: expandIdentityClaims(rawIdentity["claim"].(*schema.Set).List()),
}
expandedIdentities = append(expandedIdentities, i)
}
}
return expandedIdentities
}
func flattenIdentities(identities []octopusdeploy.Identity) []interface{} {
if identities == nil {
return nil
}
flattenedIdentities := make([]interface{}, len(identities))
for i, identity := range identities {
rawIdentity := map[string]interface{}{
"provider": identity.IdentityProviderName,
}
if identity.Claims != nil {
rawIdentity["claim"] = flattenIdentityClaims(identity.Claims)
}
flattenedIdentities[i] = rawIdentity
}
return flattenedIdentities
}
func getIdentitySchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"provider": {
Optional: true,
Type: schema.TypeString,
},
"claim": {
Optional: true,
Elem: &schema.Resource{Schema: getIdentityClaimSchema()},
Type: schema.TypeSet,
},
}
}