Skip to content

Commit

Permalink
PDI-1540: Add pingone_webhook (Resource) Export (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikostien-pingidentity committed Mar 14, 2024
1 parent 1ebb2c1 commit d84718e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (c *PingonePlatformConnector) Export(format, outputDir string, overwriteExp
resources.RoleAssignmentUser(&c.clientInfo),
resources.TrustedEmailAddress(&c.clientInfo),
resources.TrustedEmailDomain(&c.clientInfo),
resources.Webhook(&c.clientInfo),
}

for _, exportableResource := range exportableResources {
Expand Down
61 changes: 61 additions & 0 deletions internal/connector/pingone_platform/resources/pingone_webhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package resources

import (
"fmt"

"github.com/pingidentity/pingctl/internal/connector"
"github.com/pingidentity/pingctl/internal/logger"
)

// Verify that the resource satisfies the exportable resource interface
var (
_ connector.ExportableResource = &PingoneWebhookResource{}
)

type PingoneWebhookResource struct {
clientInfo *connector.SDKClientInfo
}

// Utility method for creating a PingoneWebhookResource
func Webhook(clientInfo *connector.SDKClientInfo) *PingoneWebhookResource {
return &PingoneWebhookResource{
clientInfo: clientInfo,
}
}

func (r *PingoneWebhookResource) ExportAll() (*[]connector.ImportBlock, error) {
l := logger.Get()

l.Debug().Msgf("Fetching all %s resources...", r.ResourceType())

apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.SubscriptionsWebhooksApi.ReadAllSubscriptions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute
apiFunctionName := "ReadAllSubscriptions"

usersEmbedded, err := 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 _, subscription := range usersEmbedded.GetSubscriptions() {
subscriptionId, subscriptionIdOk := subscription.GetIdOk()
subscriptionName, subscriptionNameOk := subscription.GetNameOk()

if subscriptionIdOk && subscriptionNameOk {
importBlocks = append(importBlocks, connector.ImportBlock{
ResourceType: r.ResourceType(),
ResourceName: *subscriptionName,
ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *subscriptionId),
})
}
}

return &importBlocks, nil
}

func (r *PingoneWebhookResource) ResourceType() string {
return "pingone_webhook"
}

0 comments on commit d84718e

Please sign in to comment.