-
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 branch 'go-cli' into PDI-1546-app-secret
- Loading branch information
Showing
5 changed files
with
303 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
99 changes: 99 additions & 0 deletions
99
internal/connector/pingone/resources/sso/pingone_application_attribute_mapping.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,99 @@ | ||
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 = &PingoneApplicationAttributeMappingResource{} | ||
) | ||
|
||
type PingoneApplicationAttributeMappingResource struct { | ||
clientInfo *connector.SDKClientInfo | ||
} | ||
|
||
// Utility method for creating a PingoneApplicationAttributeMappingResource | ||
func ApplicationAttributeMapping(clientInfo *connector.SDKClientInfo) *PingoneApplicationAttributeMappingResource { | ||
return &PingoneApplicationAttributeMappingResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingoneApplicationAttributeMappingResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute | ||
apiApplicationFunctionName := "ReadAllApplications" | ||
|
||
embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
for _, app := range embedded.GetApplications() { | ||
var ( | ||
appId *string | ||
appIdOk bool | ||
appName *string | ||
appNameOk bool | ||
) | ||
|
||
switch { | ||
case app.ApplicationOIDC != nil: | ||
appId, appIdOk = app.ApplicationOIDC.GetIdOk() | ||
appName, appNameOk = app.ApplicationOIDC.GetNameOk() | ||
case app.ApplicationSAML != nil: | ||
appId, appIdOk = app.ApplicationSAML.GetIdOk() | ||
appName, appNameOk = app.ApplicationSAML.GetNameOk() | ||
case app.ApplicationWSFED != nil: | ||
appId, appIdOk = app.ApplicationWSFED.GetIdOk() | ||
appName, appNameOk = app.ApplicationWSFED.GetNameOk() | ||
default: | ||
continue | ||
} | ||
|
||
if appIdOk && appNameOk { | ||
apiExecuteAttributeMappingFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationAttributeMappingApi.ReadAllApplicationAttributeMappings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute | ||
apiAttributeMappingFunctionName := "ReadAllApplicationAttributeMappings" | ||
|
||
attributeMappingsEmbedded, err := common.GetManagementEmbedded(apiExecuteAttributeMappingFunc, apiAttributeMappingFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, attributeMapping := range attributeMappingsEmbedded.GetAttributes() { | ||
if attributeMapping.ApplicationAttributeMapping == nil { | ||
continue | ||
} | ||
|
||
attributeMappingId, attributeMappingIdOk := attributeMapping.ApplicationAttributeMapping.GetIdOk() | ||
attributeMappingName, attributeMappingNameOk := attributeMapping.ApplicationAttributeMapping.GetNameOk() | ||
|
||
if attributeMappingIdOk && attributeMappingNameOk { | ||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: fmt.Sprintf("%s_%s", *appName, *attributeMappingName), | ||
ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *appId, *attributeMappingId), | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingoneApplicationAttributeMappingResource) ResourceType() string { | ||
return "pingone_application_attribute_mapping" | ||
} |
76 changes: 76 additions & 0 deletions
76
internal/connector/pingone/resources/sso/pingone_group_nesting.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,76 @@ | ||
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 = &PingoneGroupNestingResource{} | ||
) | ||
|
||
type PingoneGroupNestingResource struct { | ||
clientInfo *connector.SDKClientInfo | ||
} | ||
|
||
// Utility method for creating a PingoneGroupNestingResource | ||
func GroupNesting(clientInfo *connector.SDKClientInfo) *PingoneGroupNestingResource { | ||
return &PingoneGroupNestingResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingoneGroupNestingResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute | ||
apiFunctionName := "ReadAllGroups" | ||
|
||
embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
for _, parentGroup := range embedded.GetGroups() { | ||
parentGroupId, parentGroupIdOk := parentGroup.GetIdOk() | ||
parentGroupName, parentGroupNameOk := parentGroup.GetNameOk() | ||
|
||
if parentGroupIdOk && parentGroupNameOk { | ||
apiGroupNestingExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadGroupNesting(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *parentGroupId).Execute | ||
apiGroupNestingFunctionName := "ReadGroupNesting" | ||
|
||
embeddedGroupNesting, err := common.GetManagementEmbedded(apiGroupNestingExecuteFunc, apiGroupNestingFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, nestedGroup := range embeddedGroupNesting.GetGroupMemberships() { | ||
nestedGroupId, nestedGroupIdOk := nestedGroup.GetIdOk() | ||
nestedGroupName, nestedGroupNameOk := nestedGroup.GetNameOk() | ||
if nestedGroupIdOk && nestedGroupNameOk { | ||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: fmt.Sprintf("%s_%s", *parentGroupName, *nestedGroupName), | ||
ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *parentGroupId, *nestedGroupId), | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingoneGroupNestingResource) ResourceType() string { | ||
return "pingone_group_nesting" | ||
} |
62 changes: 62 additions & 0 deletions
62
internal/connector/pingone/resources/sso/pingone_password_policy.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,62 @@ | ||
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 = &PingonePasswordPolicyResource{} | ||
) | ||
|
||
type PingonePasswordPolicyResource struct { | ||
clientInfo *connector.SDKClientInfo | ||
} | ||
|
||
// Utility method for creating a PingonePasswordPolicyResource | ||
func PasswordPolicy(clientInfo *connector.SDKClientInfo) *PingonePasswordPolicyResource { | ||
return &PingonePasswordPolicyResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingonePasswordPolicyResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.PasswordPoliciesApi.ReadAllPasswordPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute | ||
apiFunctionName := "ReadAllPasswordPolicies" | ||
|
||
embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
for _, passwordPolicy := range embedded.GetPasswordPolicies() { | ||
passwordPolicyId, passwordPolicyIdOk := passwordPolicy.GetIdOk() | ||
passwordPolicyName, passwordPolicyNameOk := passwordPolicy.GetNameOk() | ||
|
||
if passwordPolicyIdOk && passwordPolicyNameOk { | ||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: *passwordPolicyName, | ||
ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *passwordPolicyId), | ||
}) | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingonePasswordPolicyResource) ResourceType() string { | ||
return "pingone_password_policy" | ||
} |
62 changes: 62 additions & 0 deletions
62
internal/connector/pingone/resources/sso/pingone_resource.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,62 @@ | ||
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 = &PingoneResourceResource{} | ||
) | ||
|
||
type PingoneResourceResource struct { | ||
clientInfo *connector.SDKClientInfo | ||
} | ||
|
||
// Utility method for creating a PingoneResourceResource | ||
func Resource(clientInfo *connector.SDKClientInfo) *PingoneResourceResource { | ||
return &PingoneResourceResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingoneResourceResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute | ||
apiFunctionName := "ReadAllResources" | ||
|
||
embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
for _, resource := range embedded.GetResources() { | ||
resourceId, resourceIdOk := resource.GetIdOk() | ||
resourceName, resourceNameOk := resource.GetNameOk() | ||
|
||
if resourceIdOk && resourceNameOk { | ||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: *resourceName, | ||
ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *resourceId), | ||
}) | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingoneResourceResource) ResourceType() string { | ||
return "pingone_resource" | ||
} |