github.com/cloudwan/edgelq-sdk@v1.15.4/iam/resources/v1alpha2/role/role.pb.object_ext.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  	"fmt"
     9  	"sort"
    10  
    11  	"google.golang.org/protobuf/proto"
    12  	googlefieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb"
    13  
    14  	gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
    15  )
    16  
    17  // proto imports
    18  import (
    19  	condition "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/condition"
    20  	permission "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/permission"
    21  	meta "github.com/cloudwan/goten-sdk/types/meta"
    22  )
    23  
    24  // ensure the imports are used
    25  var (
    26  	_ = new(fmt.Stringer)
    27  	_ = new(sort.Interface)
    28  
    29  	_ = new(proto.Message)
    30  	_ = googlefieldmaskpb.FieldMask{}
    31  
    32  	_ = new(gotenobject.FieldPath)
    33  )
    34  
    35  // make sure we're using proto imports
    36  var (
    37  	_ = &condition.Condition{}
    38  	_ = &permission.Permission{}
    39  	_ = &meta.Meta{}
    40  )
    41  
    42  func (o *Role) GotenObjectExt() {}
    43  
    44  func (o *Role) MakeFullFieldMask() *Role_FieldMask {
    45  	return FullRole_FieldMask()
    46  }
    47  
    48  func (o *Role) MakeRawFullFieldMask() gotenobject.FieldMask {
    49  	return FullRole_FieldMask()
    50  }
    51  
    52  func (o *Role) MakeDiffFieldMask(other *Role) *Role_FieldMask {
    53  	if o == nil && other == nil {
    54  		return &Role_FieldMask{}
    55  	}
    56  	if o == nil || other == nil {
    57  		return FullRole_FieldMask()
    58  	}
    59  
    60  	res := &Role_FieldMask{}
    61  	if o.GetName().String() != other.GetName().String() {
    62  		res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorName})
    63  	}
    64  	if o.GetDisplayName() != other.GetDisplayName() {
    65  		res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorDisplayName})
    66  	}
    67  
    68  	if len(o.GetIncludedPermissions()) == len(other.GetIncludedPermissions()) {
    69  		for i, lValue := range o.GetIncludedPermissions() {
    70  			rValue := other.GetIncludedPermissions()[i]
    71  			if lValue.String() != rValue.String() {
    72  				res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorIncludedPermissions})
    73  				break
    74  			}
    75  		}
    76  	} else {
    77  		res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorIncludedPermissions})
    78  	}
    79  	{
    80  		subMask := o.GetDefaultConditionBinding().MakeDiffFieldMask(other.GetDefaultConditionBinding())
    81  		if subMask.IsFull() {
    82  			res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorDefaultConditionBinding})
    83  		} else {
    84  			for _, subpath := range subMask.Paths {
    85  				res.Paths = append(res.Paths, &Role_FieldSubPath{selector: Role_FieldPathSelectorDefaultConditionBinding, subPath: subpath})
    86  			}
    87  		}
    88  	}
    89  
    90  	if len(o.GetIncludedConditionBindings()) == len(other.GetIncludedConditionBindings()) {
    91  		for i, lValue := range o.GetIncludedConditionBindings() {
    92  			rValue := other.GetIncludedConditionBindings()[i]
    93  			if len(lValue.MakeDiffFieldMask(rValue).Paths) > 0 {
    94  				res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorIncludedConditionBindings})
    95  				break
    96  			}
    97  		}
    98  	} else {
    99  		res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorIncludedConditionBindings})
   100  	}
   101  
   102  	if len(o.GetRequiredConditions()) == len(other.GetRequiredConditions()) {
   103  		for i, lValue := range o.GetRequiredConditions() {
   104  			rValue := other.GetRequiredConditions()[i]
   105  			if lValue.String() != rValue.String() {
   106  				res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorRequiredConditions})
   107  				break
   108  			}
   109  		}
   110  	} else {
   111  		res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorRequiredConditions})
   112  	}
   113  	{
   114  		subMask := o.GetMetadata().MakeDiffFieldMask(other.GetMetadata())
   115  		if subMask.IsFull() {
   116  			res.Paths = append(res.Paths, &Role_FieldTerminalPath{selector: Role_FieldPathSelectorMetadata})
   117  		} else {
   118  			for _, subpath := range subMask.Paths {
   119  				res.Paths = append(res.Paths, &Role_FieldSubPath{selector: Role_FieldPathSelectorMetadata, subPath: subpath})
   120  			}
   121  		}
   122  	}
   123  	return res
   124  }
   125  
   126  func (o *Role) MakeRawDiffFieldMask(other gotenobject.GotenObjectExt) gotenobject.FieldMask {
   127  	return o.MakeDiffFieldMask(other.(*Role))
   128  }
   129  
   130  func (o *Role) Clone() *Role {
   131  	if o == nil {
   132  		return nil
   133  	}
   134  	result := &Role{}
   135  	if o.Name == nil {
   136  		result.Name = nil
   137  	} else if data, err := o.Name.ProtoString(); err != nil {
   138  		panic(err)
   139  	} else {
   140  		result.Name = &Name{}
   141  		if err := result.Name.ParseProtoString(data); err != nil {
   142  			panic(err)
   143  		}
   144  	}
   145  	result.DisplayName = o.DisplayName
   146  	result.IncludedPermissions = make([]*permission.Reference, len(o.IncludedPermissions))
   147  	for i, sourceValue := range o.IncludedPermissions {
   148  		if sourceValue == nil {
   149  			result.IncludedPermissions[i] = nil
   150  		} else if data, err := sourceValue.ProtoString(); err != nil {
   151  			panic(err)
   152  		} else {
   153  			result.IncludedPermissions[i] = &permission.Reference{}
   154  			if err := result.IncludedPermissions[i].ParseProtoString(data); err != nil {
   155  				panic(err)
   156  			}
   157  		}
   158  	}
   159  	result.DefaultConditionBinding = o.DefaultConditionBinding.Clone()
   160  	result.IncludedConditionBindings = make([]*condition.ConditionBinding, len(o.IncludedConditionBindings))
   161  	for i, sourceValue := range o.IncludedConditionBindings {
   162  		result.IncludedConditionBindings[i] = sourceValue.Clone()
   163  	}
   164  	result.RequiredConditions = make([]*condition.Reference, len(o.RequiredConditions))
   165  	for i, sourceValue := range o.RequiredConditions {
   166  		if sourceValue == nil {
   167  			result.RequiredConditions[i] = nil
   168  		} else if data, err := sourceValue.ProtoString(); err != nil {
   169  			panic(err)
   170  		} else {
   171  			result.RequiredConditions[i] = &condition.Reference{}
   172  			if err := result.RequiredConditions[i].ParseProtoString(data); err != nil {
   173  				panic(err)
   174  			}
   175  		}
   176  	}
   177  	result.Metadata = o.Metadata.Clone()
   178  	return result
   179  }
   180  
   181  func (o *Role) CloneRaw() gotenobject.GotenObjectExt {
   182  	return o.Clone()
   183  }
   184  
   185  func (o *Role) Merge(source *Role) {
   186  	if source.GetName() != nil {
   187  		if data, err := source.GetName().ProtoString(); err != nil {
   188  			panic(err)
   189  		} else {
   190  			o.Name = &Name{}
   191  			if err := o.Name.ParseProtoString(data); err != nil {
   192  				panic(err)
   193  			}
   194  		}
   195  	} else {
   196  		o.Name = nil
   197  	}
   198  	o.DisplayName = source.GetDisplayName()
   199  	for _, sourceValue := range source.GetIncludedPermissions() {
   200  		exists := false
   201  		for _, currentValue := range o.IncludedPermissions {
   202  			leftProtoStr, _ := currentValue.ProtoString()
   203  			rightProtoStr, _ := sourceValue.ProtoString()
   204  			if leftProtoStr == rightProtoStr {
   205  				exists = true
   206  				break
   207  			}
   208  		}
   209  		if !exists {
   210  			var newDstElement *permission.Reference
   211  			if sourceValue != nil {
   212  				if data, err := sourceValue.ProtoString(); err != nil {
   213  					panic(err)
   214  				} else {
   215  					newDstElement = &permission.Reference{}
   216  					if err := newDstElement.ParseProtoString(data); err != nil {
   217  						panic(err)
   218  					}
   219  				}
   220  			}
   221  			o.IncludedPermissions = append(o.IncludedPermissions, newDstElement)
   222  		}
   223  	}
   224  
   225  	if source.GetDefaultConditionBinding() != nil {
   226  		if o.DefaultConditionBinding == nil {
   227  			o.DefaultConditionBinding = new(condition.ConditionBinding)
   228  		}
   229  		o.DefaultConditionBinding.Merge(source.GetDefaultConditionBinding())
   230  	}
   231  	for _, sourceValue := range source.GetIncludedConditionBindings() {
   232  		exists := false
   233  		for _, currentValue := range o.IncludedConditionBindings {
   234  			if proto.Equal(sourceValue, currentValue) {
   235  				exists = true
   236  				break
   237  			}
   238  		}
   239  		if !exists {
   240  			var newDstElement *condition.ConditionBinding
   241  			if sourceValue != nil {
   242  				newDstElement = new(condition.ConditionBinding)
   243  				newDstElement.Merge(sourceValue)
   244  			}
   245  			o.IncludedConditionBindings = append(o.IncludedConditionBindings, newDstElement)
   246  		}
   247  	}
   248  
   249  	for _, sourceValue := range source.GetRequiredConditions() {
   250  		exists := false
   251  		for _, currentValue := range o.RequiredConditions {
   252  			leftProtoStr, _ := currentValue.ProtoString()
   253  			rightProtoStr, _ := sourceValue.ProtoString()
   254  			if leftProtoStr == rightProtoStr {
   255  				exists = true
   256  				break
   257  			}
   258  		}
   259  		if !exists {
   260  			var newDstElement *condition.Reference
   261  			if sourceValue != nil {
   262  				if data, err := sourceValue.ProtoString(); err != nil {
   263  					panic(err)
   264  				} else {
   265  					newDstElement = &condition.Reference{}
   266  					if err := newDstElement.ParseProtoString(data); err != nil {
   267  						panic(err)
   268  					}
   269  				}
   270  			}
   271  			o.RequiredConditions = append(o.RequiredConditions, newDstElement)
   272  		}
   273  	}
   274  
   275  	if source.GetMetadata() != nil {
   276  		if o.Metadata == nil {
   277  			o.Metadata = new(meta.Meta)
   278  		}
   279  		o.Metadata.Merge(source.GetMetadata())
   280  	}
   281  }
   282  
   283  func (o *Role) MergeRaw(source gotenobject.GotenObjectExt) {
   284  	o.Merge(source.(*Role))
   285  }