github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/acl/test/generate.go (about) 1 package acltest 2 3 import ( 4 "github.com/TrueCloudLab/frostfs-api-go/v2/acl" 5 accountingtest "github.com/TrueCloudLab/frostfs-api-go/v2/refs/test" 6 ) 7 8 func GenerateBearerToken(empty bool) *acl.BearerToken { 9 m := new(acl.BearerToken) 10 11 if !empty { 12 m.SetBody(GenerateBearerTokenBody(false)) 13 } 14 15 m.SetSignature(accountingtest.GenerateSignature(empty)) 16 17 return m 18 } 19 20 func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody { 21 m := new(acl.BearerTokenBody) 22 23 if !empty { 24 m.SetOwnerID(accountingtest.GenerateOwnerID(false)) 25 m.SetEACL(GenerateTable(false)) 26 m.SetLifetime(GenerateTokenLifetime(false)) 27 } 28 29 return m 30 } 31 32 func GenerateTable(empty bool) *acl.Table { 33 m := new(acl.Table) 34 35 if !empty { 36 m.SetRecords(GenerateRecords(false)) 37 m.SetContainerID(accountingtest.GenerateContainerID(false)) 38 } 39 40 m.SetVersion(accountingtest.GenerateVersion(empty)) 41 42 return m 43 } 44 45 func GenerateRecords(empty bool) []acl.Record { 46 var rs []acl.Record 47 48 if !empty { 49 rs = append(rs, 50 *GenerateRecord(false), 51 *GenerateRecord(false), 52 ) 53 } 54 55 return rs 56 } 57 58 func GenerateRecord(empty bool) *acl.Record { 59 m := new(acl.Record) 60 61 if !empty { 62 m.SetAction(acl.ActionAllow) 63 m.SetOperation(acl.OperationGet) 64 m.SetFilters(GenerateFilters(false)) 65 m.SetTargets(GenerateTargets(false)) 66 } 67 68 return m 69 } 70 71 func GenerateFilters(empty bool) []acl.HeaderFilter { 72 var fs []acl.HeaderFilter 73 74 if !empty { 75 fs = append(fs, 76 *GenerateFilter(false), 77 *GenerateFilter(false), 78 ) 79 } 80 81 return fs 82 } 83 84 func GenerateFilter(empty bool) *acl.HeaderFilter { 85 m := new(acl.HeaderFilter) 86 87 if !empty { 88 m.SetKey("key") 89 m.SetValue("val") 90 m.SetHeaderType(acl.HeaderTypeRequest) 91 m.SetMatchType(acl.MatchTypeStringEqual) 92 } 93 94 return m 95 } 96 97 func GenerateTargets(empty bool) []acl.Target { 98 var ts []acl.Target 99 100 if !empty { 101 ts = append(ts, 102 *GenerateTarget(false), 103 *GenerateTarget(false), 104 ) 105 } 106 107 return ts 108 } 109 110 func GenerateTarget(empty bool) *acl.Target { 111 m := new(acl.Target) 112 113 if !empty { 114 m.SetRole(acl.RoleSystem) 115 m.SetKeys([][]byte{{1}, {2}}) 116 } 117 118 return m 119 } 120 121 func GenerateTokenLifetime(empty bool) *acl.TokenLifetime { 122 m := new(acl.TokenLifetime) 123 124 if !empty { 125 m.SetExp(1) 126 m.SetIat(2) 127 m.SetExp(3) 128 } 129 130 return m 131 }