-
Notifications
You must be signed in to change notification settings - Fork 66
/
schema_identity_claim.go
52 lines (46 loc) · 1.43 KB
/
schema_identity_claim.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
package octopusdeploy
import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/users"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandIdentityClaims(claims []interface{}) map[string]users.IdentityClaim {
expandedClaims := make(map[string]users.IdentityClaim, len(claims))
for _, claim := range claims {
claimMap := claim.(map[string]interface{})
name := claimMap["name"].(string)
identityClaim := users.IdentityClaim{
IsIdentifyingClaim: claimMap["is_identifying_claim"].(bool),
Value: claimMap["value"].(string),
}
expandedClaims[name] = identityClaim
}
return expandedClaims
}
func flattenIdentityClaims(identityClaims map[string]users.IdentityClaim) []interface{} {
if identityClaims == nil {
return nil
}
flattenedIdentityClaims := []interface{}{}
for key, identityClaim := range identityClaims {
rawIdentityClaim := map[string]interface{}{
"is_identifying_claim": identityClaim.IsIdentifyingClaim,
"name": key,
"value": identityClaim.Value,
}
flattenedIdentityClaims = append(flattenedIdentityClaims, rawIdentityClaim)
}
return flattenedIdentityClaims
}
func getIdentityClaimSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": getNameSchema(true),
"is_identifying_claim": {
Required: true,
Type: schema.TypeBool,
},
"value": {
Required: true,
Type: schema.TypeString,
},
}
}