Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Add string constants for resource types
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Godin committed Nov 1, 2023
1 parent 8df20bf commit d093362
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 34 deletions.
16 changes: 8 additions & 8 deletions dashboard_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ func (c *Client) UpdateDashboardPermissionsByUID(uid string, items *PermissionIt
}

func (c *Client) ListDashboardResourcePermissions(ident ResourceIdent) ([]*ResourcePermission, error) {
return c.listResourcePermissions("dashboards", ident)
return c.listResourcePermissions(DashboardsResource, ident)
}

func (c *Client) SetDashboardResourcePermissions(ident ResourceIdent, body SetResourcePermissionsBody) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissions("dashboards", ident, body)
return c.setResourcePermissions(DashboardsResource, ident, body)
}

func (c *Client) SetUserDashboardResourcePermissions(ident ResourceIdent, userID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"dashboards",
DashboardsResource,
ident,
"users",
UsersResource,
ResourceID(userID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand All @@ -84,9 +84,9 @@ func (c *Client) SetUserDashboardResourcePermissions(ident ResourceIdent, userID

func (c *Client) SetTeamDashboardResourcePermissions(ident ResourceIdent, teamID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"dashboards",
DashboardsResource,
ident,
"teams",
TeamsResource,
ResourceID(teamID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand All @@ -99,9 +99,9 @@ func (c *Client) SetTeamDashboardResourcePermissions(ident ResourceIdent, teamID

func (c *Client) SetBuiltInRoleDashboardResourcePermissions(ident ResourceIdent, builtInRole string, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"dashboards",
DashboardsResource,
ident,
"builtInRoles",
BuiltInRolesResource,
ResourceUID(builtInRole),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand Down
16 changes: 8 additions & 8 deletions datasource_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ func (c *Client) RemoveDatasourcePermission(id, permissionID int64) error {
}

func (c *Client) ListDatasourceResourcePermissions(ident ResourceIdent) ([]*ResourcePermission, error) {
return c.listResourcePermissions("datasources", ident)
return c.listResourcePermissions(DatasourcesResource, ident)
}

func (c *Client) SetDatasourceResourcePermissions(ident ResourceIdent, body SetResourcePermissionsBody) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissions("datasources", ident, body)
return c.setResourcePermissions(DatasourcesResource, ident, body)
}

func (c *Client) SetUserDatasourceResourcePermissions(ident ResourceIdent, userID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"datasources",
DatasourcesResource,
ident,
"users",
UsersResource,
ResourceID(userID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand All @@ -122,9 +122,9 @@ func (c *Client) SetUserDatasourceResourcePermissions(ident ResourceIdent, userI

func (c *Client) SetTeamDatasourceResourcePermissions(ident ResourceIdent, teamID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"datasources",
DatasourcesResource,
ident,
"teams",
TeamsResource,
ResourceID(teamID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand All @@ -137,9 +137,9 @@ func (c *Client) SetTeamDatasourceResourcePermissions(ident ResourceIdent, teamI

func (c *Client) SetBuiltInRoleDatasourceResourcePermissions(ident ResourceIdent, builtInRole string, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"datasources",
DatasourcesResource,
ident,
"builtInRoles",
BuiltInRolesResource,
ResourceUID(builtInRole),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand Down
16 changes: 8 additions & 8 deletions folder_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ func (c *Client) UpdateFolderPermissions(fid string, items *PermissionItems) err
}

func (c *Client) ListFolderResourcePermissions(ident ResourceIdent) ([]*ResourcePermission, error) {
return c.listResourcePermissions("folders", ident)
return c.listResourcePermissions(FoldersResource, ident)
}

func (c *Client) SetFolderResourcePermissions(ident ResourceIdent, body SetResourcePermissionsBody) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissions("folders", ident, body)
return c.setResourcePermissions(FoldersResource, ident, body)
}

func (c *Client) SetUserFolderResourcePermissions(ident ResourceIdent, userID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"folders",
FoldersResource,
ident,
"users",
UsersResource,
ResourceID(userID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand All @@ -88,9 +88,9 @@ func (c *Client) SetUserFolderResourcePermissions(ident ResourceIdent, userID in

func (c *Client) SetTeamFolderResourcePermissions(ident ResourceIdent, teamID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"folders",
FoldersResource,
ident,
"teams",
TeamsResource,
ResourceID(teamID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand All @@ -103,9 +103,9 @@ func (c *Client) SetTeamFolderResourcePermissions(ident ResourceIdent, teamID in

func (c *Client) SetBuiltInRoleFolderResourcePermissions(ident ResourceIdent, builtInRole string, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"folders",
FoldersResource,
ident,
"builtInRoles",
BuiltInRolesResource,
ResourceUID(builtInRole),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand Down
10 changes: 10 additions & 0 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import (
"strconv"
)

const (
DashboardsResource = "dashboards"
DatasourcesResource = "datasources"
FoldersResource = "folders"
ServiceAccountsResource = "serviceaccounts"
TeamsResource = "teams"
UsersResource = "users"
BuiltInRolesResource = "builtInRoles"
)

// ResourceIdent represents anything that can be considered a resource identifier.
type ResourceIdent interface {
fmt.Stringer
Expand Down
12 changes: 6 additions & 6 deletions service_account_permissions.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package gapi

func (c *Client) ListServiceAccountResourcePermissions(ident ResourceIdent) ([]*ResourcePermission, error) {
return c.listResourcePermissions("serviceaccounts", ident)
return c.listResourcePermissions(ServiceAccountsResource, ident)
}

func (c *Client) SetServiceAccountResourcePermissions(ident ResourceIdent, body SetResourcePermissionsBody) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissions("serviceaccounts", ident, body)
return c.setResourcePermissions(ServiceAccountsResource, ident, body)
}

func (c *Client) SetUserServiceAccountResourcePermissions(ident ResourceIdent, userID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"serviceaccounts",
ServiceAccountsResource,
ident,
"users",
UsersResource,
ResourceID(userID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand All @@ -25,9 +25,9 @@ func (c *Client) SetUserServiceAccountResourcePermissions(ident ResourceIdent, u

func (c *Client) SetTeamServiceAccountResourcePermissions(ident ResourceIdent, teamID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"serviceaccounts",
ServiceAccountsResource,
ident,
"teams",
TeamsResource,
ResourceID(teamID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand Down
8 changes: 4 additions & 4 deletions team_permissions.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package gapi

func (c *Client) ListTeamResourcePermissions(ident ResourceIdent) ([]*ResourcePermission, error) {
return c.listResourcePermissions("teams", ident)
return c.listResourcePermissions(TeamsResource, ident)
}

func (c *Client) SetTeamResourcePermissions(ident ResourceIdent, body SetResourcePermissionsBody) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissions("teams", ident, body)
return c.setResourcePermissions(TeamsResource, ident, body)
}

func (c *Client) SetUserTeamResourcePermissions(ident ResourceIdent, userID int64, permission string) (*SetResourcePermissionsResponse, error) {
return c.setResourcePermissionByAssignment(
"teams",
TeamsResource,
ident,
"users",
UsersResource,
ResourceID(userID),
SetResourcePermissionBody{
Permission: SetResourcePermissionItem{
Expand Down

0 comments on commit d093362

Please sign in to comment.