-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PDI-1540: Add pingone_webhook (Resource) Export (#69)
- Loading branch information
1 parent
1ebb2c1
commit d84718e
Showing
2 changed files
with
62 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
61 changes: 61 additions & 0 deletions
61
internal/connector/pingone_platform/resources/pingone_webhook.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,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" | ||
} |