Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (c *PingOnePlatformConnector) Export(format, outputDir string, overwriteExp
l.Debug().Msgf("Exporting all PingOne Platform Resources...")

exportableResources := []connector.ExportableResource{
resources.AlertChannel(&c.clientInfo),
resources.Agreement(&c.clientInfo),
resources.AgreementEnable(&c.clientInfo),
resources.AgreementLocalization(&c.clientInfo),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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 = &PingOneAlertChannelResource{}
)

type PingOneAlertChannelResource struct {
clientInfo *connector.PingOneClientInfo
}

// Utility method for creating a PingOneAlertChannelResource
func AlertChannel(clientInfo *connector.PingOneClientInfo) *PingOneAlertChannelResource {
return &PingOneAlertChannelResource{
clientInfo: clientInfo,
}
}

func (r *PingOneAlertChannelResource) ResourceType() string {
return "pingone_alert_channel"
}

func (r *PingOneAlertChannelResource) ExportAll() (*[]connector.ImportBlock, error) {
l := logger.Get()
l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType())

importBlocks := []connector.ImportBlock{}

alertChannelData, err := r.getAlertChannelData()
if err != nil {
return nil, err
}

for alertChannelId, alertChannelName := range alertChannelData {
commentData := map[string]string{
"Export Environment ID": r.clientInfo.ExportEnvironmentID,
"Alert Channel ID": alertChannelId,
"Alert Channel Name": alertChannelName,
"Resource Type": r.ResourceType(),
}

importBlock := connector.ImportBlock{
ResourceType: r.ResourceType(),
ResourceName: alertChannelName,
ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, alertChannelId),
CommentInformation: common.GenerateCommentInformation(commentData),
}

importBlocks = append(importBlocks, importBlock)
}

return &importBlocks, nil
}

func (r *PingOneAlertChannelResource) getAlertChannelData() (map[string]string, error) {
alertChannelData := make(map[string]string)

iter := r.clientInfo.ApiClient.ManagementAPIClient.AlertingApi.ReadAllAlertChannels(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute()
alertChannels, err := pingone.GetManagementAPIObjectsFromIterator[management.AlertChannel](iter, "ReadAllAlertChannels", "GetAlertChannels", r.ResourceType())
if err != nil {
return nil, err
}

for _, alertChannel := range alertChannels {
alertChannelId, alertChannelIdOk := alertChannel.GetIdOk()
alertChannelName, alertChannelNameOk := alertChannel.GetAlertNameOk()

if alertChannelIdOk && alertChannelNameOk {
alertChannelData[*alertChannelId] = *alertChannelName
}
}

return alertChannelData, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package resources_test

import (
"fmt"
"testing"

"github.com/pingidentity/pingcli/internal/connector"
"github.com/pingidentity/pingcli/internal/connector/pingone/platform/resources"
"github.com/pingidentity/pingcli/internal/testing/testutils"
)

func TestAlertChannelExport(t *testing.T) {
// Get initialized apiClient and resource
PingOneClientInfo := testutils.GetPingOneClientInfo(t)
resource := resources.AlertChannel(PingOneClientInfo)

// Defined the expected ImportBlocks for the resource
expectedImportBlocks := []connector.ImportBlock{
{
ResourceType: "pingone_alert_channel",
ResourceName: "Test Alert Channel",
ResourceID: fmt.Sprintf("%s/6035f516-b474-4941-945a-76514913a74d", testutils.GetEnvironmentID()),
},
}

testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestIdentityProviderAttributeExport(t *testing.T) {
expectedImportBlocks := []connector.ImportBlock{
{
ResourceType: "pingone_identity_provider_attribute",
ResourceName: "Test IdP_username",
ResourceName: "Default Idp Test_username",
ResourceID: fmt.Sprintf("%s/a99df558-7090-4303-8f35-860ac660e371/51a036c6-41ed-44f7-bd1d-eacaa2a1feab", testutils.GetEnvironmentID()),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestIdentityProviderExport(t *testing.T) {
expectedImportBlocks := []connector.ImportBlock{
{
ResourceType: "pingone_identity_provider",
ResourceName: "Test IdP",
ResourceName: "Default Idp Test",
ResourceID: fmt.Sprintf("%s/a99df558-7090-4303-8f35-860ac660e371", testutils.GetEnvironmentID()),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func TestPopulationExport(t *testing.T) {
ResourceName: "LDAP Gateway Population",
ResourceID: fmt.Sprintf("%s/374fdb3c-4e94-4547-838a-0c200b9a7c70", testutils.GetEnvironmentID()),
},
{
ResourceType: "pingone_population",
ResourceName: "Test Default Idp Population",
ResourceID: fmt.Sprintf("%s/2814912d-4a0f-4104-a779-80c13b2a6dcd", testutils.GetEnvironmentID()),
},
}

testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks)
Expand Down