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

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