-
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 (#132)
* Add PF resource export pingfederate_oauth_issuer * Add PF resource export pingfederate_server_settings * Add PF resource export pingfederate_open_id_connect_settings * Add PF resource export pingfederate_password_credential_validator * Add PF resource export pingfederate_redirect_validation
- Loading branch information
1 parent
137beb9
commit de58e24
Showing
13 changed files
with
514 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
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
84 changes: 84 additions & 0 deletions
84
internal/connector/pingfederate/resources/pingfederate_oauth_issuer.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 = &PingFederateOAuthIssuerResource{} | ||
) | ||
|
||
type PingFederateOAuthIssuerResource struct { | ||
clientInfo *connector.PingFederateClientInfo | ||
} | ||
|
||
// Utility method for creating a PingFederateOAuthIssuerResource | ||
func OAuthIssuer(clientInfo *connector.PingFederateClientInfo) *PingFederateOAuthIssuerResource { | ||
return &PingFederateOAuthIssuerResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingFederateOAuthIssuerResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteFunc := r.clientInfo.ApiClient.OauthIssuersAPI.GetOauthIssuers(r.clientInfo.Context).Execute | ||
apiFunctionName := "GetOauthIssuers" | ||
|
||
issuers, response, err := apiExecuteFunc() | ||
|
||
err = common.HandleClientResponse(response, err, apiFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if issuers == nil { | ||
l.Error().Msgf("Returned %s() issuers 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) | ||
} | ||
|
||
issuersItems, ok := issuers.GetItemsOk() | ||
if !ok { | ||
l.Error().Msgf("Failed to get %s() issuers 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 _, issuer := range issuersItems { | ||
issuerId, issuerIdOk := issuer.GetIdOk() | ||
issuerName, issuerNameOk := issuer.GetNameOk() | ||
|
||
if issuerIdOk && issuerNameOk { | ||
commentData := map[string]string{ | ||
"Resource Type": r.ResourceType(), | ||
"OAuth Issuer Resource ID": *issuerId, | ||
"OAuth Issuer Resource Name": *issuerName, | ||
} | ||
|
||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: *issuerName, | ||
ResourceID: *issuerId, | ||
CommentInformation: common.GenerateCommentInformation(commentData), | ||
}) | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingFederateOAuthIssuerResource) ResourceType() string { | ||
return "pingfederate_oauth_issuer" | ||
} |
26 changes: 26 additions & 0 deletions
26
internal/connector/pingfederate/resources/pingfederate_oauth_issuer_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 TestPingFederateOAuthIssuerExport(t *testing.T) { | ||
// Get initialized apiClient and resource | ||
PingFederateClientInfo := testutils.GetPingFederateClientInfo(t) | ||
resource := resources.OAuthIssuer(PingFederateClientInfo) | ||
|
||
// Defined the expected ImportBlocks for the resource | ||
expectedImportBlocks := []connector.ImportBlock{ | ||
{ | ||
ResourceType: "pingfederate_oauth_issuer", | ||
ResourceName: "Test Issuer", | ||
ResourceID: "BmoJwEmyzs4RSNMzVUlCs8qTPC", | ||
}, | ||
} | ||
|
||
testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
} |
52 changes: 52 additions & 0 deletions
52
internal/connector/pingfederate/resources/pingfederate_open_id_connect_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 = &PingFederateOpenIDConnectSettingsResource{} | ||
) | ||
|
||
type PingFederateOpenIDConnectSettingsResource struct { | ||
clientInfo *connector.PingFederateClientInfo | ||
} | ||
|
||
// Utility method for creating a PingFederateOpenIDConnectSettingsResource | ||
func OpenIDConnectSettings(clientInfo *connector.PingFederateClientInfo) *PingFederateOpenIDConnectSettingsResource { | ||
return &PingFederateOpenIDConnectSettingsResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingFederateOpenIDConnectSettingsResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
importBlocks := []connector.ImportBlock{} | ||
|
||
l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) | ||
|
||
openIDConnectSettingsId := "open_id_connect_settings_singleton_id" | ||
openIDConnectSettingsName := "Open ID Connect 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: openIDConnectSettingsName, | ||
ResourceID: openIDConnectSettingsId, | ||
CommentInformation: common.GenerateCommentInformation(commentData), | ||
}) | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingFederateOpenIDConnectSettingsResource) ResourceType() string { | ||
return "pingfederate_open_id_connect_settings" | ||
} |
26 changes: 26 additions & 0 deletions
26
internal/connector/pingfederate/resources/pingfederate_open_id_connect_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 TestPingFederateOpenIDConnectSettingsExport(t *testing.T) { | ||
// Get initialized apiClient and resource | ||
PingFederateClientInfo := testutils.GetPingFederateClientInfo(t) | ||
resource := resources.OpenIDConnectSettings(PingFederateClientInfo) | ||
|
||
// Defined the expected ImportBlocks for the resource | ||
expectedImportBlocks := []connector.ImportBlock{ | ||
{ | ||
ResourceType: "pingfederate_open_id_connect_settings", | ||
ResourceName: "Open ID Connect Settings", | ||
ResourceID: "open_id_connect_settings_singleton_id", | ||
}, | ||
} | ||
|
||
testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
} |
84 changes: 84 additions & 0 deletions
84
internal/connector/pingfederate/resources/pingfederate_password_credential_validator.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 = &PingFederatePasswordCredentialValidatorResource{} | ||
) | ||
|
||
type PingFederatePasswordCredentialValidatorResource struct { | ||
clientInfo *connector.PingFederateClientInfo | ||
} | ||
|
||
// Utility method for creating a PingFederatePasswordCredentialValidatorResource | ||
func PasswordCredentialValidator(clientInfo *connector.PingFederateClientInfo) *PingFederatePasswordCredentialValidatorResource { | ||
return &PingFederatePasswordCredentialValidatorResource{ | ||
clientInfo: clientInfo, | ||
} | ||
} | ||
|
||
func (r *PingFederatePasswordCredentialValidatorResource) ExportAll() (*[]connector.ImportBlock, error) { | ||
l := logger.Get() | ||
|
||
l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) | ||
|
||
apiExecuteFunc := r.clientInfo.ApiClient.PasswordCredentialValidatorsAPI.GetPasswordCredentialValidators(r.clientInfo.Context).Execute | ||
apiFunctionName := "GetPasswordCredentialValidators" | ||
|
||
passwordCredentialValidators, response, err := apiExecuteFunc() | ||
|
||
err = common.HandleClientResponse(response, err, apiFunctionName, r.ResourceType()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if passwordCredentialValidators == nil { | ||
l.Error().Msgf("Returned %s() passwordCredentialValidators 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) | ||
} | ||
|
||
passwordCredentialValidatorsItems, ok := passwordCredentialValidators.GetItemsOk() | ||
if !ok { | ||
l.Error().Msgf("Failed to get %s() passwordCredentialValidators 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 _, passwordCredentialValidator := range passwordCredentialValidatorsItems { | ||
passwordCredentialValidatorId, passwordCredentialValidatorIdOk := passwordCredentialValidator.GetIdOk() | ||
passwordCredentialValidatorName, passwordCredentialValidatorNameOk := passwordCredentialValidator.GetNameOk() | ||
|
||
if passwordCredentialValidatorIdOk && passwordCredentialValidatorNameOk { | ||
commentData := map[string]string{ | ||
"Resource Type": r.ResourceType(), | ||
"Password Credential Validator Resource ID": *passwordCredentialValidatorId, | ||
"Password Credential Validator Resource Name": *passwordCredentialValidatorName, | ||
} | ||
|
||
importBlocks = append(importBlocks, connector.ImportBlock{ | ||
ResourceType: r.ResourceType(), | ||
ResourceName: *passwordCredentialValidatorName, | ||
ResourceID: *passwordCredentialValidatorId, | ||
CommentInformation: common.GenerateCommentInformation(commentData), | ||
}) | ||
} | ||
} | ||
|
||
return &importBlocks, nil | ||
} | ||
|
||
func (r *PingFederatePasswordCredentialValidatorResource) ResourceType() string { | ||
return "pingfederate_password_credential_validator" | ||
} |
36 changes: 36 additions & 0 deletions
36
internal/connector/pingfederate/resources/pingfederate_password_credential_validator_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,36 @@ | ||
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 TestPingFederatePasswordCredentialValidatorExport(t *testing.T) { | ||
// Get initialized apiClient and resource | ||
PingFederateClientInfo := testutils.GetPingFederateClientInfo(t) | ||
resource := resources.PasswordCredentialValidator(PingFederateClientInfo) | ||
|
||
// Defined the expected ImportBlocks for the resource | ||
expectedImportBlocks := []connector.ImportBlock{ | ||
{ | ||
ResourceType: "pingfederate_password_credential_validator", | ||
ResourceName: "pingdirectory", | ||
ResourceID: "pingdirectory", | ||
}, | ||
{ | ||
ResourceType: "pingfederate_password_credential_validator", | ||
ResourceName: "simple", | ||
ResourceID: "simple", | ||
}, | ||
{ | ||
ResourceType: "pingfederate_password_credential_validator", | ||
ResourceName: "PD PCV", | ||
ResourceID: "PDPCV", | ||
}, | ||
} | ||
|
||
testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) | ||
} |
Oops, something went wrong.