-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(terraform-provider-jans): update terraform module (#4164)
* fix(terraform-provider-jans): update terraform provider Signed-off-by: moabu <47318409+moabu@users.noreply.github.com> * docs: update CHANGELOG.md --------- Signed-off-by: moabu <47318409+moabu@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
230 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "jans_plugins Data Source - terraform-provider-jans" | ||
subcategory: "" | ||
description: |- | ||
Data source for retrieving the plugins that are configured in the Janssen server | ||
--- | ||
|
||
# jans_plugins (Data Source) | ||
|
||
Data source for retrieving the plugins that are configured in the Janssen server | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `enabled` (List of Object) List of all enabled plugins (see [below for nested schema](#nestedatt--enabled)) | ||
- `id` (String) The ID of this resource. | ||
|
||
<a id="nestedatt--enabled"></a> | ||
### Nested Schema for `enabled` | ||
|
||
Read-Only: | ||
|
||
- `class_name` (String) | ||
- `description` (String) | ||
- `name` (String) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package jans | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// PluginConf represents a single plugin enabled on the server. | ||
type PluginConf struct { | ||
Name string `schema:"name" json:"name,omitempty"` | ||
Description string `schema:"description" json:"description,omitempty"` | ||
ClassName string `schema:"class_name" json:"className,omitempty"` | ||
} | ||
|
||
// Plugins holds the list of all plugins currently enabled on the server. | ||
type Plugins struct { | ||
Enabled []PluginConf `schema:"enabled"` | ||
} | ||
|
||
// GetPlugins returns the list of plugins currently enabled on the server. | ||
func (c *Client) GetPlugins(ctx context.Context) ([]PluginConf, error) { | ||
|
||
token, err := c.getToken(ctx, "https://jans.io/oauth/config/plugin.readonly") | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get token: %w", err) | ||
} | ||
|
||
ret := []PluginConf{} | ||
|
||
if err := c.get(ctx, "/jans-config-api/api/v1/plugin", token, &ret); err != nil { | ||
return nil, fmt.Errorf("get request failed: %w", err) | ||
} | ||
|
||
return ret, nil | ||
} |
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,25 @@ | ||
package jans | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestPlugins(t *testing.T) { | ||
|
||
client, err := NewInsecureClient(host, user, pass) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
plugins, err := client.GetPlugins(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(plugins) != 3 { | ||
t.Fatal("expected 3 plugins, got ", len(plugins)) | ||
} | ||
} |
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,66 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/jans/terraform-provider-jans/jans" | ||
) | ||
|
||
func dataSourcePlugins() *schema.Resource { | ||
|
||
return &schema.Resource{ | ||
Description: "Data source for retrieving the plugins that are configured in the Janssen server", | ||
ReadContext: dataSourcePluginsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"enabled": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "List of all enabled plugins", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "Name of the plugin", | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Description: "Description of the plugin", | ||
Computed: true, | ||
}, | ||
"class_name": { | ||
Type: schema.TypeString, | ||
Description: "Class name of the plugin", | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePluginsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
c := meta.(*jans.Client) | ||
|
||
pluginConfig, err := c.GetPlugins(ctx) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
plugins := jans.Plugins{ | ||
Enabled: pluginConfig, | ||
} | ||
|
||
if err := toSchemaResource(d, plugins); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(strconv.FormatInt(time.Now().Unix(), 10)) | ||
|
||
return nil | ||
} |
62 changes: 62 additions & 0 deletions
62
terraform-provider-jans/provider/data_source_plugins_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,62 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/jans/terraform-provider-jans/jans" | ||
) | ||
|
||
func TestDatasourcePlugins_Mapping(t *testing.T) { | ||
|
||
schema := dataSourcePlugins() | ||
|
||
data := schema.Data(nil) | ||
|
||
plugins := jans.Plugins{ | ||
Enabled: []jans.PluginConf{ | ||
{ | ||
Name: "fidoe2", | ||
}, | ||
}, | ||
} | ||
|
||
if err := toSchemaResource(data, &plugins); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
newPlugins := jans.Plugins{} | ||
|
||
if err := fromSchemaResource(data, &newPlugins); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if diff := cmp.Diff(plugins, newPlugins); diff != "" { | ||
t.Errorf("Got different plugins after mapping: %s", diff) | ||
} | ||
|
||
} | ||
|
||
func TestAccDataSourcePlugins_basic(t *testing.T) { | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourcePlugins_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.jans_plugins.all", "enabled.0.name", "fido2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourcePlugins_basic() string { | ||
return ` | ||
data "jans_plugins" "all" { | ||
} | ||
` | ||
} |
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