Skip to content

Commit

Permalink
Move clients data source files into client package
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-brenton committed Nov 25, 2024
1 parent 0ad702b commit ff940bc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clients
package client

import (
"context"
Expand All @@ -11,12 +11,11 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/auth0/terraform-provider-auth0/internal/auth0/client"
"github.com/auth0/terraform-provider-auth0/internal/config"
)

// NewDataSource will return a new auth0_clients data source.
func NewDataSource() *schema.Resource {
// NewClientsDataSource will return a new auth0_clients data source.
func NewClientsDataSource() *schema.Resource {
return &schema.Resource{
ReadContext: readClientsForDataSource,
Description: "Data source to retrieve a list of Auth0 application clients with optional filtering.",
Expand All @@ -32,7 +31,7 @@ func NewDataSource() *schema.Resource {
Description: "Filter clients by application types.",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(client.ValidAppTypes, false),
ValidateFunc: validation.StringInSlice(ValidAppTypes, false),
},
},
"is_first_party": {
Expand All @@ -53,7 +52,7 @@ func NewDataSource() *schema.Resource {
}

func coreClientDataSourceSchema() map[string]*schema.Schema {
clientSchema := client.NewDataSource().Schema
clientSchema := dataSourceSchema()

// Remove unused fields from the client schema.
fieldsToRemove := []string{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clients_test
package client_test

import (
"fmt"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/auth0/terraform-provider-auth0/internal/acctest"
)

const testAccGivenAClient = `
const testAccGivenSomeClients = `
resource "auth0_client" "my_client_1" {
name = "Acceptance Test 1 - {{.testName}}"
app_type = "non_interactive"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestAccDataClientsNameFilter(t *testing.T) {
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
{
Config: acctest.ParseTestName(testAccGivenAClient+testAccDataClientsWithNameFilter, t.Name()),
Config: acctest.ParseTestName(testAccGivenSomeClients+testAccDataClientsWithNameFilter, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.auth0_clients.test", "id"),
resource.TestCheckResourceAttr("data.auth0_clients.test", "clients.#", "2"),
Expand All @@ -87,7 +87,7 @@ func TestAccDataClientsAppTypeFilter(t *testing.T) {
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
{
Config: acctest.ParseTestName(testAccGivenAClient+testAccDataClientsWithAppTypeFilter, t.Name()),
Config: acctest.ParseTestName(testAccGivenSomeClients+testAccDataClientsWithAppTypeFilter, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.auth0_clients.test", "id"),
resource.TestCheckResourceAttr("data.auth0_clients.test", "clients.#", "1"),
Expand All @@ -104,10 +104,12 @@ func TestAccDataClientsIsFirstPartyFilter(t *testing.T) {
PreventPostDestroyRefresh: true,
Steps: []resource.TestStep{
{
Config: acctest.ParseTestName(testAccGivenAClient+testAccDataClientsWithIsFirstPartyFilter, t.Name()),
Config: acctest.ParseTestName(testAccGivenSomeClients+testAccDataClientsWithIsFirstPartyFilter, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.auth0_clients.test", "id"),
resource.TestCheckResourceAttr("data.auth0_clients.test", "clients.#", "1"),
resource.TestCheckResourceAttr("data.auth0_clients.test", "clients.0.is_first_party", "true"),
resource.TestCheckResourceAttr("data.auth0_clients.test", "clients.0.name", fmt.Sprintf("Acceptance Test 1 - %v", t.Name())),
),
},
},
Expand Down
29 changes: 29 additions & 0 deletions internal/auth0/client/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,32 @@ func flattenCredentials(

return stateCredentials, nil
}

func flattenClientList(data *schema.ResourceData, clients []*management.Client) error {
if clients == nil {
return data.Set("clients", make([]map[string]interface{}, 0))
}

clientList := make([]map[string]interface{}, 0, len(clients))
for _, client := range clients {
clientMap := map[string]interface{}{
"client_id": client.GetClientID(),
"client_secret": client.GetClientSecret(),
"name": client.GetName(),
"description": client.GetDescription(),
"app_type": client.GetAppType(),
"is_first_party": client.GetIsFirstParty(),
"is_token_endpoint_ip_header_trusted": client.GetIsTokenEndpointIPHeaderTrusted(),
"callbacks": client.GetCallbacks(),
"allowed_logout_urls": client.GetAllowedLogoutURLs(),
"allowed_origins": client.GetAllowedOrigins(),
"allowed_clients": client.GetAllowedClients(),
"grant_types": client.GetGrantTypes(),
"web_origins": client.GetWebOrigins(),
"client_metadata": client.GetClientMetadata(),
}
clientList = append(clientList, clientMap)
}

return data.Set("clients", clientList)
}
35 changes: 0 additions & 35 deletions internal/auth0/clients/flatten.go

This file was deleted.

3 changes: 1 addition & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/auth0/terraform-provider-auth0/internal/auth0/attackprotection"
"github.com/auth0/terraform-provider-auth0/internal/auth0/branding"
"github.com/auth0/terraform-provider-auth0/internal/auth0/client"
"github.com/auth0/terraform-provider-auth0/internal/auth0/clients"
"github.com/auth0/terraform-provider-auth0/internal/auth0/connection"
"github.com/auth0/terraform-provider-auth0/internal/auth0/customdomain"
"github.com/auth0/terraform-provider-auth0/internal/auth0/email"
Expand Down Expand Up @@ -156,7 +155,7 @@ func New() *schema.Provider {
"auth0_branding": branding.NewDataSource(),
"auth0_branding_theme": branding.NewThemeDataSource(),
"auth0_client": client.NewDataSource(),
"auth0_clients": clients.NewDataSource(),
"auth0_clients": client.NewClientsDataSource(),
"auth0_connection": connection.NewDataSource(),
"auth0_connection_scim_configuration": connection.NewSCIMConfigurationDataSource(),
"auth0_custom_domain": customdomain.NewDataSource(),
Expand Down

0 comments on commit ff940bc

Please sign in to comment.