Skip to content

Commit

Permalink
CRUD for idp
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimutant committed Mar 14, 2024
1 parent d3efe2f commit 37dcb74
Show file tree
Hide file tree
Showing 3 changed files with 453 additions and 2 deletions.
64 changes: 63 additions & 1 deletion nutanix/services/v2/iam/data_source_nutanix_saml_idp_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func DatasourceNutanixSamlIDPv4() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"idp_metadata_xml": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -105,7 +109,10 @@ func DatasourceNutanixSamlIDPv4Read(ctx context.Context, d *schema.ResourceData,
if err := d.Set("idp_metadata_url", getResp.IdpMetadataUrl); err != nil {
return diag.FromErr(err)
}
if err := d.Set("idp_metadata", getResp.IdpMetadata); err != nil {
if err := d.Set("idp_metadata", flattenIdpMetadata(getResp.IdpMetadata)); err != nil {
return diag.FromErr(err)
}
if err := d.Set("idp_metadata_xml", getResp.IdpMetadataXml); err != nil {
return diag.FromErr(err)
}
if err := d.Set("username_attr", getResp.UsernameAttribute); err != nil {
Expand Down Expand Up @@ -148,3 +155,58 @@ func DatasourceNutanixSamlIDPv4Read(ctx context.Context, d *schema.ResourceData,
d.SetId(*getResp.ExtId)
return nil
}

func flattenIdpMetadata(pr *import1.IdpMetadata) []map[string]interface{} {
if pr != nil {
idps := make([]map[string]interface{}, 0)
idp := make(map[string]interface{})

idp["entity_id"] = pr.EntityId
idp["login_url"] = pr.LoginUrl
idp["logout_url"] = pr.LogoutUrl
idp["error_url"] = pr.ErrorUrl
idp["certificate"] = pr.Certificate
if pr.NameIdPolicyFormat != nil {
idp["name_id_policy_format"] = flattenNameIdPolicyFormat(pr.NameIdPolicyFormat)
}

idps = append(idps, idp)
return idps
}
return nil
}

func flattenNameIdPolicyFormat(pr *import1.NameIdPolicyFormat) string {
if pr != nil {
const two, three, four, five, six, seven, eight, nine, ten = 2, 3, 4, 5, 6, 7, 8, 9, 10

if *pr == import1.NameIdPolicyFormat(two) {
return "emailAddress"
}
if *pr == import1.NameIdPolicyFormat(three) {
return "unspecified"
}
if *pr == import1.NameIdPolicyFormat(four) {
return "X509SubjectName"
}
if *pr == import1.NameIdPolicyFormat(five) {
return "WindowsDomainQualifiedName"
}
if *pr == import1.NameIdPolicyFormat(six) {
return "encrypted"
}
if *pr == import1.NameIdPolicyFormat(seven) {
return "entity"
}
if *pr == import1.NameIdPolicyFormat(eight) {
return "kerberos"
}
if *pr == import1.NameIdPolicyFormat(nine) {
return "persistent"
}
if *pr == import1.NameIdPolicyFormat(ten) {
return "transient"
}
}
return "UNKNOWN"
}
9 changes: 8 additions & 1 deletion nutanix/services/v2/iam/data_source_nutanix_saml_idps_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func DatasourceNutanixSamlIDPsV4() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"idp_metadata_xml": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -177,11 +181,14 @@ func flattenIdentityProvidersEntities(pr []import1.SamlIdentityProvider) []inter
idp["name"] = v.Name
}
if v.IdpMetadata != nil {
idp["idp_metadata_url"] = v.IdpMetadata
idp["idp_metadata_url"] = flattenIdpMetadata(v.IdpMetadata)
}
if v.IdpMetadataUrl != nil {
idp["idp_metadata"] = v.IdpMetadataUrl
}
if v.IdpMetadataXml != nil {
idp["idp_metadata_xml"] = v.IdpMetadataXml
}
if v.UsernameAttribute != nil {
idp["username_attr"] = v.UsernameAttribute
}
Expand Down
Loading

0 comments on commit 37dcb74

Please sign in to comment.