Airat Arifullin
32a975a20d
* Introduce `Chain`, `ChainTarget` and `TargetType`. * Implement api-v2 converters for the introduced types. * Add unit-tests. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package apemanager
|
|
|
|
import (
|
|
apemanager_v2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
|
|
)
|
|
|
|
// TargetType is an SDK representation for v2's TargetType.
|
|
type TargetType apemanager_v2.TargetType
|
|
|
|
const (
|
|
TargetTypeUndefined TargetType = iota
|
|
TargetTypeNamespace
|
|
TargetTypeContainer
|
|
TargetTypeUser
|
|
TargetTypeGroup
|
|
)
|
|
|
|
// ToV2 converts TargetType to v2.
|
|
func (targetType TargetType) ToV2() apemanager_v2.TargetType {
|
|
return apemanager_v2.TargetType(targetType)
|
|
}
|
|
|
|
// FromV2 reads TargetType to v2.
|
|
func (targetType *TargetType) FromV2(v2targetType apemanager_v2.TargetType) {
|
|
*targetType = TargetType(v2targetType)
|
|
}
|
|
|
|
// ChainTarget is an SDK representation for v2's ChainTarget.
|
|
//
|
|
// Note that ChainTarget (as well as v2's ChainTarget) and all related entities
|
|
// are NOT operated by Access-Policy-Engine (APE). The client is responsible
|
|
// to convert these types to policy-engine entities.
|
|
type ChainTarget struct {
|
|
TargetType TargetType
|
|
|
|
Name string
|
|
}
|
|
|
|
// ToV2 converts ChainTarget to v2.
|
|
func (ct *ChainTarget) ToV2() *apemanager_v2.ChainTarget {
|
|
v2ct := new(apemanager_v2.ChainTarget)
|
|
|
|
v2ct.SetTargetType(ct.TargetType.ToV2())
|
|
v2ct.SetName(ct.Name)
|
|
|
|
return v2ct
|
|
}
|
|
|
|
// FromV2 reads ChainTarget frpm v2.
|
|
func (ct *ChainTarget) FromV2(v2ct *apemanager_v2.ChainTarget) {
|
|
ct.TargetType.FromV2(v2ct.GetTargetType())
|
|
ct.Name = v2ct.GetName()
|
|
}
|