Skip to content

Commit

Permalink
update service account permissions to use the new endpoints from Gola…
Browse files Browse the repository at this point in the history
…ng API client
  • Loading branch information
IevaVasiljeva committed Nov 7, 2023
1 parent f3b1845 commit 6afbb43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func getServiceAccountPermissions(ctx context.Context, d *schema.ResourceData, m
return nil, diag.FromErr(err)
}

saPermissions, err := client.GetServiceAccountPermissions(id)
saPermissions, err := client.ListServiceAccountResourcePermissions(id)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.1.5

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / unit tests

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / cloudinstance

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / docs

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - TLS Proxy

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - Enterprise

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 9.5.13

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)

Check failure on line 122 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 8.5.27

client.ListServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method ListServiceAccountResourcePermissions)
if err, shouldReturn := common.CheckReadError("service account permissions", d, err); shouldReturn {
return nil, err
}
Expand Down Expand Up @@ -163,12 +163,12 @@ func updateServiceAccountPermissions(client *gapi.Client, idStr string, from, to
}
}

permissionList := gapi.ServiceAccountPermissionItems{}
var permissionList []gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.1.5

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / unit tests

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / cloudinstance

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / docs

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - TLS Proxy

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - Enterprise

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 9.5.13

undefined: gapi.SetResourcePermissionItem

Check failure on line 166 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 8.5.27

undefined: gapi.SetResourcePermissionItem

// Iterate over permissions from the configuration (the desired permission setup)
for _, p := range listOrSet(to) {
permission := p.(map[string]interface{})
permissionItem := gapi.ServiceAccountPermissionItem{}
permissionItem := gapi.SetResourcePermissionItem{}

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.1.5

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / unit tests

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / cloudinstance

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / docs

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - TLS Proxy

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - Enterprise

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 9.5.13

undefined: gapi.SetResourcePermissionItem

Check failure on line 171 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 8.5.27

undefined: gapi.SetResourcePermissionItem
_, teamIDStr := SplitOrgResourceID(permission["team_id"].(string))
teamID, _ := strconv.ParseInt(teamIDStr, 10, 64)
_, userIDStr := SplitOrgResourceID(permission["user_id"].(string))
Expand All @@ -194,24 +194,25 @@ func updateServiceAccountPermissions(client *gapi.Client, idStr string, from, to
permissionItem.UserID = userID
}
permissionItem.Permission = permission["permission"].(string)
permissionList.Permissions = append(permissionList.Permissions, &permissionItem)
permissionList = append(permissionList, permissionItem)
}

// Remove the permissions that are in the state but not in the config
for teamID := range oldTeamPerms {
permissionList.Permissions = append(permissionList.Permissions, &gapi.ServiceAccountPermissionItem{
permissionList = append(permissionList, gapi.SetResourcePermissionItem{

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.1.5

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / unit tests

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / cloudinstance

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / docs

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - TLS Proxy

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - Enterprise

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 9.5.13

undefined: gapi.SetResourcePermissionItem

Check failure on line 202 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 8.5.27

undefined: gapi.SetResourcePermissionItem
TeamID: teamID,
Permission: "",
})
}
for userID := range oldUserPerms {
permissionList.Permissions = append(permissionList.Permissions, &gapi.ServiceAccountPermissionItem{
permissionList = append(permissionList, gapi.SetResourcePermissionItem{

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.1.5

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / unit tests

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / cloudinstance

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / docs

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - TLS Proxy

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - Enterprise

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 9.5.13

undefined: gapi.SetResourcePermissionItem

Check failure on line 208 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 8.5.27

undefined: gapi.SetResourcePermissionItem
UserID: userID,
Permission: "",
})
}

return client.UpdateServiceAccountPermissions(id, &permissionList)
_, err = client.SetServiceAccountResourcePermissions(id, gapi.SetResourcePermissionsBody{Permissions: permissionList})

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.1.5

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.1.5

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / unit tests

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / unit tests

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / cloudinstance

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / cloudinstance

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / docs

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / docs

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - TLS Proxy

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - TLS Proxy

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - Enterprise

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0 - Enterprise

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 10.2.0

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 9.5.13

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 9.5.13

undefined: gapi.SetResourcePermissionsBody

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 8.5.27

client.SetServiceAccountResourcePermissions undefined (type *gapi.Client has no field or method SetServiceAccountResourcePermissions)

Check failure on line 214 in internal/resources/grafana/resource_service_account_permission.go

View workflow job for this annotation

GitHub Actions / 8.5.27

undefined: gapi.SetResourcePermissionsBody
return err
}

func listOrSet(v interface{}) []interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccServiceAccountPermission(t *testing.T) {

name := acctest.RandString(10)

var saPermission gapi.ServiceAccountPermission
var saPermission gapi.ResourcePermission
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: testutils.ProviderFactories,
CheckDestroy: testAccServiceAccountPermissionsCheckDestroy(saPermission.ID),
Expand All @@ -42,7 +42,7 @@ func TestAccServiceAccountPermission_inOrg(t *testing.T) {

name := acctest.RandString(10)

var saPermission gapi.ServiceAccountPermission
var saPermission gapi.ResourcePermission
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: testutils.ProviderFactories,
CheckDestroy: testAccServiceAccountPermissionsCheckDestroy(saPermission.ID),
Expand All @@ -61,7 +61,7 @@ func TestAccServiceAccountPermission_inOrg(t *testing.T) {
})
}

func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ServiceAccountPermission) resource.TestCheckFunc {
func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ResourcePermission) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[rn]
if !ok {
Expand All @@ -76,7 +76,7 @@ func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ServiceAcc
}
client := testutils.Provider.Meta().(*common.Client).GrafanaAPI.WithOrgID(orgID)

perms, err := client.GetServiceAccountPermissions(saID)
perms, err := client.ListServiceAccountResourcePermissions(saID)
if err != nil {
return fmt.Errorf("error getting service account permissions: %s", err)
}
Expand All @@ -92,7 +92,7 @@ func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ServiceAcc
func testAccServiceAccountPermissionsCheckDestroy(id int64) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testutils.Provider.Meta().(*common.Client).GrafanaAPI
saPerms, err := client.GetServiceAccountPermissions(id)
saPerms, err := client.ListServiceAccountResourcePermissions(id)
if err != nil {
return err
}
Expand Down

0 comments on commit 6afbb43

Please sign in to comment.