Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking if resource server scopes is empty for auth0 tf generate #856

Merged
merged 7 commits into from
Sep 26, 2023
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
Loading