Skip to content

Commit

Permalink
add plex and saml source pm
Browse files Browse the repository at this point in the history
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
  • Loading branch information
rissson committed Aug 12, 2024
1 parent b454204 commit db8828f
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/resources/property_mapping_source_plex.md
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.
24 changes: 24 additions & 0 deletions docs/resources/property_mapping_source_saml.md
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.
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func Provider(version string, testing bool) *schema.Provider {
"authentik_property_mapping_provider_scope": tr(resourcePropertyMappingProviderScope),
"authentik_property_mapping_source_ldap": tr(resourcePropertyMappingSourceLDAP),
"authentik_property_mapping_source_oauth": tr(resourcePropertyMappingSourceOAuth),
"authentik_property_mapping_source_plex": tr(resourcePropertyMappingSourcePlex),
"authentik_property_mapping_source_saml": tr(resourcePropertyMappingSourceSAML),
"authentik_property_mapping_source_scim": tr(resourcePropertyMappingSourceSCIM),
"authentik_provider_google_workspace": tr(resourceProviderGoogleWorkspace),
"authentik_provider_ldap": tr(resourceProviderLDAP),
Expand Down
92 changes: 92 additions & 0 deletions internal/provider/resource_property_mapping_source_plex.go
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)

Check warning on line 63 in internal/provider/resource_property_mapping_source_plex.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/resource_property_mapping_source_plex.go#L63

Added line #L63 was not covered by tests
}

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)

Check warning on line 78 in internal/provider/resource_property_mapping_source_plex.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/resource_property_mapping_source_plex.go#L78

Added line #L78 was not covered by tests
}

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)

Check warning on line 89 in internal/provider/resource_property_mapping_source_plex.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/resource_property_mapping_source_plex.go#L89

Added line #L89 was not covered by tests
}
return diag.Diagnostics{}
}
40 changes: 40 additions & 0 deletions internal/provider/resource_property_mapping_source_plex_test.go
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 internal/provider/resource_property_mapping_source_saml.go
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)

Check warning on line 63 in internal/provider/resource_property_mapping_source_saml.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/resource_property_mapping_source_saml.go#L63

Added line #L63 was not covered by tests
}

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)

Check warning on line 78 in internal/provider/resource_property_mapping_source_saml.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/resource_property_mapping_source_saml.go#L78

Added line #L78 was not covered by tests
}

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)

Check warning on line 89 in internal/provider/resource_property_mapping_source_saml.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/resource_property_mapping_source_saml.go#L89

Added line #L89 was not covered by tests
}
return diag.Diagnostics{}
}
40 changes: 40 additions & 0 deletions internal/provider/resource_property_mapping_source_saml_test.go
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)
}

0 comments on commit db8828f

Please sign in to comment.