Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
wip generate some more data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
iwarapter committed Apr 29, 2023
1 parent 7948c51 commit 94ff6fc
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 245 deletions.
31 changes: 31 additions & 0 deletions docs/data-sources/keypair_ssl_server_certificate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "pingfederate_keypair_ssl_server_certificate Data Source - terraform-provider-pingfederate"
subcategory: ""
description: |-
---

# pingfederate_keypair_ssl_server_certificate (Data Source)



## Example Usage

```terraform
data "pingfederate_keypair_ssl_server_certificate" "csr" {
id = pingfederate_keypair_ssl_server.demo_generate.id
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `key_pair_id` (String) ID of the key pair.

### Read-Only

- `certificate` (String) PEM-encoded CSR of the ssl server keypair.
- `id` (String) The ID of this resource.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "pingfederate_keypair_ssl_server_certificate" "csr" {
id = pingfederate_keypair_ssl_server.demo_generate.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "pingfederate_keypair_ssl_server" "demo_generate" {
city = "Test"
common_name = "Test"
country = "GB"
key_algorithm = "RSA"
key_size = 2048
organization = "Test"
organization_unit = "Test"
state = "Test"
valid_days = 365
subject_alternative_names = ["foo", "bar"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package framework

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/iwarapter/pingfederate-sdk-go/services/keyPairsSslServer"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/path"
)

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &pingfederateKeyPairSslServerCertificateDataSource{}
_ datasource.DataSourceWithConfigure = &pingfederateKeyPairSslServerCertificateDataSource{}
)

type pingfederateKeyPairSslServerCertificateDataSource struct {
client *pfClient
}

func NewKeyPairSslServerCertificateDataSource() datasource.DataSource {
return &pingfederateKeyPairSslServerCertificateDataSource{}
}

func (p *pingfederateKeyPairSslServerCertificateDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_keypair_ssl_server_certificate"
}

func (p *pingfederateKeyPairSslServerCertificateDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

p.client = req.ProviderData.(*pfClient)
}

func (p *pingfederateKeyPairSslServerCertificateDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"key_pair_id": schema.StringAttribute{
Description: "ID of the key pair.",
Required: true,
},
"certificate": schema.StringAttribute{
Description: "PEM-encoded CSR of the ssl server keypair.",
Computed: true,
},
},
}
}

func (p *pingfederateKeyPairSslServerCertificateDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
type KeyPairIdData struct {
Id types.String `tfsdk:"id"`
KeyPairId types.String `tfsdk:"key_pair_id"`
Certificate types.String `tfsdk:"certificate"`
}

var data KeyPairIdData
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

cert, _, err := p.client.KeyPairsSslServer.ExportCertificateFileWithContext(ctx, &keyPairsSslServer.ExportCertificateFileInput{Id: data.KeyPairId.ValueString()})
if err != nil {
resp.Diagnostics.AddError("Unable to read keypair ssl server settings certificate", err.Error())
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), data.KeyPairId.ValueString())...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("key_pair_id"), data.KeyPairId.ValueString())...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("certificate"), *cert)...)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package framework

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccPingFederateKeyPairSslServerCertificateDatasource(t *testing.T) {
resourceName := "data.pingfederate_keypair_ssl_server_certificate.test"
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccPingFederateKeyPairSslServerCertificateDatasourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "certificate"),
),
},
},
})
}

func testAccPingFederateKeyPairSslServerCertificateDatasourceConfig() string {
return `
resource "pingfederate_keypair_ssl_server" "example" {
common_name = "localhost"
country = "GB"
key_algorithm = "RSA"
key_size = 2048
organization = "Test"
valid_days = 365
lifecycle {
create_before_destroy = true
}
}
data "pingfederate_keypair_ssl_server_certificate" "test" {
key_pair_id = pingfederate_keypair_ssl_server.example.id
}
resource "pingfederate_certificates_ca" "demo" {
certificate_id = "local"
file_data = base64encode(data.pingfederate_keypair_ssl_server_certificate.test.certificate)
}
`
}
85 changes: 35 additions & 50 deletions internal/framework/datasource_schemas.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package framework

import (
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func AuthorizationServerSettingsSchema() schema.Schema {
func datasourceAuthorizationServerSettings() schema.Schema {
return schema.Schema{
Description: `Authorization Server Settings attributes.`,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"activation_code_check_mode": schema.StringAttribute{
Description: `Determines whether the user is prompted to enter or confirm the activation code after authenticating or before. The default is AFTER_AUTHENTICATION.`,
Computed: true,
Expand Down Expand Up @@ -89,6 +84,10 @@ func AuthorizationServerSettingsSchema() schema.Schema {
Attributes: listScopeEntry(),
},
},
"id": schema.StringAttribute{
Description: ``,
Computed: true,
},
"include_issuer_in_authorization_response": schema.BoolAttribute{
Description: `Determines whether the authorization server's issuer value is added to the authorization response or not. The default value is false.`,
Computed: true,
Expand All @@ -108,19 +107,15 @@ func AuthorizationServerSettingsSchema() schema.Schema {
"par_status": schema.StringAttribute{
Description: `The status of pushed authorization request support. The default value is ENABLED.`,
Computed: true,
Validators: []validator.String{
stringvalidator.OneOf("DISABLED", "ENABLED", "REQUIRED"),
},
},
"pending_authorization_timeout": schema.NumberAttribute{
Description: `The 'device_code' and 'user_code' timeout, in seconds.`,
Computed: true,
},
"persistent_grant_contract": schema.SingleNestedAttribute{
Description: `The persistent grant contract defines attributes that are associated with OAuth persistent grants.`,

Computed: true,
Attributes: singlePersistentGrantContract(),
Computed: true,
Attributes: singlePersistentGrantContract(),
},
"persistent_grant_idle_timeout": schema.NumberAttribute{
Description: `The persistent grant idle timeout. The default value is 30 (days). -1 indicates an indefinite amount of time.`,
Expand All @@ -129,9 +124,6 @@ func AuthorizationServerSettingsSchema() schema.Schema {
"persistent_grant_idle_timeout_time_unit": schema.StringAttribute{
Description: `The persistent grant idle timeout time unit.`,
Computed: true,
Validators: []validator.String{
stringvalidator.OneOf("MINUTES", "DAYS", "HOURS"),
},
},
"persistent_grant_lifetime": schema.NumberAttribute{
Description: `The persistent grant lifetime. The default value is indefinite. -1 indicates an indefinite amount of time.`,
Expand All @@ -140,13 +132,9 @@ func AuthorizationServerSettingsSchema() schema.Schema {
"persistent_grant_lifetime_unit": schema.StringAttribute{
Description: `The persistent grant lifetime unit.`,
Computed: true,
Validators: []validator.String{
stringvalidator.OneOf("MINUTES", "DAYS", "HOURS"),
},
},
"persistent_grant_reuse_grant_types": schema.ListAttribute{
Description: `The grant types that the OAuth AS can reuse rather than creating a new grant for each request. Only 'IMPLICIT' or 'AUTHORIZATION_CODE' or 'RESOURCE_OWNER_CREDENTIALS' are valid grant types.`,

Computed: true,
ElementType: types.StringType,
},
Expand Down Expand Up @@ -203,9 +191,6 @@ func AuthorizationServerSettingsSchema() schema.Schema {
"user_authorization_consent_page_setting": schema.StringAttribute{
Description: `User Authorization Consent Page setting to use PingFederate's internal consent page or an external system`,
Computed: true,
Validators: []validator.String{
stringvalidator.OneOf("INTERNAL", "ADAPTER"),
},
},
"user_authorization_url": schema.StringAttribute{
Description: `The URL used to generate 'verification_url' and 'verification_url_complete' values in a Device Authorization request`,
Expand All @@ -215,6 +200,34 @@ func AuthorizationServerSettingsSchema() schema.Schema {
}
}

func listPersistentGrantAttribute() map[string]schema.Attribute {
return map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: `The name of this attribute.`,
Computed: true,
},
}
}

func singlePersistentGrantContract() map[string]schema.Attribute {
return map[string]schema.Attribute{
"core_attributes": schema.ListNestedAttribute{
Description: `This is a read-only list of persistent grant attributes and includes USER_KEY and USER_NAME. Changes to this field will be ignored.`,
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: listPersistentGrantAttribute(),
},
},
"extended_attributes": schema.ListNestedAttribute{
Description: `A list of additional attributes for the persistent grant contract.`,
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: listPersistentGrantAttribute(),
},
},
}
}

func listScopeEntry() map[string]schema.Attribute {
return map[string]schema.Attribute{
"description": schema.StringAttribute{
Expand Down Expand Up @@ -249,31 +262,3 @@ func listScopeGroupEntry() map[string]schema.Attribute {
},
}
}

func listPersistentGrantAttribute() map[string]schema.Attribute {
return map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: `The name of this attribute.`,
Computed: true,
},
}
}

func singlePersistentGrantContract() map[string]schema.Attribute {
return map[string]schema.Attribute{
"core_attributes": schema.ListNestedAttribute{
Description: `This is a read-only list of persistent grant attributes and includes USER_KEY and USER_NAME. Changes to this field will be ignored.`,
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: listPersistentGrantAttribute(),
},
},
"extended_attributes": schema.ListNestedAttribute{
Description: `A list of additional attributes for the persistent grant contract.`,
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: listPersistentGrantAttribute(),
},
},
}
}

0 comments on commit 94ff6fc

Please sign in to comment.