-
Notifications
You must be signed in to change notification settings - Fork 2
Add PingOne Authorize Service for Terraform Export #6
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
erikostien-pingidentity
merged 33 commits into
main
from
add-pingone-authorize-export-202410
Mar 3, 2025
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
728440e
begin draft for `authorize` service Terraform export
patrickcping ef7b359
development updates
patrickcping b5b0357
full authorize draft (pre-testing)
patrickcping fef7b68
Merge branch 'main' into add-pingone-authorize-export-202410
patrickcping 64ae319
update imports
patrickcping 0537447
Merge branch 'main' into add-pingone-authorize-export-202410
patrickcping 512695f
add authorize to available exportable services
patrickcping ac7f66d
change name to full name, filter on managed entity
patrickcping 59ff819
Merge branch 'main' into add-pingone-authorize-export-202410
patrickcping 821e9d2
Merge branch 'main' into add-pingone-authorize-export-202410
patrickcping 506994e
update authorize for EA
patrickcping 1432fca
Remove unreleased authorize editor resources
patrickcping 7e649eb
Revert go.mod to standard
patrickcping 846ac30
add `pingone_application_resource_permission`
patrickcping a91fdf5
fix lint and extract issues
patrickcping 1c6a0c2
add `pingone_application_resource` resource
patrickcping 9f2a6a6
update test cases
patrickcping a010f4e
testing test
patrickcping d0ef5da
update tests
patrickcping 0d3addb
update role permissions resource name
patrickcping 78f8e3c
refactor application_resource
patrickcping bb3fba4
clarify PingOne resource
patrickcping c4523b2
update test
patrickcping 2dd5978
remove keys
patrickcping 6c50801
correct test
patrickcping 38beb41
update test
patrickcping b6d337a
update keying
patrickcping 4da6403
correct lint
patrickcping 87fe2e7
add back api service deployment
patrickcping 6991a8c
add tests for undeployed api service
patrickcping 4552d94
add missing attribute test
patrickcping 30f7610
correct resource ID in test
patrickcping 7b9fd51
uncomment test
patrickcping 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ go.work | |
| go.work.sum | ||
| export | ||
| vendor | ||
| env*.sh | ||
| env*.sh | ||
| .env | ||
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
68 changes: 68 additions & 0 deletions
68
internal/connector/pingone/authorize/pingone_authorize_connector.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,68 @@ | ||
| package authorize | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| pingoneGoClient "github.com/patrickcping/pingone-go-sdk-v2/pingone" | ||
| "github.com/pingidentity/pingcli/internal/connector" | ||
| "github.com/pingidentity/pingcli/internal/connector/common" | ||
| "github.com/pingidentity/pingcli/internal/connector/pingone/authorize/resources" | ||
| "github.com/pingidentity/pingcli/internal/logger" | ||
| ) | ||
|
|
||
| const ( | ||
| serviceName = "pingone-authorize" | ||
| ) | ||
|
|
||
| // Verify that the connector satisfies the expected interfaces | ||
| var ( | ||
| _ connector.Exportable = &PingoneAuthorizeConnector{} | ||
| _ connector.Authenticatable = &PingoneAuthorizeConnector{} | ||
| ) | ||
|
|
||
| type PingoneAuthorizeConnector struct { | ||
| clientInfo connector.PingOneClientInfo | ||
| } | ||
|
|
||
| // Utility method for creating a PingoneAuthorizeConnector | ||
| func AuthorizeConnector(ctx context.Context, apiClient *pingoneGoClient.Client, apiClientId *string, exportEnvironmentID string) *PingoneAuthorizeConnector { | ||
| return &PingoneAuthorizeConnector{ | ||
| clientInfo: connector.PingOneClientInfo{ | ||
| Context: ctx, | ||
| ApiClient: apiClient, | ||
| ApiClientId: apiClientId, | ||
| ExportEnvironmentID: exportEnvironmentID, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (c *PingoneAuthorizeConnector) Export(format, outputDir string, overwriteExport bool) error { | ||
| l := logger.Get() | ||
|
|
||
| l.Debug().Msgf("Exporting all PingOne Authorize Resources...") | ||
|
|
||
| exportableResources := []connector.ExportableResource{ | ||
| resources.AuthorizeAPIService(&c.clientInfo), | ||
| resources.AuthorizeAPIServiceDeployment(&c.clientInfo), | ||
| resources.AuthorizeAPIServiceOperation(&c.clientInfo), | ||
| resources.ApplicationResource(&c.clientInfo), | ||
| resources.AuthorizeApplicationResourcePermission(&c.clientInfo), | ||
| resources.AuthorizeApplicationRole(&c.clientInfo), | ||
| resources.AuthorizeApplicationRolePermission(&c.clientInfo), | ||
| resources.AuthorizeDecisionEndpoint(&c.clientInfo), | ||
| } | ||
|
|
||
| return common.WriteFiles(exportableResources, format, outputDir, overwriteExport) | ||
| } | ||
|
|
||
| func (c *PingoneAuthorizeConnector) ConnectorServiceName() string { | ||
| return serviceName | ||
| } | ||
|
|
||
| func (c *PingoneAuthorizeConnector) Login() error { | ||
| return nil | ||
| } | ||
|
|
||
| func (c *PingoneAuthorizeConnector) Logout() error { | ||
| return nil | ||
| } |
59 changes: 59 additions & 0 deletions
59
internal/connector/pingone/authorize/pingone_authorize_connector_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,59 @@ | ||
| package authorize_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/pingidentity/pingcli/internal/connector" | ||
| "github.com/pingidentity/pingcli/internal/connector/pingone/authorize/resources" | ||
| "github.com/pingidentity/pingcli/internal/testing/testutils" | ||
| "github.com/pingidentity/pingcli/internal/testing/testutils_terraform" | ||
| ) | ||
|
|
||
| func TestAuthorizeTerraformPlan(t *testing.T) { | ||
| PingOneClientInfo := testutils.GetPingOneClientInfo(t) | ||
|
|
||
| testutils_terraform.InitPingOneTerraform(t) | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| resource connector.ExportableResource | ||
| ignoredErrors []string | ||
| }{ | ||
| { | ||
| name: "AuthorizeAPIService", | ||
| resource: resources.AuthorizeAPIService(PingOneClientInfo), | ||
| ignoredErrors: nil, | ||
| }, | ||
| { | ||
| name: "AuthorizeAPIServiceDeployment", | ||
| resource: resources.AuthorizeAPIServiceDeployment(PingOneClientInfo), | ||
| ignoredErrors: nil, | ||
| }, | ||
| { | ||
| name: "AuthorizeAPIServiceOperation", | ||
| resource: resources.AuthorizeAPIServiceOperation(PingOneClientInfo), | ||
| ignoredErrors: nil, | ||
| }, | ||
| { | ||
| name: "AuthorizeApplicationRole", | ||
| resource: resources.AuthorizeApplicationRole(PingOneClientInfo), | ||
| ignoredErrors: nil, | ||
| }, | ||
| { | ||
| name: "AuthorizeApplicationRolePermission", | ||
| resource: resources.AuthorizeApplicationRolePermission(PingOneClientInfo), | ||
| ignoredErrors: nil, | ||
| }, | ||
| { | ||
| name: "AuthorizeDecisionEndpoint", | ||
| resource: resources.AuthorizeDecisionEndpoint(PingOneClientInfo), | ||
| ignoredErrors: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| testutils_terraform.ValidateTerraformPlan(t, tc.resource, tc.ignoredErrors) | ||
| }) | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
internal/connector/pingone/authorize/resources/pingone_application_resource.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,108 @@ | ||
| package resources | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/patrickcping/pingone-go-sdk-v2/authorize" | ||
| "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 = &PingOneApplicationResourceResource{} | ||
| ) | ||
|
|
||
| type PingOneApplicationResourceResource struct { | ||
| clientInfo *connector.PingOneClientInfo | ||
| } | ||
|
|
||
| // Utility method for creating a PingOneApplicationResourceResource | ||
| func ApplicationResource(clientInfo *connector.PingOneClientInfo) *PingOneApplicationResourceResource { | ||
| return &PingOneApplicationResourceResource{ | ||
| clientInfo: clientInfo, | ||
| } | ||
| } | ||
|
|
||
| func (r *PingOneApplicationResourceResource) ResourceType() string { | ||
| return "pingone_application_resource" | ||
| } | ||
|
|
||
| type applicationResourceObj struct { | ||
| applicationResourceName string | ||
| resourceId string | ||
| resourceName string | ||
| } | ||
|
|
||
| func (r *PingOneApplicationResourceResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
| l := logger.Get() | ||
| l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) | ||
|
|
||
| importBlocks := []connector.ImportBlock{} | ||
|
|
||
| applicationResourceData, err := r.getApplicationResourceData() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for applicationResourceId, applicationResourceObj := range applicationResourceData { | ||
| commentData := map[string]string{ | ||
| "PingOne Resource ID": applicationResourceObj.resourceId, | ||
| "PingOne Resource Name": applicationResourceObj.resourceName, | ||
| "Application Resource ID": applicationResourceId, | ||
| "Application Resource Name": applicationResourceObj.applicationResourceName, | ||
| "Export Environment ID": r.clientInfo.ExportEnvironmentID, | ||
| "Resource Type": r.ResourceType(), | ||
| } | ||
|
|
||
| importBlock := connector.ImportBlock{ | ||
| ResourceType: r.ResourceType(), | ||
| ResourceName: fmt.Sprintf("%s_%s", applicationResourceObj.resourceName, applicationResourceObj.applicationResourceName), | ||
| ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, applicationResourceObj.resourceId, applicationResourceId), | ||
| CommentInformation: common.GenerateCommentInformation(commentData), | ||
| } | ||
|
|
||
| importBlocks = append(importBlocks, importBlock) | ||
| } | ||
|
|
||
| return &importBlocks, nil | ||
| } | ||
|
|
||
| func (r *PingOneApplicationResourceResource) getApplicationResourceData() (map[string]applicationResourceObj, error) { | ||
| applicationResourceData := make(map[string]applicationResourceObj) | ||
|
|
||
| iter := r.clientInfo.ApiClient.AuthorizeAPIClient.ApplicationResourcesApi.ReadApplicationResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() | ||
| applicationResources, err := pingone.GetAuthorizeAPIObjectsFromIterator[authorize.ApplicationResource](iter, "ReadApplicationResources", "GetResources", r.ResourceType()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, applicationResource := range applicationResources { | ||
| applicationResourceId, applicationResourceIdOk := applicationResource.GetIdOk() | ||
| applicationResourceName, applicationResourceNameOk := applicationResource.GetNameOk() | ||
| resourceId, resourceIdOk := applicationResource.Parent.GetIdOk() | ||
|
|
||
| if applicationResourceIdOk && applicationResourceNameOk && resourceIdOk { | ||
|
|
||
| resourceObj, httpResponse, err := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadOneResource(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *resourceId).Execute() | ||
| ok, err := common.HandleClientResponse(httpResponse, err, "ReadOneResource", r.ResourceType()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| // A warning was given when handling the client response. Return nil apiObjects to skip export of resource | ||
| if !ok { | ||
| return nil, nil | ||
| } | ||
|
|
||
| applicationResourceData[*applicationResourceId] = applicationResourceObj{ | ||
| applicationResourceName: *applicationResourceName, | ||
| resourceId: *resourceId, | ||
| resourceName: resourceObj.GetName(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return applicationResourceData, nil | ||
| } | ||
Oops, something went wrong.
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.