github.com/cloudwan/edgelq-sdk@v1.15.4/iam/resources/v1alpha2/permission/permission.pb.fieldmask.go (about)

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