2017-11-11 04:44:02 +00:00
|
|
|
package authorization
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-03-31 07:13:30 +00:00
|
|
|
"github.com/rancher/norman/httperror"
|
2017-11-11 04:44:02 +00:00
|
|
|
"github.com/rancher/norman/types"
|
2017-12-18 20:56:50 +00:00
|
|
|
"github.com/rancher/norman/types/slice"
|
2017-11-11 04:44:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AllAccess struct {
|
|
|
|
}
|
|
|
|
|
2018-03-31 07:13:30 +00:00
|
|
|
func (*AllAccess) CanCreate(apiContext *types.APIContext, schema *types.Schema) error {
|
|
|
|
if slice.ContainsString(schema.CollectionMethods, http.MethodPost) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return httperror.NewAPIError(httperror.PermissionDenied, "can not create "+schema.ID)
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 07:13:30 +00:00
|
|
|
func (*AllAccess) CanGet(apiContext *types.APIContext, schema *types.Schema) error {
|
|
|
|
if slice.ContainsString(schema.ResourceMethods, http.MethodGet) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return httperror.NewAPIError(httperror.PermissionDenied, "can not get "+schema.ID)
|
2018-02-01 02:14:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 07:13:30 +00:00
|
|
|
func (*AllAccess) CanList(apiContext *types.APIContext, schema *types.Schema) error {
|
|
|
|
if slice.ContainsString(schema.CollectionMethods, http.MethodGet) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return httperror.NewAPIError(httperror.PermissionDenied, "can not list "+schema.ID)
|
2017-12-18 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 07:13:30 +00:00
|
|
|
func (*AllAccess) CanUpdate(apiContext *types.APIContext, obj map[string]interface{}, schema *types.Schema) error {
|
|
|
|
if slice.ContainsString(schema.ResourceMethods, http.MethodPut) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return httperror.NewAPIError(httperror.PermissionDenied, "can not update "+schema.ID)
|
2017-12-18 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2018-03-31 07:13:30 +00:00
|
|
|
func (*AllAccess) CanDelete(apiContext *types.APIContext, obj map[string]interface{}, schema *types.Schema) error {
|
|
|
|
if slice.ContainsString(schema.ResourceMethods, http.MethodDelete) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return httperror.NewAPIError(httperror.PermissionDenied, "can not delete "+schema.ID)
|
2017-12-18 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2018-04-25 19:16:16 +00:00
|
|
|
func (*AllAccess) CanDo(apiGroup, resource, verb string, apiContext *types.APIContext, obj map[string]interface{}, schema *types.Schema) error {
|
|
|
|
if slice.ContainsString(schema.ResourceMethods, verb) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return httperror.NewAPIError(httperror.PermissionDenied, "can not perform "+verb+" "+schema.ID)
|
|
|
|
}
|
|
|
|
|
2018-03-03 06:09:47 +00:00
|
|
|
func (*AllAccess) Filter(apiContext *types.APIContext, schema *types.Schema, obj map[string]interface{}, context map[string]string) map[string]interface{} {
|
2017-12-18 20:56:50 +00:00
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2018-03-03 06:09:47 +00:00
|
|
|
func (*AllAccess) FilterList(apiContext *types.APIContext, schema *types.Schema, obj []map[string]interface{}, context map[string]string) []map[string]interface{} {
|
2017-12-18 20:56:50 +00:00
|
|
|
return obj
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|