Skip to content

Commit

Permalink
Checking if resource server scopes is empty for auth0 tf generate (#…
Browse files Browse the repository at this point in the history
…856)

* Checking resource server scopes if empty before exporting

* Linting applied

* Using getter

---------

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
willvedd and willvedd authored Sep 26, 2023
1 parent c9c09f2 commit 2e785d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
11 changes: 7 additions & 4 deletions internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,13 @@ func (f *resourceServerResourceFetcher) FetchData(ctx context.Context) (importDa
ResourceName: "auth0_resource_server." + sanitizeResourceName(api.GetName()),
ImportID: api.GetID(),
})
data = append(data, importDataItem{
ResourceName: "auth0_resource_server_scopes." + sanitizeResourceName(api.GetName()),
ImportID: api.GetID(),
})

if len(api.GetScopes()) > 0 {
data = append(data, importDataItem{
ResourceName: "auth0_resource_server_scopes." + sanitizeResourceName(api.GetName()),
ImportID: api.GetID(),
})
}
}

if !apis.HasNext() {
Expand Down
32 changes: 19 additions & 13 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,12 @@ func TestResourceServerResourceFetcher_FetchData(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockScopes := []management.ResourceServerScope{
{Value: auth0.String("read:user")},
{Value: auth0.String("create:user")},
}
mockScopesEmpty := []management.ResourceServerScope{}

resourceServerAPI := mock.NewMockResourceServerAPI(ctrl)
resourceServerAPI.EXPECT().
List(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Expand All @@ -946,12 +952,14 @@ func TestResourceServerResourceFetcher_FetchData(t *testing.T) {
},
ResourceServers: []*management.ResourceServer{
{
ID: auth0.String("610e04b71f71b9003a7eb3df"),
Name: auth0.String("Auth0 Management API"),
ID: auth0.String("610e04b71f71b9003a7eb3df"),
Name: auth0.String("Auth0 Management API"),
Scopes: &mockScopes,
},
{
ID: auth0.String("6358fed7b77d3c391dd78a40"),
Name: auth0.String("Payments API"),
ID: auth0.String("6358fed7b77d3c391dd78a40"),
Name: auth0.String("Payments API"),
Scopes: &mockScopes,
},
},
},
Expand All @@ -968,12 +976,14 @@ func TestResourceServerResourceFetcher_FetchData(t *testing.T) {
},
ResourceServers: []*management.ResourceServer{
{
ID: auth0.String("66ef6f9c435cab03def5fa16"),
Name: auth0.String("Blog API"),
ID: auth0.String("66ef6f9c435cab03def5fa16"),
Name: auth0.String("Blog API"),
Scopes: &mockScopes,
},
{
ID: auth0.String("63bf6f9b0e025715cb91ce7c"),
Name: auth0.String("User API"),
ID: auth0.String("63bf6f9b0e025715cb91ce7c"),
Name: auth0.String("API with no scopes"),
Scopes: &mockScopesEmpty,
},
},
},
Expand Down Expand Up @@ -1012,11 +1022,7 @@ func TestResourceServerResourceFetcher_FetchData(t *testing.T) {
ImportID: "66ef6f9c435cab03def5fa16",
},
{
ResourceName: "auth0_resource_server.user_api",
ImportID: "63bf6f9b0e025715cb91ce7c",
},
{
ResourceName: "auth0_resource_server_scopes.user_api",
ResourceName: "auth0_resource_server.api_with_no_scopes",
ImportID: "63bf6f9b0e025715cb91ce7c",
},
}
Expand Down

0 comments on commit 2e785d6

Please sign in to comment.