-
Notifications
You must be signed in to change notification settings - Fork 2
pingone_resource_secret resource platform export support #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wesleymccollam
merged 5 commits into
main
from
pingone_resource_secret-resource-export-support
Mar 12, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0f8e65
add pingone_resource_secret resource platform export support, update …
wesleymccollam 4f95ee3
edit tests
wesleymccollam 6d42ac7
Merge branch 'main' into pingone_resource_secret-resource-export-support
wesleymccollam 38069fd
add population default idp continue fix, only export custom resource …
wesleymccollam 0d4824d
Merge branch 'main' into pingone_resource_secret-resource-export-support
wesleymccollam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
101 changes: 101 additions & 0 deletions
101
internal/connector/pingone/sso/resources/pingone_resource_secret.go
This file contains hidden or 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,101 @@ | ||
| package resources | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/patrickcping/pingone-go-sdk-v2/management" | ||
| "github.com/pingidentity/pingcli/internal/connector" | ||
| "github.com/pingidentity/pingcli/internal/connector/common" | ||
| "github.com/pingidentity/pingcli/internal/connector/pingone" | ||
| "github.com/pingidentity/pingcli/internal/logger" | ||
| ) | ||
|
|
||
| // Verify that the resource satisfies the exportable resource interface | ||
| var ( | ||
| _ connector.ExportableResource = &PingOneResourceSecretResource{} | ||
| ) | ||
|
|
||
| type PingOneResourceSecretResource struct { | ||
| clientInfo *connector.PingOneClientInfo | ||
| } | ||
|
|
||
| // Utility method for creating a PingOneResourceSecretResource | ||
| func ResourceSecret(clientInfo *connector.PingOneClientInfo) *PingOneResourceSecretResource { | ||
| return &PingOneResourceSecretResource{ | ||
| clientInfo: clientInfo, | ||
| } | ||
| } | ||
|
|
||
| func (r *PingOneResourceSecretResource) ResourceType() string { | ||
| return "pingone_resource_secret" | ||
| } | ||
|
|
||
| func (r *PingOneResourceSecretResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
| l := logger.Get() | ||
| l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) | ||
|
|
||
| importBlocks := []connector.ImportBlock{} | ||
|
|
||
| resourceData, err := r.getResourceData() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for resourceId, resourceName := range resourceData { | ||
| resourceSecretOk, err := r.getResourceSecret(resourceId) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if !resourceSecretOk { | ||
| continue | ||
| } | ||
|
|
||
| commentData := map[string]string{ | ||
| "Resource ID": resourceId, | ||
| "Resource Name": resourceName, | ||
| "Export Environment ID": r.clientInfo.ExportEnvironmentID, | ||
| "Resource Type": r.ResourceType(), | ||
| } | ||
|
|
||
| importBlock := connector.ImportBlock{ | ||
| ResourceType: r.ResourceType(), | ||
| ResourceName: fmt.Sprintf("%s_secret", resourceName), | ||
| ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceId), | ||
| CommentInformation: common.GenerateCommentInformation(commentData), | ||
| } | ||
|
|
||
| importBlocks = append(importBlocks, importBlock) | ||
| } | ||
|
|
||
| return &importBlocks, nil | ||
| } | ||
|
|
||
| func (r *PingOneResourceSecretResource) getResourceData() (map[string]string, error) { | ||
| resourceData := make(map[string]string) | ||
|
|
||
| iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() | ||
| resourceInners, err := pingone.GetManagementAPIObjectsFromIterator[management.EntityArrayEmbeddedResourcesInner](iter, "ReadAllResources", "GetResources", r.ResourceType()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, resourceInner := range resourceInners { | ||
| if resourceInner.Resource != nil { | ||
| resourceId, resourceIdOk := resourceInner.Resource.GetIdOk() | ||
| resourceName, resourceNameOk := resourceInner.Resource.GetNameOk() | ||
| resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() | ||
|
|
||
| if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_CUSTOM { | ||
erikostien-pingidentity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resourceData[*resourceId] = *resourceName | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return resourceData, nil | ||
| } | ||
|
|
||
| func (r *PingOneResourceSecretResource) getResourceSecret(resourceId string) (bool, error) { | ||
| _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.ResourceClientSecretApi.ReadResourceSecret(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() | ||
| return common.HandleClientResponse(response, err, "ReadResourceSecret", r.ResourceType()) | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
internal/connector/pingone/sso/resources/pingone_resource_secret_test.go
This file contains hidden or 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,42 @@ | ||
| package resources_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/pingidentity/pingcli/internal/connector" | ||
| "github.com/pingidentity/pingcli/internal/connector/pingone/sso/resources" | ||
| "github.com/pingidentity/pingcli/internal/testing/testutils" | ||
| ) | ||
|
|
||
| func TestResourceSecretExport(t *testing.T) { | ||
| // Get initialized apiClient and resource | ||
| PingOneClientInfo := testutils.GetPingOneClientInfo(t) | ||
| resource := resources.ResourceSecret(PingOneClientInfo) | ||
|
|
||
| // Defined the expected ImportBlocks for the resource | ||
| expectedImportBlocks := []connector.ImportBlock{ | ||
| { | ||
| ResourceType: "pingone_resource_secret", | ||
| ResourceName: "Undeployed Test API Service_secret", | ||
| ResourceID: fmt.Sprintf("%s/a35fe5ea-084c-4245-80f1-85f9eaf4f063", testutils.GetEnvironmentID()), | ||
| }, | ||
| { | ||
| ResourceType: "pingone_resource_secret", | ||
| ResourceName: "authorize-api-service_secret", | ||
| ResourceID: fmt.Sprintf("%s/3c6001a0-6110-4934-9d34-fa8c4a2894c2", testutils.GetEnvironmentID()), | ||
| }, | ||
| { | ||
| ResourceType: "pingone_resource_secret", | ||
| ResourceName: "test_secret", | ||
| ResourceID: fmt.Sprintf("%s/4b9ef858-62ce-4bd0-9186-997b8527529d", testutils.GetEnvironmentID()), | ||
| }, | ||
| { | ||
| ResourceType: "pingone_resource_secret", | ||
| ResourceName: "testing_secret", | ||
| ResourceID: fmt.Sprintf("%s/52afd89f-f3c0-4c78-b896-432c0a07329b", testutils.GetEnvironmentID()), | ||
| }, | ||
| } | ||
|
|
||
| testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.