github.com/cloudwan/edgelq-sdk@v1.15.4/iam/resources/v1alpha2/role/role.pb.fieldmask.go (about) 1 // Code generated by protoc-gen-goten-object 2 // File: edgelq/iam/proto/v1alpha2/role.proto 3 // DO NOT EDIT!!! 4 5 package role 6 7 import ( 8 "encoding/json" 9 "strings" 10 11 "google.golang.org/grpc/codes" 12 "google.golang.org/grpc/status" 13 "google.golang.org/protobuf/proto" 14 preflect "google.golang.org/protobuf/reflect/protoreflect" 15 googlefieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb" 16 17 gotenobject "github.com/cloudwan/goten-sdk/runtime/object" 18 ) 19 20 // proto imports 21 import ( 22 condition "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/condition" 23 permission "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/permission" 24 meta "github.com/cloudwan/goten-sdk/types/meta" 25 ) 26 27 // ensure the imports are used 28 var ( 29 _ = new(json.Marshaler) 30 _ = strings.Builder{} 31 32 _ = codes.NotFound 33 _ = status.Status{} 34 _ = new(proto.Message) 35 _ = new(preflect.Message) 36 _ = googlefieldmaskpb.FieldMask{} 37 38 _ = new(gotenobject.FieldMask) 39 ) 40 41 // make sure we're using proto imports 42 var ( 43 _ = &condition.Condition{} 44 _ = &permission.Permission{} 45 _ = &meta.Meta{} 46 ) 47 48 type Role_FieldMask struct { 49 Paths []Role_FieldPath 50 } 51 52 func FullRole_FieldMask() *Role_FieldMask { 53 res := &Role_FieldMask{} 54 res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorName}) 55 res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorDisplayName}) 56 res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorIncludedPermissions}) 57 res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorDefaultConditionBinding}) 58 res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorIncludedConditionBindings}) 59 res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorRequiredConditions}) 60 res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorMetadata}) 61 return res 62 } 63 64 func (fieldMask *Role_FieldMask) String() string { 65 if fieldMask == nil { 66 return "<nil>" 67 } 68 pathsStr := make([]string, 0, len(fieldMask.Paths)) 69 for _, path := range fieldMask.Paths { 70 pathsStr = append(pathsStr, path.String()) 71 } 72 return strings.Join(pathsStr, ", ") 73 } 74 75 func (fieldMask *Role_FieldMask) IsFull() bool { 76 if fieldMask == nil { 77 return false 78 } 79 presentSelectors := make([]bool, 7) 80 for _, path := range fieldMask.Paths { 81 if asFinal, ok := path.(*Role_FieldTerminalPath); ok { 82 presentSelectors[int(asFinal.selector)] = true 83 } 84 } 85 for _, flag := range presentSelectors { 86 if !flag { 87 return false 88 } 89 } 90 return true 91 } 92 93 func (fieldMask *Role_FieldMask) ProtoReflect() preflect.Message { 94 return gotenobject.MakeFieldMaskReflection(fieldMask, func(raw string) (gotenobject.FieldPath, error) { 95 return ParseRole_FieldPath(raw) 96 }) 97 } 98 99 func (fieldMask *Role_FieldMask) ProtoMessage() {} 100 101 func (fieldMask *Role_FieldMask) Reset() { 102 if fieldMask != nil { 103 fieldMask.Paths = nil 104 } 105 } 106 107 func (fieldMask *Role_FieldMask) Subtract(other *Role_FieldMask) *Role_FieldMask { 108 result := &Role_FieldMask{} 109 removedSelectors := make([]bool, 7) 110 otherSubMasks := map[Role_FieldPathSelector]gotenobject.FieldMask{ 111 Role_FieldPathSelectorDefaultConditionBinding: &condition.ConditionBinding_FieldMask{}, 112 Role_FieldPathSelectorIncludedConditionBindings: &condition.ConditionBinding_FieldMask{}, 113 Role_FieldPathSelectorMetadata: &meta.Meta_FieldMask{}, 114 } 115 mySubMasks := map[Role_FieldPathSelector]gotenobject.FieldMask{ 116 Role_FieldPathSelectorDefaultConditionBinding: &condition.ConditionBinding_FieldMask{}, 117 Role_FieldPathSelectorIncludedConditionBindings: &condition.ConditionBinding_FieldMask{}, 118 Role_FieldPathSelectorMetadata: &meta.Meta_FieldMask{}, 119 } 120 121 for _, path := range other.GetPaths() { 122 switch tp := path.(type) { 123 case *Role_FieldTerminalPath: 124 removedSelectors[int(tp.selector)] = true 125 case *Role_FieldSubPath: 126 otherSubMasks[tp.selector].AppendRawPath(tp.subPath) 127 } 128 } 129 for _, path := range fieldMask.GetPaths() { 130 if !removedSelectors[int(path.Selector())] { 131 if otherSubMask := otherSubMasks[path.Selector()]; otherSubMask != nil && otherSubMask.PathsCount() > 0 { 132 if tp, ok := path.(*Role_FieldTerminalPath); ok { 133 switch tp.selector { 134 case Role_FieldPathSelectorDefaultConditionBinding: 135 mySubMasks[Role_FieldPathSelectorDefaultConditionBinding] = condition.FullConditionBinding_FieldMask() 136 case Role_FieldPathSelectorIncludedConditionBindings: 137 mySubMasks[Role_FieldPathSelectorIncludedConditionBindings] = condition.FullConditionBinding_FieldMask() 138 case Role_FieldPathSelectorMetadata: 139 mySubMasks[Role_FieldPathSelectorMetadata] = meta.FullMeta_FieldMask() 140 } 141 } else if tp, ok := path.(*Role_FieldSubPath); ok { 142 mySubMasks[tp.selector].AppendRawPath(tp.subPath) 143 } 144 } else { 145 result.Paths = append(result.Paths, path) 146 } 147 } 148 } 149 for selector, mySubMask := range mySubMasks { 150 if mySubMask.PathsCount() > 0 { 151 for _, allowedPath := range mySubMask.SubtractRaw(otherSubMasks[selector]).GetRawPaths() { 152 result.Paths = append(result.Paths, &Role_FieldSubPath{selector: selector, subPath: allowedPath}) 153 } 154 } 155 } 156 157 if len(result.Paths) == 0 { 158 return nil 159 } 160 return result 161 } 162 163 func (fieldMask *Role_FieldMask) SubtractRaw(other gotenobject.FieldMask) gotenobject.FieldMask { 164 return fieldMask.Subtract(other.(*Role_FieldMask)) 165 } 166 167 // FilterInputFields generates copy of field paths with output_only field paths removed 168 func (fieldMask *Role_FieldMask) FilterInputFields() *Role_FieldMask { 169 result := &Role_FieldMask{} 170 for _, path := range fieldMask.Paths { 171 switch path.Selector() { 172 case Role_FieldPathSelectorMetadata: 173 if _, ok := path.(*Role_FieldTerminalPath); ok { 174 for _, subpath := range meta.FullMeta_FieldMask().FilterInputFields().Paths { 175 result.Paths = append(result.Paths, &Role_FieldSubPath{selector: path.Selector(), subPath: subpath}) 176 } 177 } else if sub, ok := path.(*Role_FieldSubPath); ok { 178 selectedMask := &meta.Meta_FieldMask{ 179 Paths: []meta.Meta_FieldPath{sub.subPath.(meta.Meta_FieldPath)}, 180 } 181 for _, allowedPath := range selectedMask.FilterInputFields().Paths { 182 result.Paths = append(result.Paths, &Role_FieldSubPath{selector: Role_FieldPathSelectorMetadata, subPath: allowedPath}) 183 } 184 } 185 default: 186 result.Paths = append(result.Paths, path) 187 } 188 } 189 return result 190 } 191 192 // ToFieldMask is used for proto conversions 193 func (fieldMask *Role_FieldMask) ToProtoFieldMask() *googlefieldmaskpb.FieldMask { 194 protoFieldMask := &googlefieldmaskpb.FieldMask{} 195 for _, path := range fieldMask.Paths { 196 protoFieldMask.Paths = append(protoFieldMask.Paths, path.String()) 197 } 198 return protoFieldMask 199 } 200 201 func (fieldMask *Role_FieldMask) FromProtoFieldMask(protoFieldMask *googlefieldmaskpb.FieldMask) error { 202 if fieldMask == nil { 203 return status.Error(codes.Internal, "target field mask is nil") 204 } 205 fieldMask.Paths = make([]Role_FieldPath, 0, len(protoFieldMask.Paths)) 206 for _, strPath := range protoFieldMask.Paths { 207 path, err := ParseRole_FieldPath(strPath) 208 if err != nil { 209 return err 210 } 211 fieldMask.Paths = append(fieldMask.Paths, path) 212 } 213 return nil 214 } 215 216 // implement methods required by customType 217 func (fieldMask Role_FieldMask) Marshal() ([]byte, error) { 218 protoFieldMask := fieldMask.ToProtoFieldMask() 219 return proto.Marshal(protoFieldMask) 220 } 221 222 func (fieldMask *Role_FieldMask) Unmarshal(data []byte) error { 223 protoFieldMask := &googlefieldmaskpb.FieldMask{} 224 if err := proto.Unmarshal(data, protoFieldMask); err != nil { 225 return err 226 } 227 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 228 return err 229 } 230 return nil 231 } 232 233 func (fieldMask *Role_FieldMask) Size() int { 234 return proto.Size(fieldMask.ToProtoFieldMask()) 235 } 236 237 func (fieldMask Role_FieldMask) MarshalJSON() ([]byte, error) { 238 return json.Marshal(fieldMask.ToProtoFieldMask()) 239 } 240 241 func (fieldMask *Role_FieldMask) UnmarshalJSON(data []byte) error { 242 protoFieldMask := &googlefieldmaskpb.FieldMask{} 243 if err := json.Unmarshal(data, protoFieldMask); err != nil { 244 return err 245 } 246 if err := fieldMask.FromProtoFieldMask(protoFieldMask); err != nil { 247 return err 248 } 249 return nil 250 } 251 252 func (fieldMask *Role_FieldMask) AppendPath(path Role_FieldPath) { 253 fieldMask.Paths = append(fieldMask.Paths, path) 254 } 255 256 func (fieldMask *Role_FieldMask) AppendRawPath(path gotenobject.FieldPath) { 257 fieldMask.Paths = append(fieldMask.Paths, path.(Role_FieldPath)) 258 } 259 260 func (fieldMask *Role_FieldMask) GetPaths() []Role_FieldPath { 261 if fieldMask == nil { 262 return nil 263 } 264 return fieldMask.Paths 265 } 266 267 func (fieldMask *Role_FieldMask) GetRawPaths() []gotenobject.FieldPath { 268 if fieldMask == nil { 269 return nil 270 } 271 rawPaths := make([]gotenobject.FieldPath, 0, len(fieldMask.Paths)) 272 for _, path := range fieldMask.Paths { 273 rawPaths = append(rawPaths, path) 274 } 275 return rawPaths 276 } 277 278 func (fieldMask *Role_FieldMask) SetFromCliFlag(raw string) error { 279 path, err := ParseRole_FieldPath(raw) 280 if err != nil { 281 return err 282 } 283 fieldMask.Paths = append(fieldMask.Paths, path) 284 return nil 285 } 286 287 func (fieldMask *Role_FieldMask) Set(target, source *Role) { 288 for _, path := range fieldMask.Paths { 289 val, _ := path.GetSingle(source) 290 // if val is nil, then field does not exist in source, skip 291 // otherwise, process (can still reflect.ValueOf(val).IsNil!) 292 if val != nil { 293 path.WithIValue(val).SetTo(&target) 294 } 295 } 296 } 297 298 func (fieldMask *Role_FieldMask) SetRaw(target, source gotenobject.GotenObjectExt) { 299 fieldMask.Set(target.(*Role), source.(*Role)) 300 } 301 302 func (fieldMask *Role_FieldMask) Project(source *Role) *Role { 303 if source == nil { 304 return nil 305 } 306 if fieldMask == nil { 307 return source 308 } 309 result := &Role{} 310 defaultConditionBindingMask := &condition.ConditionBinding_FieldMask{} 311 wholeDefaultConditionBindingAccepted := false 312 includedConditionBindingsMask := &condition.ConditionBinding_FieldMask{} 313 wholeIncludedConditionBindingsAccepted := false 314 metadataMask := &meta.Meta_FieldMask{} 315 wholeMetadataAccepted := false 316 317 for _, p := range fieldMask.Paths { 318 switch tp := p.(type) { 319 case *Role_FieldTerminalPath: 320 switch tp.selector { 321 case Role_FieldPathSelectorName: 322 result.Name = source.Name 323 case Role_FieldPathSelectorDisplayName: 324 result.DisplayName = source.DisplayName 325 case Role_FieldPathSelectorIncludedPermissions: 326 result.IncludedPermissions = source.IncludedPermissions 327 case Role_FieldPathSelectorDefaultConditionBinding: 328 result.DefaultConditionBinding = source.DefaultConditionBinding 329 wholeDefaultConditionBindingAccepted = true 330 case Role_FieldPathSelectorIncludedConditionBindings: 331 result.IncludedConditionBindings = source.IncludedConditionBindings 332 wholeIncludedConditionBindingsAccepted = true 333 case Role_FieldPathSelectorRequiredConditions: 334 result.RequiredConditions = source.RequiredConditions 335 case Role_FieldPathSelectorMetadata: 336 result.Metadata = source.Metadata 337 wholeMetadataAccepted = true 338 } 339 case *Role_FieldSubPath: 340 switch tp.selector { 341 case Role_FieldPathSelectorDefaultConditionBinding: 342 defaultConditionBindingMask.AppendPath(tp.subPath.(condition.ConditionBinding_FieldPath)) 343 case Role_FieldPathSelectorIncludedConditionBindings: 344 includedConditionBindingsMask.AppendPath(tp.subPath.(condition.ConditionBinding_FieldPath)) 345 case Role_FieldPathSelectorMetadata: 346 metadataMask.AppendPath(tp.subPath.(meta.Meta_FieldPath)) 347 } 348 } 349 } 350 if wholeDefaultConditionBindingAccepted == false && len(defaultConditionBindingMask.Paths) > 0 { 351 result.DefaultConditionBinding = defaultConditionBindingMask.Project(source.GetDefaultConditionBinding()) 352 } 353 if wholeIncludedConditionBindingsAccepted == false && len(includedConditionBindingsMask.Paths) > 0 { 354 for _, sourceItem := range source.GetIncludedConditionBindings() { 355 result.IncludedConditionBindings = append(result.IncludedConditionBindings, includedConditionBindingsMask.Project(sourceItem)) 356 } 357 } 358 if wholeMetadataAccepted == false && len(metadataMask.Paths) > 0 { 359 result.Metadata = metadataMask.Project(source.GetMetadata()) 360 } 361 return result 362 } 363 364 func (fieldMask *Role_FieldMask) ProjectRaw(source gotenobject.GotenObjectExt) gotenobject.GotenObjectExt { 365 return fieldMask.Project(source.(*Role)) 366 } 367 368 func (fieldMask *Role_FieldMask) PathsCount() int { 369 if fieldMask == nil { 370 return 0 371 } 372 return len(fieldMask.Paths) 373 }