-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
- Loading branch information
Showing
7 changed files
with
314 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
page_title: "authentik_property_mapping_source_plex Resource - terraform-provider-authentik" | ||
subcategory: "Customization" | ||
description: |- | ||
Manage Plex Source Property mappings | ||
--- | ||
|
||
# authentik_property_mapping_source_plex (Resource) | ||
|
||
Manage Plex Source Property mappings | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `expression` (String) | ||
- `name` (String) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
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,24 @@ | ||
--- | ||
page_title: "authentik_property_mapping_source_saml Resource - terraform-provider-authentik" | ||
subcategory: "Customization" | ||
description: |- | ||
Manage SAML Source Property mappings | ||
--- | ||
|
||
# authentik_property_mapping_source_saml (Resource) | ||
|
||
Manage SAML Source Property mappings | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `expression` (String) | ||
- `name` (String) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. |
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
92 changes: 92 additions & 0 deletions
92
internal/provider/resource_property_mapping_source_plex.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,92 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
api "goauthentik.io/api/v3" | ||
) | ||
|
||
func resourcePropertyMappingSourcePlex() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Customization --- Manage Plex Source Property mappings", | ||
CreateContext: resourcePropertyMappingSourcePlexCreate, | ||
ReadContext: resourcePropertyMappingSourcePlexRead, | ||
UpdateContext: resourcePropertyMappingSourcePlexUpdate, | ||
DeleteContext: resourcePropertyMappingSourcePlexDelete, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"expression": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DiffSuppressFunc: diffSuppressExpression, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourcePropertyMappingSourcePlexSchemaToProvider(d *schema.ResourceData) *api.PlexSourcePropertyMappingRequest { | ||
r := api.PlexSourcePropertyMappingRequest{ | ||
Name: d.Get("name").(string), | ||
Expression: d.Get("expression").(string), | ||
} | ||
return &r | ||
} | ||
|
||
func resourcePropertyMappingSourcePlexCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*APIClient) | ||
|
||
r := resourcePropertyMappingSourcePlexSchemaToProvider(d) | ||
|
||
res, hr, err := c.client.PropertymappingsApi.PropertymappingsSourcePlexCreate(ctx).PlexSourcePropertyMappingRequest(*r).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
|
||
d.SetId(res.Pk) | ||
return resourcePropertyMappingSourcePlexRead(ctx, d, m) | ||
} | ||
|
||
func resourcePropertyMappingSourcePlexRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
c := m.(*APIClient) | ||
|
||
res, hr, err := c.client.PropertymappingsApi.PropertymappingsSourcePlexRetrieve(ctx, d.Id()).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
|
||
setWrapper(d, "name", res.Name) | ||
setWrapper(d, "expression", res.Expression) | ||
return diags | ||
} | ||
|
||
func resourcePropertyMappingSourcePlexUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*APIClient) | ||
|
||
app := resourcePropertyMappingSourcePlexSchemaToProvider(d) | ||
|
||
res, hr, err := c.client.PropertymappingsApi.PropertymappingsSourcePlexUpdate(ctx, d.Id()).PlexSourcePropertyMappingRequest(*app).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
|
||
d.SetId(res.Pk) | ||
return resourcePropertyMappingSourcePlexRead(ctx, d, m) | ||
} | ||
|
||
func resourcePropertyMappingSourcePlexDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*APIClient) | ||
hr, err := c.client.PropertymappingsApi.PropertymappingsSourcePlexDestroy(ctx, d.Id()).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
return diag.Diagnostics{} | ||
} |
40 changes: 40 additions & 0 deletions
40
internal/provider/resource_property_mapping_source_plex_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,40 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccResourcePropertyMappingSourcePlex(t *testing.T) { | ||
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourcePropertyMappingSourcePlex(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("authentik_property_mapping_source_plex.name", "name", rName), | ||
), | ||
}, | ||
{ | ||
Config: testAccResourcePropertyMappingSourcePlex(rName + "test"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("authentik_property_mapping_source_plex.name", "name", rName+"test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourcePropertyMappingSourcePlex(name string) string { | ||
return fmt.Sprintf(` | ||
resource "authentik_property_mapping_source_plex" "name" { | ||
name = "%[1]s" | ||
expression = "return True" | ||
} | ||
`, name) | ||
} |
92 changes: 92 additions & 0 deletions
92
internal/provider/resource_property_mapping_source_saml.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,92 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
api "goauthentik.io/api/v3" | ||
) | ||
|
||
func resourcePropertyMappingSourceSAML() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Customization --- Manage SAML Source Property mappings", | ||
CreateContext: resourcePropertyMappingSourceSAMLCreate, | ||
ReadContext: resourcePropertyMappingSourceSAMLRead, | ||
UpdateContext: resourcePropertyMappingSourceSAMLUpdate, | ||
DeleteContext: resourcePropertyMappingSourceSAMLDelete, | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"expression": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DiffSuppressFunc: diffSuppressExpression, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourcePropertyMappingSourceSAMLSchemaToProvider(d *schema.ResourceData) *api.SAMLSourcePropertyMappingRequest { | ||
r := api.SAMLSourcePropertyMappingRequest{ | ||
Name: d.Get("name").(string), | ||
Expression: d.Get("expression").(string), | ||
} | ||
return &r | ||
} | ||
|
||
func resourcePropertyMappingSourceSAMLCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*APIClient) | ||
|
||
r := resourcePropertyMappingSourceSAMLSchemaToProvider(d) | ||
|
||
res, hr, err := c.client.PropertymappingsApi.PropertymappingsSourceSamlCreate(ctx).SAMLSourcePropertyMappingRequest(*r).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
|
||
d.SetId(res.Pk) | ||
return resourcePropertyMappingSourceSAMLRead(ctx, d, m) | ||
} | ||
|
||
func resourcePropertyMappingSourceSAMLRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
c := m.(*APIClient) | ||
|
||
res, hr, err := c.client.PropertymappingsApi.PropertymappingsSourceSamlRetrieve(ctx, d.Id()).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
|
||
setWrapper(d, "name", res.Name) | ||
setWrapper(d, "expression", res.Expression) | ||
return diags | ||
} | ||
|
||
func resourcePropertyMappingSourceSAMLUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*APIClient) | ||
|
||
app := resourcePropertyMappingSourceSAMLSchemaToProvider(d) | ||
|
||
res, hr, err := c.client.PropertymappingsApi.PropertymappingsSourceSamlUpdate(ctx, d.Id()).SAMLSourcePropertyMappingRequest(*app).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
|
||
d.SetId(res.Pk) | ||
return resourcePropertyMappingSourceSAMLRead(ctx, d, m) | ||
} | ||
|
||
func resourcePropertyMappingSourceSAMLDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*APIClient) | ||
hr, err := c.client.PropertymappingsApi.PropertymappingsSourceSamlDestroy(ctx, d.Id()).Execute() | ||
if err != nil { | ||
return httpToDiag(d, hr, err) | ||
} | ||
return diag.Diagnostics{} | ||
} |
40 changes: 40 additions & 0 deletions
40
internal/provider/resource_property_mapping_source_saml_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,40 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccResourcePropertyMappingSourceSAML(t *testing.T) { | ||
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
resource.UnitTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: providerFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourcePropertyMappingSourceSAML(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("authentik_property_mapping_source_saml.name", "name", rName), | ||
), | ||
}, | ||
{ | ||
Config: testAccResourcePropertyMappingSourceSAML(rName + "test"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("authentik_property_mapping_source_saml.name", "name", rName+"test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourcePropertyMappingSourceSAML(name string) string { | ||
return fmt.Sprintf(` | ||
resource "authentik_property_mapping_source_saml" "name" { | ||
name = "%[1]s" | ||
expression = "return True" | ||
} | ||
`, name) | ||
} |