-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PDI-1507: Add pingone_agreement_enable (Resource) Export (#40)
- Loading branch information
1 parent
83dcc5c
commit 9bc5c5d
Showing
2 changed files
with
61 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
60 changes: 60 additions & 0 deletions
60
internal/connector/pingone_platform/resources/pingone_agreement_enable.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,60 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/patrickcping/pingone-go-sdk-v2/pingone" | ||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/logger" | ||
) | ||
|
||
// Verify that the resource satisfies the exportable resource interface | ||
var ( | ||
_ connector.ExportableResource = &PingoneAgreementEnableResource{} | ||
) | ||
|
||
type PingoneAgreementEnableResource struct { | ||
context context.Context | ||
apiClient *sdk.Client | ||
environmentID string | ||
} | ||
|
||
// Utility method for creating a PingoneAgreementResource | ||
func AgreementEnableResource(ctx context.Context, apiClient *sdk.Client, environmentID string) *PingoneAgreementEnableResource { | ||
return &PingoneAgreementEnableResource{ | ||
context: ctx, | ||
apiClient: apiClient, | ||
environmentID: environmentID, | ||
} | ||
} | ||
|
||
func (r *PingoneAgreementEnableResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all pingone_agreement_enable resources...") | ||
|
||
entityArray, response, err := r.apiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.context, r.environmentID).Execute() | ||
defer response.Body.Close() | ||
if err != nil { | ||
l.Error().Err(err).Msgf("ReadAllAgreements Response Code: %s\nResponse Body: %s", response.Status, response.Body) | ||
return nil, err | ||
} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all pingone_agreement_enable resources...") | ||
|
||
var importBlocks []connector.ImportBlock | ||
for _, agreement := range entityArray.Embedded.Agreements { | ||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: fmt.Sprintf("%s_enable", agreement.Name), | ||
ResourceID: *agreement.Id, | ||
}) | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingoneAgreementEnableResource) ResourceType() string { | ||
return "pingone_agreement_enable" | ||
} |