[IAM] - Add swagger docs for resource permissions API (#79525)
* IAM: Apply swagger-go comments for generating docs on resource permissions endpoints * Update pkg/services/accesscontrol/resourcepermissions/api.go Clarifies swagger note on assigning to service accounts Co-authored-by: Ieva <ieva.vasiljeva@grafana.com> --------- Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
This commit is contained in:
@@ -63,11 +63,26 @@ type Assignments struct {
|
||||
BuiltInRoles bool `json:"builtInRoles"`
|
||||
}
|
||||
|
||||
// swagger:response resourcePermissionsDescription
|
||||
type DescriptionResponse struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body Description `json:"body"`
|
||||
}
|
||||
|
||||
type Description struct {
|
||||
Assignments Assignments `json:"assignments"`
|
||||
Permissions []string `json:"permissions"`
|
||||
}
|
||||
|
||||
// swagger:route POST /access-control/:resource/description enterprise,access_control getResourceDescription
|
||||
//
|
||||
// Get a description of a resource's access control properties.
|
||||
//
|
||||
// Responses:
|
||||
// 200: resourcePermissionsDescription
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (a *api) getDescription(c *contextmodel.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, &Description{
|
||||
Permissions: a.permissions,
|
||||
@@ -92,6 +107,17 @@ type resourcePermissionDTO struct {
|
||||
Permission string `json:"permission"`
|
||||
}
|
||||
|
||||
// swagger:response getResourcePermissionsResponse
|
||||
type getResourcePermissionsResponse []resourcePermissionDTO
|
||||
|
||||
// swagger:route POST /access-control/:resource/:resourceID enterprise,access_control getResourcePermissions
|
||||
//
|
||||
// Get permissions for a resource.
|
||||
//
|
||||
// Responses:
|
||||
// 200: getResourcePermissionsResponse
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (a *api) getPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
resourceID := web.Params(c.Req)[":resourceID"]
|
||||
|
||||
@@ -108,7 +134,7 @@ func (a *api) getPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
})
|
||||
}
|
||||
|
||||
dto := make([]resourcePermissionDTO, 0, len(permissions))
|
||||
dto := make(getResourcePermissionsResponse, 0, len(permissions))
|
||||
for _, p := range permissions {
|
||||
if permission := a.service.MapActions(p); permission != "" {
|
||||
teamAvatarUrl := ""
|
||||
@@ -146,6 +172,19 @@ type setPermissionsCommand struct {
|
||||
Permissions []accesscontrol.SetResourcePermissionCommand `json:"permissions"`
|
||||
}
|
||||
|
||||
// swagger:route POST /access-control/:resource/:resourceID/users/:userID enterprise,access_control setResourcePermissionsForUser
|
||||
//
|
||||
// Set resource permissions for a user.
|
||||
//
|
||||
// Assigns permissions for a resource by a given type (`:resource`) and `:resourceID` to a user or a service account.
|
||||
// Allowed resources are `datasources`, `teams`, `dashboards`, `folders`, and `serviceaccounts`.
|
||||
// Refer to the `/access-control/:resource/description` endpoint for allowed Permissions.
|
||||
//
|
||||
// Responses:
|
||||
// 200: okRespoonse
|
||||
// 400: badRequestError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (a *api) setUserPermission(c *contextmodel.ReqContext) response.Response {
|
||||
userID, err := strconv.ParseInt(web.Params(c.Req)[":userID"], 10, 64)
|
||||
if err != nil {
|
||||
@@ -166,6 +205,19 @@ func (a *api) setUserPermission(c *contextmodel.ReqContext) response.Response {
|
||||
return permissionSetResponse(cmd)
|
||||
}
|
||||
|
||||
// swagger:route POST /access-control/:resource/:resourceID/teams/:teamID enterprise,access_control setResourcePermissionsForTeam
|
||||
//
|
||||
// Set resource permissions for a team.
|
||||
//
|
||||
// Assigns permissions for a resource by a given type (`:resource`) and `:resourceID` to a team.
|
||||
// Allowed resources are `datasources`, `teams`, `dashboards`, `folders`, and `serviceaccounts`.
|
||||
// Refer to the `/access-control/:resource/description` endpoint for allowed Permissions.
|
||||
//
|
||||
// Responses:
|
||||
// 200: okRespoonse
|
||||
// 400: badRequestError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (a *api) setTeamPermission(c *contextmodel.ReqContext) response.Response {
|
||||
teamID, err := strconv.ParseInt(web.Params(c.Req)[":teamID"], 10, 64)
|
||||
if err != nil {
|
||||
@@ -186,6 +238,19 @@ func (a *api) setTeamPermission(c *contextmodel.ReqContext) response.Response {
|
||||
return permissionSetResponse(cmd)
|
||||
}
|
||||
|
||||
// swagger:route POST /access-control/:resource/:resourceID/builtInRoles/:builtInRole enterprise,access_control setResourcePermissionsForBuiltInRole
|
||||
//
|
||||
// Set resource permissions for a built-in role.
|
||||
//
|
||||
// Assigns permissions for a resource by a given type (`:resource`) and `:resourceID` to a built-in role.
|
||||
// Allowed resources are `datasources`, `teams`, `dashboards`, `folders`, and `serviceaccounts`.
|
||||
// Refer to the `/access-control/:resource/description` endpoint for allowed Permissions.
|
||||
//
|
||||
// Responses:
|
||||
// 200: okRespoonse
|
||||
// 400: badRequestError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (a *api) setBuiltinRolePermission(c *contextmodel.ReqContext) response.Response {
|
||||
builtInRole := web.Params(c.Req)[":builtInRole"]
|
||||
resourceID := web.Params(c.Req)[":resourceID"]
|
||||
@@ -203,6 +268,19 @@ func (a *api) setBuiltinRolePermission(c *contextmodel.ReqContext) response.Resp
|
||||
return permissionSetResponse(cmd)
|
||||
}
|
||||
|
||||
// swagger:route POST /access-control/:resource/:resourceID enterprise,access_control setResourcePermissions
|
||||
//
|
||||
// Set resource permissions.
|
||||
//
|
||||
// Assigns permissions for a resource by a given type (`:resource`) and `:resourceID` to one or many
|
||||
// assignment types. Allowed resources are `datasources`, `teams`, `dashboards`, `folders`, and `serviceaccounts`.
|
||||
// Refer to the `/access-control/:resource/description` endpoint for allowed Permissions.
|
||||
//
|
||||
// Responses:
|
||||
// 200: okRespoonse
|
||||
// 400: badRequestError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (a *api) setPermissions(c *contextmodel.ReqContext) response.Response {
|
||||
resourceID := web.Params(c.Req)[":resourceID"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user