diff --git a/dashboard_permissions.go b/dashboard_permissions.go index babc04d0..de555003 100644 --- a/dashboard_permissions.go +++ b/dashboard_permissions.go @@ -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{ @@ -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{ @@ -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{ diff --git a/datasource_permissions.go b/datasource_permissions.go index ffa5869b..23104a8b 100644 --- a/datasource_permissions.go +++ b/datasource_permissions.go @@ -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{ @@ -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{ @@ -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{ diff --git a/folder_permissions.go b/folder_permissions.go index 847de5d5..1427c362 100644 --- a/folder_permissions.go +++ b/folder_permissions.go @@ -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{ @@ -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{ @@ -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{ diff --git a/resource.go b/resource.go index 79ecaee3..ef0fe8fd 100644 --- a/resource.go +++ b/resource.go @@ -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 diff --git a/service_account_permissions.go b/service_account_permissions.go index e5640429..dd20d7af 100644 --- a/service_account_permissions.go +++ b/service_account_permissions.go @@ -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{ @@ -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{ diff --git a/team_permissions.go b/team_permissions.go index cf49cc77..cba89f46 100644 --- a/team_permissions.go +++ b/team_permissions.go @@ -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{