git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/ape/chain_target.go (about) 1 package ape 2 3 import ( 4 apeV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape" 5 ) 6 7 // TargetType is an SDK representation for v2's TargetType. 8 type TargetType apeV2.TargetType 9 10 const ( 11 TargetTypeUndefined TargetType = iota 12 TargetTypeNamespace 13 TargetTypeContainer 14 TargetTypeUser 15 TargetTypeGroup 16 ) 17 18 // ToV2 converts TargetType to v2. 19 func (targetType TargetType) ToV2() apeV2.TargetType { 20 return apeV2.TargetType(targetType) 21 } 22 23 // FromV2 reads TargetType to v2. 24 func (targetType *TargetType) FromV2(v2targetType apeV2.TargetType) { 25 *targetType = TargetType(v2targetType) 26 } 27 28 // ChainTarget is an SDK representation for v2's ChainTarget. 29 // 30 // Note that ChainTarget (as well as v2's ChainTarget) and all related entities 31 // are NOT operated by Access-Policy-Engine (APE). The client is responsible 32 // to convert these types to policy-engine entities. 33 type ChainTarget struct { 34 TargetType TargetType 35 36 Name string 37 } 38 39 // ToV2 converts ChainTarget to v2. 40 func (ct *ChainTarget) ToV2() *apeV2.ChainTarget { 41 v2ct := new(apeV2.ChainTarget) 42 43 v2ct.SetTargetType(ct.TargetType.ToV2()) 44 v2ct.SetName(ct.Name) 45 46 return v2ct 47 } 48 49 // FromV2 reads ChainTarget frpm v2. 50 func (ct *ChainTarget) FromV2(v2ct *apeV2.ChainTarget) { 51 ct.TargetType.FromV2(v2ct.GetTargetType()) 52 ct.Name = v2ct.GetName() 53 }