-
Notifications
You must be signed in to change notification settings - Fork 2
pingone_population_default_identity_provider resource platform export support #81
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_population_default_identity_provider-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
2a48c56
add pingone_population_default_identity_provider resource platform ex…
wesleymccollam 095519d
add test
wesleymccollam 846cbb0
pr edits, remove 403 error check on worker app temporarily
wesleymccollam 60e5fb7
update app secret test
wesleymccollam f0455fd
uncomment 403 error check, minor test edits
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
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
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
97 changes: 97 additions & 0 deletions
97
internal/connector/pingone/sso/resources/pingone_population_default_identity_provider.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,97 @@ | ||
| 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 = &PingOnePopulationDefaultIdpResource{} | ||
| ) | ||
|
|
||
| type PingOnePopulationDefaultIdpResource struct { | ||
| clientInfo *connector.PingOneClientInfo | ||
| } | ||
|
|
||
| // Utility method for creating a PingOnePopulationDefaultIdpResource | ||
| func PopulationDefaultIdp(clientInfo *connector.PingOneClientInfo) *PingOnePopulationDefaultIdpResource { | ||
| return &PingOnePopulationDefaultIdpResource{ | ||
| clientInfo: clientInfo, | ||
| } | ||
| } | ||
|
|
||
| func (r *PingOnePopulationDefaultIdpResource) ResourceType() string { | ||
| return "pingone_population_default_identity_provider" | ||
| } | ||
|
|
||
| func (r *PingOnePopulationDefaultIdpResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
| l := logger.Get() | ||
| l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) | ||
|
|
||
| importBlocks := []connector.ImportBlock{} | ||
|
|
||
| populationData, err := r.getPopulationData() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for populationId, populationName := range populationData { | ||
| ok, err := r.checkPopulationDefaultIdp(populationId) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if !ok { | ||
| return &importBlocks, nil | ||
| } | ||
|
|
||
| commentData := map[string]string{ | ||
| "Export Environment ID": r.clientInfo.ExportEnvironmentID, | ||
| "Population ID": populationId, | ||
| "Population Name": populationName, | ||
| "Resource Type": r.ResourceType(), | ||
| } | ||
|
|
||
| importBlock := connector.ImportBlock{ | ||
| ResourceType: r.ResourceType(), | ||
| ResourceName: fmt.Sprintf("%s_default_identity_provider", populationName), | ||
| ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, populationId), | ||
| CommentInformation: common.GenerateCommentInformation(commentData), | ||
| } | ||
|
|
||
| importBlocks = append(importBlocks, importBlock) | ||
| } | ||
|
|
||
| return &importBlocks, nil | ||
| } | ||
|
|
||
| func (r *PingOnePopulationDefaultIdpResource) getPopulationData() (map[string]string, error) { | ||
| populationData := make(map[string]string) | ||
|
|
||
| iter := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadAllPopulations(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() | ||
| populations, err := pingone.GetManagementAPIObjectsFromIterator[management.Population](iter, "ReadAllPopulations", "GetPopulations", r.ResourceType()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, population := range populations { | ||
| populationId, populationIdOk := population.GetIdOk() | ||
| populationName, populationNameOk := population.GetNameOk() | ||
|
|
||
| if populationIdOk && populationNameOk { | ||
| populationData[*populationId] = *populationName | ||
| } | ||
| } | ||
|
|
||
| return populationData, nil | ||
| } | ||
|
|
||
| func (r *PingOnePopulationDefaultIdpResource) checkPopulationDefaultIdp(populationId string) (bool, error) { | ||
| _, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadOnePopulationDefaultIdp(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, populationId).Execute() | ||
| return pingone.CheckSingletonResource(resp, err, "ReadOnePopulationDefaultIdp", r.ResourceType()) | ||
| } |
37 changes: 37 additions & 0 deletions
37
...rnal/connector/pingone/sso/resources/pingone_population_default_identity_provider_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,37 @@ | ||
| 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 TestPopulationDefaultIdpExport(t *testing.T) { | ||
| // Get initialized apiClient and resource | ||
| PingOneClientInfo := testutils.GetPingOneClientInfo(t) | ||
| resource := resources.PopulationDefaultIdp(PingOneClientInfo) | ||
|
|
||
| // Defined the expected ImportBlocks for the resource | ||
| expectedImportBlocks := []connector.ImportBlock{ | ||
| { | ||
| ResourceType: "pingone_population_default_identity_provider", | ||
| ResourceName: "Default_default_identity_provider", | ||
| ResourceID: fmt.Sprintf("%s/720da2ce-4dd0-48d9-af75-aeadbda1860d", testutils.GetEnvironmentID()), | ||
| }, | ||
| { | ||
| ResourceType: "pingone_population_default_identity_provider", | ||
| ResourceName: "LDAP Gateway Population_default_identity_provider", | ||
| ResourceID: fmt.Sprintf("%s/374fdb3c-4e94-4547-838a-0c200b9a7c70", testutils.GetEnvironmentID()), | ||
| }, | ||
| { | ||
| ResourceType: "pingone_population_default_identity_provider", | ||
| ResourceName: "Test Default Idp Population_default_identity_provider", | ||
| ResourceID: fmt.Sprintf("%s/2814912d-4a0f-4104-a779-80c13b2a6dcd", testutils.GetEnvironmentID()), | ||
| }, | ||
| } | ||
|
|
||
| testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
| } |
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
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.