-
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-1813: Export block HCL generation for PingFederate (#130)
* Add PF resource export pingfederate_idp_default_urls * Add PF resource export pingfederate_idp_sp_connection and update ignoredError checking for Terraform testing * Add PF resource export pingfederate_incoming_proxy_settings * Add PF resource export pingfederate_kerberos_realm * Add PF resource export pingfederate_local_identity_identity_profile * Update ignoredError checking for Terraform testing
- Loading branch information
1 parent
7c214b3
commit ab10521
Showing
19 changed files
with
660 additions
and
7 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
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
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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
internal/connector/pingfederate/resources/pingfederate_idp_default_urls.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,52 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/connector/common" | ||
"github.com/pingidentity/pingctl/internal/logger" | ||
) | ||
|
||
// Verify that the resource satisfies the exportable resource interface | ||
var ( | ||
_ connector.ExportableResource = &PingFederateExtendedPropertiesResource{} | ||
) | ||
|
||
type PingFederateIDPDefaultURLsResource struct { | ||
clientInfo *connector.PingFederateClientInfo | ||
} | ||
|
||
// Utility method for creating a PingFederateIDPDefaultURLsResource | ||
func IDPDefaultURLs(clientInfo *connector.PingFederateClientInfo) *PingFederateIDPDefaultURLsResource { | ||
return &PingFederateIDPDefaultURLsResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingFederateIDPDefaultURLsResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
idpDefaultURLsId := "idp_default_urls_singleton_id" | ||
idpDefaultURLsName := "IDP Default URLs" | ||
|
||
commentData := map[string]string{ | ||
"Resource Type": r.ResourceType(), | ||
"Singleton ID": common.SINGLETON_ID_COMMENT_DATA, | ||
} | ||
|
||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: idpDefaultURLsName, | ||
ResourceID: idpDefaultURLsId, | ||
CommentInformation: common.GenerateCommentInformation(commentData), | ||
}) | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingFederateIDPDefaultURLsResource) ResourceType() string { | ||
return "pingfederate_idp_default_urls" | ||
} |
26 changes: 26 additions & 0 deletions
26
internal/connector/pingfederate/resources/pingfederate_idp_default_urls_test.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,26 @@ | ||
package resources_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/connector/pingfederate/resources" | ||
"github.com/pingidentity/pingctl/internal/testing/testutils" | ||
) | ||
|
||
func TestPingFederateIDPDefaultURLsExport(t *testing.T) { | ||
// Get initialized apiClient and resource | ||
PingFederateClientInfo := testutils.GetPingFederateClientInfo(t) | ||
resource := resources.IDPDefaultURLs(PingFederateClientInfo) | ||
|
||
// Defined the expected ImportBlocks for the resource | ||
expectedImportBlocks := []connector.ImportBlock{ | ||
{ | ||
ResourceType: "pingfederate_idp_default_urls", | ||
ResourceName: "IDP Default URLs", | ||
ResourceID: "idp_default_urls_singleton_id", | ||
}, | ||
} | ||
|
||
testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
} |
84 changes: 84 additions & 0 deletions
84
internal/connector/pingfederate/resources/pingfederate_idp_sp_connection.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,84 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/connector/common" | ||
"github.com/pingidentity/pingctl/internal/logger" | ||
) | ||
|
||
// Verify that the resource satisfies the exportable resource interface | ||
var ( | ||
_ connector.ExportableResource = &PingFederateIDPSPConnectionResource{} | ||
) | ||
|
||
type PingFederateIDPSPConnectionResource struct { | ||
clientInfo *connector.PingFederateClientInfo | ||
} | ||
|
||
// Utility method for creating a PingFederateIDPSPConnectionResource | ||
func IDPSPConnection(clientInfo *connector.PingFederateClientInfo) *PingFederateIDPSPConnectionResource { | ||
return &PingFederateIDPSPConnectionResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingFederateIDPSPConnectionResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteFunc := r.clientInfo.ApiClient.IdpSpConnectionsAPI.GetSpConnections(r.clientInfo.Context).Execute | ||
apiFunctionName := "GetSpConnections" | ||
|
||
spConnections, response, err := apiExecuteFunc() | ||
|
||
err = common.HandleClientResponse(response, err, apiFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if spConnections == nil { | ||
l.Error().Msgf("Returned %s() spConnections is nil.", apiFunctionName) | ||
l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) | ||
return nil, fmt.Errorf("failed to fetch %s resources via %s()", r.ResourceType(), apiFunctionName) | ||
} | ||
|
||
spConnectionsItems, ok := spConnections.GetItemsOk() | ||
if !ok { | ||
l.Error().Msgf("Failed to get %s() spConnections items.", apiFunctionName) | ||
l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) | ||
return nil, fmt.Errorf("failed to fetch %s resources via %s()", r.ResourceType(), apiFunctionName) | ||
} | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
for _, spConnection := range spConnectionsItems { | ||
spConnectionId, spConnectionIdOk := spConnection.GetIdOk() | ||
spConnectionName, spConnectionNameOk := spConnection.GetNameOk() | ||
|
||
if spConnectionIdOk && spConnectionNameOk { | ||
commentData := map[string]string{ | ||
"Resource Type": r.ResourceType(), | ||
"IDP SP Connection Resource ID": *spConnectionId, | ||
"IDP SP Connection Resource Name": *spConnectionName, | ||
} | ||
|
||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: *spConnectionName, | ||
ResourceID: *spConnectionId, | ||
CommentInformation: common.GenerateCommentInformation(commentData), | ||
}) | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingFederateIDPSPConnectionResource) ResourceType() string { | ||
return "pingfederate_idp_sp_connection" | ||
} |
26 changes: 26 additions & 0 deletions
26
internal/connector/pingfederate/resources/pingfederate_idp_sp_connection_test.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,26 @@ | ||
package resources_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/connector/pingfederate/resources" | ||
"github.com/pingidentity/pingctl/internal/testing/testutils" | ||
) | ||
|
||
func TestPingFederateIDPSPConnectionExport(t *testing.T) { | ||
// Get initialized apiClient and resource | ||
PingFederateClientInfo := testutils.GetPingFederateClientInfo(t) | ||
resource := resources.IDPSPConnection(PingFederateClientInfo) | ||
|
||
// Defined the expected ImportBlocks for the resource | ||
expectedImportBlocks := []connector.ImportBlock{ | ||
{ | ||
ResourceType: "pingfederate_idp_sp_connection", | ||
ResourceName: "test", | ||
ResourceID: "iIoQK.-GWcXI5kLp4KDNxQqAhDF", | ||
}, | ||
} | ||
|
||
testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
} |
52 changes: 52 additions & 0 deletions
52
internal/connector/pingfederate/resources/pingfederate_incoming_proxy_settings.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,52 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/connector/common" | ||
"github.com/pingidentity/pingctl/internal/logger" | ||
) | ||
|
||
// Verify that the resource satisfies the exportable resource interface | ||
var ( | ||
_ connector.ExportableResource = &PingFederateIncomingProxySettingsResource{} | ||
) | ||
|
||
type PingFederateIncomingProxySettingsResource struct { | ||
clientInfo *connector.PingFederateClientInfo | ||
} | ||
|
||
// Utility method for creating a PingFederateIncomingProxySettingsResource | ||
func IncomingProxySettings(clientInfo *connector.PingFederateClientInfo) *PingFederateIncomingProxySettingsResource { | ||
return &PingFederateIncomingProxySettingsResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingFederateIncomingProxySettingsResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
incomingProxySettingsId := "incoming_proxy_settings_singleton_id" | ||
incomingProxySettingsName := "Incoming Proxy Settings" | ||
|
||
commentData := map[string]string{ | ||
"Resource Type": r.ResourceType(), | ||
"Singleton ID": common.SINGLETON_ID_COMMENT_DATA, | ||
} | ||
|
||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: incomingProxySettingsName, | ||
ResourceID: incomingProxySettingsId, | ||
CommentInformation: common.GenerateCommentInformation(commentData), | ||
}) | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingFederateIncomingProxySettingsResource) ResourceType() string { | ||
return "pingfederate_incoming_proxy_settings" | ||
} |
26 changes: 26 additions & 0 deletions
26
internal/connector/pingfederate/resources/pingfederate_incoming_proxy_settings_test.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,26 @@ | ||
package resources_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingidentity/pingctl/internal/connector" | ||
"github.com/pingidentity/pingctl/internal/connector/pingfederate/resources" | ||
"github.com/pingidentity/pingctl/internal/testing/testutils" | ||
) | ||
|
||
func TestPingFederateIncomingProxySettingsExport(t *testing.T) { | ||
// Get initialized apiClient and resource | ||
PingFederateClientInfo := testutils.GetPingFederateClientInfo(t) | ||
resource := resources.IncomingProxySettings(PingFederateClientInfo) | ||
|
||
// Defined the expected ImportBlocks for the resource | ||
expectedImportBlocks := []connector.ImportBlock{ | ||
{ | ||
ResourceType: "pingfederate_incoming_proxy_settings", | ||
ResourceName: "Incoming Proxy Settings", | ||
ResourceID: "incoming_proxy_settings_singleton_id", | ||
}, | ||
} | ||
|
||
testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
} |
Oops, something went wrong.