frostfs-sdk-go/eacl/enums.go
Airat Arifullin 6281a25556
All checks were successful
/ DCO (pull_request) Successful in 1m17s
/ Lint (pull_request) Successful in 2m7s
/ Tests (1.19) (pull_request) Successful in 5m56s
/ Tests (1.20) (pull_request) Successful in 6m37s
[#100] types: Make sdk types as protobuf wrappers
Signed-off-by: Airat Arifullin a.arifullin@yadro.com
2023-07-12 19:08:37 +03:00

396 lines
9.1 KiB
Go

package eacl
import (
aclgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
)
// Action taken if ContainerEACL record matched request.
// Action is compatible with v2 acl.Action enum.
type Action uint32
const (
// ActionUnknown is an Action value used to mark action as undefined.
ActionUnknown Action = iota
// ActionAllow is an Action value that allows access to the operation from context.
ActionAllow
// ActionDeny is an Action value that denies access to the operation from context.
ActionDeny
)
// Operation is a object service method to match request.
// Operation is compatible with v2 acl.Operation enum.
type Operation uint32
const (
// OperationUnknown is an Operation value used to mark operation as undefined.
OperationUnknown Operation = iota
// OperationGet is an object get Operation.
OperationGet
// OperationHead is an Operation of getting the object header.
OperationHead
// OperationPut is an object put Operation.
OperationPut
// OperationDelete is an object delete Operation.
OperationDelete
// OperationSearch is an object search Operation.
OperationSearch
// OperationRange is an object payload range retrieval Operation.
OperationRange
// OperationRangeHash is an object payload range hashing Operation.
OperationRangeHash
)
// Role is a group of request senders to match request.
// Role is compatible with v2 acl.Role enum.
type Role uint32
const (
// RoleUnknown is a Role value used to mark role as undefined.
RoleUnknown Role = iota
// RoleUser is a group of senders that contains only key of container owner.
RoleUser
// RoleSystem is a group of senders that contains keys of container nodes and
// inner ring nodes.
RoleSystem
// RoleOthers is a group of senders that contains none of above keys.
RoleOthers
)
// Match is binary operation on filer name and value to check if request is matched.
// Match is compatible with v2 acl.MatchType enum.
type Match uint32
const (
// MatchUnknown is a Match value used to mark matcher as undefined.
MatchUnknown Match = iota
// MatchStringEqual is a Match of string equality.
MatchStringEqual
// MatchStringNotEqual is a Match of string inequality.
MatchStringNotEqual
)
// FilterHeaderType indicates source of headers to make matches.
// FilterHeaderType is compatible with v2 acl.HeaderType enum.
type FilterHeaderType uint32
const (
// HeaderTypeUnknown is a FilterHeaderType value used to mark header type as undefined.
HeaderTypeUnknown FilterHeaderType = iota
// HeaderFromRequest is a FilterHeaderType for request X-Header.
HeaderFromRequest
// HeaderFromObject is a FilterHeaderType for object header.
HeaderFromObject
// HeaderFromService is a FilterHeaderType for service header.
HeaderFromService
)
// ToV2 converts Action to v2 Action enum value.
func (a Action) ToV2() aclgrpc.Action {
switch a {
case ActionAllow:
return aclgrpc.Action_ALLOW
case ActionDeny:
return aclgrpc.Action_DENY
default:
return aclgrpc.Action_ACTION_UNSPECIFIED
}
}
// ActionFromV2 converts v2 Action enum value to Action.
func ActionFromV2(action aclgrpc.Action) (a Action) {
switch action {
case aclgrpc.Action_ALLOW:
a = ActionAllow
case aclgrpc.Action_DENY:
a = ActionDeny
default:
a = ActionUnknown
}
return a
}
// String returns string representation of Action.
//
// String mapping:
// - ActionAllow: ALLOW;
// - ActionDeny: DENY;
// - ActionUnknown, default: ACTION_UNSPECIFIED.
func (a Action) String() string {
return a.ToV2().String()
}
// FromString parses Action from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (a *Action) FromString(s string) bool {
var g aclgrpc.Action
ok := g.FromString(s)
if ok {
*a = ActionFromV2(g)
}
return ok
}
// ToV2 converts Operation to v2 Operation enum value.
func (o Operation) ToV2() aclgrpc.Operation {
switch o {
case OperationGet:
return aclgrpc.Operation_GET
case OperationHead:
return aclgrpc.Operation_HEAD
case OperationPut:
return aclgrpc.Operation_PUT
case OperationDelete:
return aclgrpc.Operation_DELETE
case OperationSearch:
return aclgrpc.Operation_SEARCH
case OperationRange:
return aclgrpc.Operation_GETRANGE
case OperationRangeHash:
return aclgrpc.Operation_GETRANGEHASH
default:
return aclgrpc.Operation_OPERATION_UNSPECIFIED
}
}
// OperationFromV2 converts v2 Operation enum value to Operation.
func OperationFromV2(operation aclgrpc.Operation) (o Operation) {
switch operation {
case aclgrpc.Operation_GET:
o = OperationGet
case aclgrpc.Operation_HEAD:
o = OperationHead
case aclgrpc.Operation_PUT:
o = OperationPut
case aclgrpc.Operation_DELETE:
o = OperationDelete
case aclgrpc.Operation_SEARCH:
o = OperationSearch
case aclgrpc.Operation_GETRANGE:
o = OperationRange
case aclgrpc.Operation_GETRANGEHASH:
o = OperationRangeHash
default:
o = OperationUnknown
}
return o
}
// String returns string representation of Operation.
//
// String mapping:
// - OperationGet: GET;
// - OperationHead: HEAD;
// - OperationPut: PUT;
// - OperationDelete: DELETE;
// - OperationSearch: SEARCH;
// - OperationRange: GETRANGE;
// - OperationRangeHash: GETRANGEHASH;
// - OperationUnknown, default: OPERATION_UNSPECIFIED.
func (o Operation) String() string {
return o.ToV2().String()
}
// FromString parses Operation from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (o *Operation) FromString(s string) bool {
var g aclgrpc.Operation
ok := g.FromString(s)
if ok {
*o = OperationFromV2(g)
}
return ok
}
// ToV2 converts Role to v2 Role enum value.
func (r Role) ToV2() aclgrpc.Role {
switch r {
case RoleUser:
return aclgrpc.Role_USER
case RoleSystem:
return aclgrpc.Role_SYSTEM
case RoleOthers:
return aclgrpc.Role_OTHERS
default:
return aclgrpc.Role_ROLE_UNSPECIFIED
}
}
// RoleFromV2 converts v2 Role enum value to Role.
func RoleFromV2(role aclgrpc.Role) (r Role) {
switch role {
case aclgrpc.Role_USER:
r = RoleUser
case aclgrpc.Role_SYSTEM:
r = RoleSystem
case aclgrpc.Role_OTHERS:
r = RoleOthers
default:
r = RoleUnknown
}
return r
}
// String returns string representation of Role.
//
// String mapping:
// - RoleUser: USER;
// - RoleSystem: SYSTEM;
// - RoleOthers: OTHERS;
// - RoleUnknown, default: ROLE_UNKNOWN.
func (r Role) String() string {
return r.ToV2().String()
}
// FromString parses Role from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (r *Role) FromString(s string) bool {
var g aclgrpc.Role
ok := g.FromString(s)
if ok {
*r = RoleFromV2(g)
}
return ok
}
// ToV2 converts Match to v2 MatchType enum value.
func (m Match) ToV2() aclgrpc.MatchType {
switch m {
case MatchStringEqual:
return aclgrpc.MatchType_STRING_EQUAL
case MatchStringNotEqual:
return aclgrpc.MatchType_STRING_NOT_EQUAL
default:
return aclgrpc.MatchType_MATCH_TYPE_UNSPECIFIED
}
}
// MatchFromV2 converts v2 MatchType enum value to Match.
func MatchFromV2(match aclgrpc.MatchType) (m Match) {
switch match {
case aclgrpc.MatchType_STRING_EQUAL:
m = MatchStringEqual
case aclgrpc.MatchType_STRING_NOT_EQUAL:
m = MatchStringNotEqual
default:
m = MatchUnknown
}
return m
}
// String returns string representation of Match.
//
// String mapping:
// - MatchStringEqual: STRING_EQUAL;
// - MatchStringNotEqual: STRING_NOT_EQUAL;
// - MatchUnknown, default: MATCH_TYPE_UNSPECIFIED.
func (m Match) String() string {
return m.ToV2().String()
}
// FromString parses Match from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (m *Match) FromString(s string) bool {
var g aclgrpc.MatchType
ok := g.FromString(s)
if ok {
*m = MatchFromV2(g)
}
return ok
}
// ToV2 converts FilterHeaderType to v2 HeaderType enum value.
func (h FilterHeaderType) ToV2() aclgrpc.HeaderType {
switch h {
case HeaderFromRequest:
return aclgrpc.HeaderType_REQUEST
case HeaderFromObject:
return aclgrpc.HeaderType_OBJECT
case HeaderFromService:
return aclgrpc.HeaderType_SERVICE
default:
return aclgrpc.HeaderType_HEADER_UNSPECIFIED
}
}
// FilterHeaderTypeFromV2 converts v2 HeaderType enum value to FilterHeaderType.
func FilterHeaderTypeFromV2(header aclgrpc.HeaderType) (h FilterHeaderType) {
switch header {
case aclgrpc.HeaderType_REQUEST:
h = HeaderFromRequest
case aclgrpc.HeaderType_OBJECT:
h = HeaderFromObject
case aclgrpc.HeaderType_SERVICE:
h = HeaderFromService
default:
h = HeaderTypeUnknown
}
return h
}
// String returns string representation of FilterHeaderType.
//
// String mapping:
// - HeaderFromRequest: REQUEST;
// - HeaderFromObject: OBJECT;
// - HeaderTypeUnknown, default: HEADER_UNSPECIFIED.
func (h FilterHeaderType) String() string {
return h.ToV2().String()
}
// FromString parses FilterHeaderType from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (h *FilterHeaderType) FromString(s string) bool {
var g aclgrpc.HeaderType
ok := g.FromString(s)
if ok {
*h = FilterHeaderTypeFromV2(g)
}
return ok
}