-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from pingidentity/pingone_identity_provider_at…
…tribute-resource-export pingone_identity_provider_attribute resource export
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
internal/connector/pingone/resources/sso/pingone_identity_provider_attribute.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package sso | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/connector/pingone/resources/common" | ||
"github.com/pingidentity/pingctl/internal/logger" | ||
) | ||
|
||
// Verify that the resource satisfies the exportable resource interface | ||
var ( | ||
_ connector.ExportableResource = &PingoneIdentityProviderAttributeResource{} | ||
) | ||
|
||
type PingoneIdentityProviderAttributeResource struct { | ||
clientInfo *connector.SDKClientInfo | ||
} | ||
|
||
// Utility method for creating a PingoneIdentityProviderAttributeResource | ||
func IdentityProviderAttribute(clientInfo *connector.SDKClientInfo) *PingoneIdentityProviderAttributeResource { | ||
return &PingoneIdentityProviderAttributeResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingoneIdentityProviderAttributeResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteIdpsFunc := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProvidersApi.ReadAllIdentityProviders(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute | ||
apiapiExecuteIdpsFuncFunctionName := "ReadAllIdentityProviders" | ||
|
||
embedded, err := common.GetManagementEmbedded(apiExecuteIdpsFunc, apiapiExecuteIdpsFuncFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
for _, idp := range embedded.GetIdentityProviders() { | ||
var ( | ||
idpId *string | ||
idpIdOk bool | ||
idpName *string | ||
idpNameOk bool | ||
) | ||
|
||
switch { | ||
case idp.IdentityProviderApple != nil: | ||
idpId, idpIdOk = idp.IdentityProviderApple.GetIdOk() | ||
idpName, idpNameOk = idp.IdentityProviderApple.GetNameOk() | ||
case idp.IdentityProviderClientIDClientSecret != nil: | ||
idpId, idpIdOk = idp.IdentityProviderClientIDClientSecret.GetIdOk() | ||
idpName, idpNameOk = idp.IdentityProviderClientIDClientSecret.GetNameOk() | ||
case idp.IdentityProviderFacebook != nil: | ||
idpId, idpIdOk = idp.IdentityProviderFacebook.GetIdOk() | ||
idpName, idpNameOk = idp.IdentityProviderFacebook.GetNameOk() | ||
case idp.IdentityProviderOIDC != nil: | ||
idpId, idpIdOk = idp.IdentityProviderOIDC.GetIdOk() | ||
idpName, idpNameOk = idp.IdentityProviderOIDC.GetNameOk() | ||
case idp.IdentityProviderPaypal != nil: | ||
idpId, idpIdOk = idp.IdentityProviderPaypal.GetIdOk() | ||
idpName, idpNameOk = idp.IdentityProviderPaypal.GetNameOk() | ||
case idp.IdentityProviderSAML != nil: | ||
idpId, idpIdOk = idp.IdentityProviderSAML.GetIdOk() | ||
idpName, idpNameOk = idp.IdentityProviderSAML.GetNameOk() | ||
default: | ||
continue | ||
} | ||
|
||
if idpIdOk && idpNameOk { | ||
apiExecuteIdpAttributesFunc := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProviderAttributesApi.ReadAllIdentityProviderAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *idpId).Execute | ||
apiIdpAttributesFunctionName := "ReadAllIdentityProviderAttributes" | ||
|
||
idpAttributesEmbedded, err := common.GetManagementEmbedded(apiExecuteIdpAttributesFunc, apiIdpAttributesFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, idpAttribute := range idpAttributesEmbedded.GetAttributes() { | ||
idpAttributeId, idpAttributeIdOk := idpAttribute.IdentityProviderAttribute.GetIdOk() | ||
idpAttributeName, idpAttributeNameOk := idpAttribute.IdentityProviderAttribute.GetNameOk() | ||
if idpAttributeIdOk && idpAttributeNameOk { | ||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: fmt.Sprintf("%s_%s", *idpName, *idpAttributeName), | ||
ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *idpId, *idpAttributeId), | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingoneIdentityProviderAttributeResource) ResourceType() string { | ||
return "pingone_identity_provider_attribute" | ||
} |