diff --git a/internal/btpcli/client_test.go b/internal/btpcli/client_test.go index d05148f4..ee588adb 100644 --- a/internal/btpcli/client_test.go +++ b/internal/btpcli/client_test.go @@ -287,21 +287,21 @@ func TestV2Client_BrowserLogin(t *testing.T) { srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { _, _ = w.Write([]byte("{\"loginId\":\"login.id\",\"subdomainRequired\":false}")) - } else if strings.Contains(r.URL.Path, "/login.id"){ + } else if strings.Contains(r.URL.Path, "/login.id") { res, _ := io.ReadAll(r.Body) - + idp := strings.Split(strings.Split(string(res), ",")[0], ":")[1] if idp == "\"\"" { idp = "accounts.sap.com" } else { idp = "customidp.accounts.ondemand.com" } - + w.Header().Add("HeaderCLISessionId", "sessionid") w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte("{\"issuer\":\""+idp+"\",\"refreshToken\":\"sessionid\",\"user\":\"john.doe\",\"mail\":\"john.doe@test.com\"}")) + _, _ = w.Write([]byte("{\"issuer\":\"" + idp + "\",\"refreshToken\":\"sessionid\",\"user\":\"john.doe\",\"mail\":\"john.doe@test.com\"}")) } else { w.WriteHeader(http.StatusForbidden) } @@ -334,7 +334,7 @@ func TestV2Client_BrowserLogin(t *testing.T) { }, }, uut.session) }) - + t.Run("happy path - with custom idp", func(t *testing.T) { uut := NewV2ClientWithHttpClient(srv.Client(), srvUrl) uut.session = &Session{} @@ -342,7 +342,7 @@ func TestV2Client_BrowserLogin(t *testing.T) { return "fake-correlation-id" } _, err := uut.BrowserLogin(context.TODO(), &BrowserLoginRequest{ - CustomIdp: "my.custom.idp", + CustomIdp: "my.custom.idp", GlobalAccountSubdomain: "my-subdomain", }) diff --git a/internal/btpcli/clienttypes.go b/internal/btpcli/clienttypes.go index 15ffce03..8ca6d4c4 100644 --- a/internal/btpcli/clienttypes.go +++ b/internal/btpcli/clienttypes.go @@ -70,8 +70,8 @@ type LoginResponse struct { type BrowserLoginPostResponse struct { Issuer string `json:"issuer"` RefreshToken string `json:"refreshToken"` - Username string `json:"user"` - Email string `json:"mail"` + Username string `json:"user"` + Email string `json:"mail"` } type BrowserResponse struct { @@ -79,7 +79,6 @@ type BrowserResponse struct { SubdomainRequired bool `json:"subdomainRequired"` } - /* Command */ func NewCommandRequest(action Action, command string, args any) *CommandRequest { return &CommandRequest{ diff --git a/internal/btpcli/facade_accounts_entitlement_test.go b/internal/btpcli/facade_accounts_entitlement_test.go index c548bba7..21f726ea 100644 --- a/internal/btpcli/facade_accounts_entitlement_test.go +++ b/internal/btpcli/facade_accounts_entitlement_test.go @@ -122,7 +122,7 @@ func TestAccountsEntitlementFacade_AssignToSubaccount(t *testing.T) { assertCall(t, r, command, ActionAssign, map[string]string{ "globalAccount": "795b53bb-a3f0-4769-adf0-26173282a975", - "directoryID": directoryId, + "directoryID": directoryId, "subaccount": subaccountId, "serviceName": serviceName, "servicePlanName": planName, @@ -155,7 +155,7 @@ func TestAccountsEntitlementFacade_EnableInSubaccount(t *testing.T) { assertCall(t, r, command, ActionAssign, map[string]string{ "globalAccount": "795b53bb-a3f0-4769-adf0-26173282a975", - "directoryID": directoryId, + "directoryID": directoryId, "subaccount": subaccountId, "serviceName": serviceName, "servicePlanName": planName, @@ -188,7 +188,7 @@ func TestAccountsEntitlementFacade_DisableInSubaccount(t *testing.T) { assertCall(t, r, command, ActionAssign, map[string]string{ "globalAccount": "795b53bb-a3f0-4769-adf0-26173282a975", - "directoryID": directoryId, + "directoryID": directoryId, "subaccount": subaccountId, "serviceName": serviceName, "servicePlanName": planName, diff --git a/internal/btpcli/facade_accounts_global_account.go b/internal/btpcli/facade_accounts_global_account.go index 07f6a24c..db2fd274 100644 --- a/internal/btpcli/facade_accounts_global_account.go +++ b/internal/btpcli/facade_accounts_global_account.go @@ -29,4 +29,4 @@ func (f *accountsGlobalAccountFacade) GetWithHierarchy(ctx context.Context) (cis "globalAccount": f.cliClient.GetGlobalAccountSubdomain(), "showHierarchy": "true", })) -} \ No newline at end of file +} diff --git a/internal/btpcli/facade_services_instance.go b/internal/btpcli/facade_services_instance.go index 0763eebc..af721c85 100644 --- a/internal/btpcli/facade_services_instance.go +++ b/internal/btpcli/facade_services_instance.go @@ -165,9 +165,9 @@ func (f servicesInstanceFacade) Update(ctx context.Context, args *ServiceInstanc } type ServiceInstanceShareInput struct { - Id string `btpcli:"id"` - Subaccount string `btpcli:"subaccount"` - Name string `btpcli:"name"` + Id string `btpcli:"id"` + Subaccount string `btpcli:"subaccount"` + Name string `btpcli:"name"` } func (f servicesInstanceFacade) Share(ctx context.Context, args *ServiceInstanceShareInput) (servicemanager.ServiceInstanceResponseObject, CommandResponse, error) { diff --git a/internal/provider/datasource_globalaccount_security_settings_test.go b/internal/provider/datasource_globalaccount_security_settings_test.go index c3ea7900..1c9b5f50 100644 --- a/internal/provider/datasource_globalaccount_security_settings_test.go +++ b/internal/provider/datasource_globalaccount_security_settings_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestDataSourceGlobalAccountSecuritySettings(t *testing.T) { +func TestDataSourceGlobalaccountSecuritySettings(t *testing.T) { t.Parallel() t.Run("happy path - security settings by id", func(t *testing.T) { diff --git a/internal/provider/datasource_globalaccount_test.go b/internal/provider/datasource_globalaccount_test.go index be53ecc7..6b105580 100644 --- a/internal/provider/datasource_globalaccount_test.go +++ b/internal/provider/datasource_globalaccount_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestDataSourceGlobalAccount(t *testing.T) { +func TestDataSourceGlobalaccount(t *testing.T) { t.Parallel() t.Run("happy path", func(t *testing.T) { rec, user := setupVCR(t, "fixtures/datasource_globalaccount") @@ -22,7 +22,7 @@ func TestDataSourceGlobalAccount(t *testing.T) { ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), Steps: []resource.TestStep{ { - Config: hclProviderFor(user) + hclDatasourceGlobalAccount("uut"), + Config: hclProviderFor(user) + hclDatasourceGlobalaccount("uut"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.btp_globalaccount.uut", "id", "03760ecf-9d89-4189-a92a-1c7efed09298"), resource.TestCheckResourceAttr("data.btp_globalaccount.uut", "name", "terraform-integration-canary"), @@ -53,7 +53,7 @@ func TestDataSourceGlobalAccount(t *testing.T) { ProtoV6ProviderFactories: getProviders(srv.Client()), Steps: []resource.TestStep{ { - Config: hclProviderForCLIServerAt(srv.URL) + hclDatasourceGlobalAccount("uut"), + Config: hclProviderForCLIServerAt(srv.URL) + hclDatasourceGlobalaccount("uut"), ExpectError: regexp.MustCompile(`received response with unexpected status \[Status: 404; Correlation ID:\s+[a-f0-9\-]+\]`), }, }, @@ -61,6 +61,6 @@ func TestDataSourceGlobalAccount(t *testing.T) { }) } -func hclDatasourceGlobalAccount(resourceName string) string { +func hclDatasourceGlobalaccount(resourceName string) string { return fmt.Sprintf(`data "btp_globalaccount" "%s" {}`, resourceName) } diff --git a/internal/provider/datasource_globalaccount_with_hierarchy.go b/internal/provider/datasource_globalaccount_with_hierarchy.go index b324585d..be8321de 100644 --- a/internal/provider/datasource_globalaccount_with_hierarchy.go +++ b/internal/provider/datasource_globalaccount_with_hierarchy.go @@ -396,9 +396,9 @@ __Further documentation:__ func (ds *globalaccountWithHierarchyDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { - var globalAccountData globalAccountHierarchyType + var globalaccountData globalaccountHierarchyType - diags := req.Config.Get(ctx, &globalAccountData) + diags := req.Config.Get(ctx, &globalaccountData) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -411,9 +411,9 @@ func (ds *globalaccountWithHierarchyDataSource) Read(ctx context.Context, req da return } - globalAccountData, diags = globalAccountHierarchyValueFrom(ctx, cliRes) + globalaccountData, diags = globalaccountHierarchyValueFrom(ctx, cliRes) resp.Diagnostics.Append(diags...) - diags = resp.State.Set(ctx, &globalAccountData) + diags = resp.State.Set(ctx, &globalaccountData) resp.Diagnostics.Append(diags...) } diff --git a/internal/provider/resource_globalaccount_role_collection_test.go b/internal/provider/resource_globalaccount_role_collection_test.go index f8d5cbc9..784404b0 100644 --- a/internal/provider/resource_globalaccount_role_collection_test.go +++ b/internal/provider/resource_globalaccount_role_collection_test.go @@ -16,7 +16,7 @@ type globalaccountRoleCollectionRoleRefTestType struct { RoleTemplateName string `json:"role_template_name"` } -func TestResourceGlobalAccountRoleCollection(t *testing.T) { +func TestResourceGlobalaccountRoleCollection(t *testing.T) { t.Run("happy path", func(t *testing.T) { rec, user := setupVCR(t, "fixtures/resource_globalaccount_role_collection") defer stopQuietly(rec) @@ -26,7 +26,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), Steps: []resource.TestStep{ { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollection( + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollection( "uut", "My new role collection", "Description of my new role collection", @@ -60,7 +60,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), Steps: []resource.TestStep{ { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollection( + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollection( "uut", "My new role collection", "Description of my new role collection", @@ -77,7 +77,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ), }, { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollection( + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollection( "uut", "My new role collection", "Description of my updated role collection", @@ -112,7 +112,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), Steps: []resource.TestStep{ { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollection( + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollection( "uut", "My new role collection", "Description of my new role collection", @@ -129,7 +129,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ), }, { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollection( + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollection( "uut", "My new role collection", "", @@ -164,7 +164,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), Steps: []resource.TestStep{ { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollection( + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollection( "uut", "My new role collection", "Description of my new role collection", @@ -181,7 +181,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ), }, { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollectionWoDescription( + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollectionWoDescription( "uut", "My new role collection", globalaccountRoleCollectionRoleRefTestType{ @@ -215,7 +215,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), Steps: []resource.TestStep{ { - Config: hclProviderFor(user) + hclResourceGlobalAccountRoleCollection("uut", "My new role collection", "Description of my new role collection"), + Config: hclProviderFor(user) + hclResourceGlobalaccountRoleCollection("uut", "My new role collection", "Description of my new role collection"), }, { ResourceName: "btp_globalaccount_role_collection.uut", @@ -229,7 +229,7 @@ func TestResourceGlobalAccountRoleCollection(t *testing.T) { }) } -func hclResourceGlobalAccountRoleCollection(resourceName string, displayName string, description string, roles ...globalaccountRoleCollectionRoleRefTestType) string { +func hclResourceGlobalaccountRoleCollection(resourceName string, displayName string, description string, roles ...globalaccountRoleCollectionRoleRefTestType) string { if roles == nil { roles = []globalaccountRoleCollectionRoleRefTestType{} } @@ -242,7 +242,7 @@ func hclResourceGlobalAccountRoleCollection(resourceName string, displayName str }`, resourceName, displayName, description, string(rolesJson)) } -func hclResourceGlobalAccountRoleCollectionWoDescription(resourceName string, displayName string, roles ...globalaccountRoleCollectionRoleRefTestType) string { +func hclResourceGlobalaccountRoleCollectionWoDescription(resourceName string, displayName string, roles ...globalaccountRoleCollectionRoleRefTestType) string { if roles == nil { roles = []globalaccountRoleCollectionRoleRefTestType{} } diff --git a/internal/provider/resource_subaccount_role_collection_assignment_test.go b/internal/provider/resource_subaccount_role_collection_assignment_test.go index 4195fd8e..7a978d71 100644 --- a/internal/provider/resource_subaccount_role_collection_assignment_test.go +++ b/internal/provider/resource_subaccount_role_collection_assignment_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) -func TestResourceRolCollectionAssignment(t *testing.T) { +func TestResourceSubaccountRoleCollectionAssignment(t *testing.T) { t.Parallel() t.Run("happy path - simple role collection assignment", func(t *testing.T) { rec, user := setupVCR(t, "fixtures/resource_subaccount_role_collection_assignment") diff --git a/internal/provider/resource_subaccount_role_collection_test.go b/internal/provider/resource_subaccount_role_collection_test.go index 4837b4f5..5672ccff 100644 --- a/internal/provider/resource_subaccount_role_collection_test.go +++ b/internal/provider/resource_subaccount_role_collection_test.go @@ -17,7 +17,7 @@ type subaccountRoleCollectionRoleRefTestType struct { RoleTemplateName string `json:"role_template_name"` } -func TestResourceSubAccountRoleCollection(t *testing.T) { +func TestResourceSubaccountRoleCollection(t *testing.T) { t.Run("happy path", func(t *testing.T) { rec, user := setupVCR(t, "fixtures/resource_subaccount_role_collection") defer stopQuietly(rec) diff --git a/internal/provider/type_globalaccount_hierarchy.go b/internal/provider/type_globalaccount_hierarchy.go index 8b3edc5c..f223c1dc 100644 --- a/internal/provider/type_globalaccount_hierarchy.go +++ b/internal/provider/type_globalaccount_hierarchy.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -type globalAccountHierarchyType struct { +type globalaccountHierarchyType struct { ID types.String `tfsdk:"id"` CreatedDate types.String `tfsdk:"created_date"` Directories types.List `tfsdk:"directories"` @@ -20,8 +20,8 @@ type globalAccountHierarchyType struct { Type types.String `tfsdk:"type"` } -func globalAccountHierarchyValueFrom(ctx context.Context, value cis.GlobalAccountResponseObject) (globalAccountHierarchyType, diag.Diagnostics) { - globalAccount := globalAccountHierarchyType{ +func globalaccountHierarchyValueFrom(ctx context.Context, value cis.GlobalAccountResponseObject) (globalaccountHierarchyType, diag.Diagnostics) { + globalaccount := globalaccountHierarchyType{ ID: types.StringValue(value.Guid), CreatedDate: timeToValue(value.CreatedDate.Time()), ModifiedDate: timeToValue(value.ModifiedDate.Time()), @@ -35,21 +35,21 @@ func globalAccountHierarchyValueFrom(ctx context.Context, value cis.GlobalAccoun if len(value.Children) > 0 { //The dirctory level is mentioned as 6 inorder to align with the schema strcuture defined as per the provider. - directories, diags := directoriesHierarchyValueFrom(ctx, value.Children, globalAccount.Name, globalAccount.Type, 6) + directories, diags := directoriesHierarchyValueFrom(ctx, value.Children, globalaccount.Name, globalaccount.Type, 6) summary.Append(diags...) - globalAccount.Directories, diags = types.ListValueFrom(ctx, directoryObjectType(6), directories) + globalaccount.Directories, diags = types.ListValueFrom(ctx, directoryObjectType(6), directories) summary.Append(diags...) } else { - globalAccount.Directories = types.ListNull(directoryObjectType(6)) + globalaccount.Directories = types.ListNull(directoryObjectType(6)) } if len(value.Subaccounts) > 0 { - subaccounts := subaccountsHierarchyValueFrom(ctx, value.Subaccounts, globalAccount.Name, globalAccount.Type) - globalAccount.Subaccounts, diags = types.ListValueFrom(ctx, subaccountObjectType, subaccounts) + subaccounts := subaccountsHierarchyValueFrom(ctx, value.Subaccounts, globalaccount.Name, globalaccount.Type) + globalaccount.Subaccounts, diags = types.ListValueFrom(ctx, subaccountObjectType, subaccounts) summary.Append(diags...) } else { - globalAccount.Subaccounts = types.ListNull(subaccountObjectType) + globalaccount.Subaccounts = types.ListNull(subaccountObjectType) } - return globalAccount, summary + return globalaccount, summary } diff --git a/internal/provider/type_subaccount.go b/internal/provider/type_subaccount.go index 0986b3cc..7661d732 100644 --- a/internal/provider/type_subaccount.go +++ b/internal/provider/type_subaccount.go @@ -57,16 +57,12 @@ func subaccountValueFrom(ctx context.Context, value cis.SubaccountResponseObject return subaccount, diagnostics } -func determineParentIdByFeature(cli *btpcli.ClientFacade, ctx context.Context, parentIdToVerify string, featureType string) (parentId string, isParentGlobalAccount bool) { - - parentId = "" - isParentGlobalAccount = false - +func determineParentIdByFeature(cli *btpcli.ClientFacade, ctx context.Context, parentIdToVerify string, featureType string) (parentId string, isParentGlobalaccount bool) { parentData, _, err := cli.Accounts.Directory.Get(ctx, parentIdToVerify) // The parent is the global account if err != nil { - isParentGlobalAccount = true + isParentGlobalaccount = true return } @@ -75,26 +71,26 @@ func determineParentIdByFeature(cli *btpcli.ClientFacade, ctx context.Context, p parentId = parentIdToVerify } else { // Parent is a directory, but not with entitlements feature enabled -> step up the hierarchy - parentId, isParentGlobalAccount = determineParentIdByFeature(cli, ctx, parentData.ParentGUID, featureType) + parentId, isParentGlobalaccount = determineParentIdByFeature(cli, ctx, parentData.ParentGUID, featureType) } return } func hasFeature(features []string, featureType string) (featureTypeFound bool) { - for _, f := range features { if f == featureType { featureTypeFound = true } } + return } -func determineParentIdForEntitlement(cli *btpcli.ClientFacade, ctx context.Context, parentIdToVerify string) (parentId string, isParentGlobalAccount bool) { +func determineParentIdForEntitlement(cli *btpcli.ClientFacade, ctx context.Context, parentIdToVerify string) (parentId string, isParentGlobalaccount bool) { return determineParentIdByFeature(cli, ctx, parentIdToVerify, EntitlementFeature) } -func determineParentIdForAuthorization(cli *btpcli.ClientFacade, ctx context.Context, parentIdToVerify string) (parentId string, isParentGlobalAccount bool) { +func determineParentIdForAuthorization(cli *btpcli.ClientFacade, ctx context.Context, parentIdToVerify string) (parentId string, isParentGlobalaccount bool) { return determineParentIdByFeature(cli, ctx, parentIdToVerify, AuthorizationFeature) }