Skip to content

Commit

Permalink
Use reusable idp package.
Browse files Browse the repository at this point in the history
  • Loading branch information
korenyoni committed Feb 27, 2024
1 parent de02dd7 commit 081d560
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 554 deletions.
14 changes: 2 additions & 12 deletions codefresh/resource_account_idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/codefresh-io/terraform-provider-codefresh/codefresh/cfclient"
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/datautil"
"github.com/codefresh-io/terraform-provider-codefresh/codefresh/internal/idp"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -51,16 +52,14 @@ func resourceAccountIdp() *schema.Resource {
}),
),
// Defined in resource_idp, as schema is the same for global and account scoped IDPs
Schema: idpSchema,
Schema: idp.IdpSchema,
}
}

func resourceAccountIDPCreate(d *schema.ResourceData, meta interface{}) error {

client := meta.(*cfclient.Client)

id, err := client.CreateIDP(mapResourceToAccountIDP(d), false)

if err != nil {
log.Printf("[DEBUG] Error while creating idp. Error = %v", err)
return err
Expand All @@ -71,15 +70,13 @@ func resourceAccountIDPCreate(d *schema.ResourceData, meta interface{}) error {
}

func resourceAccountIDPRead(d *schema.ResourceData, meta interface{}) error {

client := meta.(*cfclient.Client)
idpID := d.Id()

var cfClientIDP *cfclient.IDP
var err error

cfClientIDP, err = client.GetAccountIdpByID(idpID)

if err != nil {
if err.Error() == fmt.Sprintf("[ERROR] IDP with ID %s isn't found.", d.Id()) {
d.SetId("")
Expand All @@ -91,7 +88,6 @@ func resourceAccountIDPRead(d *schema.ResourceData, meta interface{}) error {
}

err = mapAccountIDPToResource(*cfClientIDP, d)

if err != nil {
log.Printf("[DEBUG] Error while getting mapping response to IDP object. Error = %v", err)
return err
Expand All @@ -104,7 +100,6 @@ func resourceAccountIDPDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cfclient.Client)

err := client.DeleteIDPAccount(d.Id())

if err != nil {
log.Printf("[DEBUG] Error while deleting account level IDP. Error = %v", err)
return err
Expand All @@ -114,11 +109,9 @@ func resourceAccountIDPDelete(d *schema.ResourceData, meta interface{}) error {
}

func resourceAccountIDPUpdate(d *schema.ResourceData, meta interface{}) error {

client := meta.(*cfclient.Client)

err := client.UpdateIDP(mapResourceToAccountIDP(d), false)

if err != nil {
log.Printf("[DEBUG] Error while updating idp. Error = %v", err)
return err
Expand Down Expand Up @@ -204,7 +197,6 @@ func mapAccountIDPToResource(cfClientIDP cfclient.IDP, d *schema.ResourceData) e
if cfClientIDP.ClientType == "azure" {

syncInterval, err := strconv.Atoi(cfClientIDP.SyncInterval)

if err != nil {
return err
}
Expand Down Expand Up @@ -250,7 +242,6 @@ func mapAccountIDPToResource(cfClientIDP cfclient.IDP, d *schema.ResourceData) e

if cfClientIDP.ClientType == "saml" {
syncInterval, err := strconv.Atoi(cfClientIDP.SyncInterval)

if err != nil {
return err
}
Expand Down Expand Up @@ -291,7 +282,6 @@ func mapAccountIDPToResource(cfClientIDP cfclient.IDP, d *schema.ResourceData) e
}

func mapResourceToAccountIDP(d *schema.ResourceData) *cfclient.IDP {

cfClientIDP := &cfclient.IDP{
ID: d.Id(),
DisplayName: d.Get("display_name").(string),
Expand Down
Loading

0 comments on commit 081d560

Please sign in to comment.