github.com/cloudwan/edgelq-sdk@v1.15.4/devices/resources/v1alpha2/provisioning_approval_request/provisioning_approval_request.pb.name.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: ProvisioningApprovalRequest
     3  // DO NOT EDIT!!!
     4  
     5  package provisioning_approval_request
     6  
     7  import (
     8  	"fmt"
     9  	"net/url"
    10  	"reflect"
    11  	"regexp"
    12  	"strings"
    13  
    14  	"google.golang.org/grpc/codes"
    15  	"google.golang.org/grpc/status"
    16  	"google.golang.org/protobuf/proto"
    17  
    18  	"github.com/cloudwan/goten-sdk/runtime/goten"
    19  	gotenresource "github.com/cloudwan/goten-sdk/runtime/resource"
    20  )
    21  
    22  // proto imports
    23  import (
    24  	provisioning_policy "github.com/cloudwan/edgelq-sdk/devices/resources/v1alpha2/provisioning_policy"
    25  	iam_service_account "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/service_account"
    26  	meta "github.com/cloudwan/goten-sdk/types/meta"
    27  )
    28  
    29  // ensure the imports are used
    30  var (
    31  	_ = codes.NotFound
    32  	_ = new(fmt.Stringer)
    33  	_ = new(proto.Message)
    34  	_ = status.Status{}
    35  	_ = url.URL{}
    36  	_ = strings.Builder{}
    37  
    38  	_ = new(goten.GotenMessage)
    39  	_ = new(gotenresource.ListQuery)
    40  )
    41  
    42  // make sure we're using proto imports
    43  var (
    44  	_ = &provisioning_policy.ProvisioningPolicy{}
    45  	_ = &iam_service_account.ServiceAccount{}
    46  	_ = &meta.Meta{}
    47  )
    48  
    49  var provisioningApprovalRequest_RegexpId = regexp.MustCompile("^(?P<provisioning_approval_request_id>[\\w][\\w.-]{0,127})$")
    50  var regexPath_Project_Region_ProvisioningPolicy = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})/regions/(?P<region_id>-|[a-z][a-z0-9\\-]{0,28}[a-z0-9])/provisioningPolicies/(?P<provisioning_policy_id>-|[\\w][\\w.-]{0,127})/provisioningApprovalRequests/(?P<provisioning_approval_request_id>-|[\\w][\\w.-]{0,127})$")
    51  
    52  func (r *ProvisioningApprovalRequest) MaybePopulateDefaults() error {
    53  	provisioningApprovalRequestInterface := interface{}(r)
    54  	if defaulter, ok := provisioningApprovalRequestInterface.(goten.Defaulter); ok {
    55  		return defaulter.PopulateDefaults()
    56  	}
    57  	return nil
    58  }
    59  
    60  type Name struct {
    61  	ParentName
    62  	ProvisioningApprovalRequestId string `firestore:"provisioningApprovalRequestId"`
    63  }
    64  
    65  func ParseName(name string) (*Name, error) {
    66  	var matches []string
    67  	if matches = regexPath_Project_Region_ProvisioningPolicy.FindStringSubmatch(name); matches != nil {
    68  		return NewNameBuilder().
    69  			SetProjectId(matches[1]).
    70  			SetRegionId(matches[2]).
    71  			SetProvisioningPolicyId(matches[3]).
    72  			SetId(matches[4]).
    73  			Name(), nil
    74  	}
    75  
    76  	return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as ProvisioningApprovalRequest name", name)
    77  }
    78  
    79  func MustParseName(name string) *Name {
    80  	result, err := ParseName(name)
    81  	if err != nil {
    82  		panic(err)
    83  	}
    84  	return result
    85  }
    86  
    87  func ParseNameOrId(nameOrId string) (*Name, error) {
    88  	name, err := ParseName(nameOrId)
    89  	if err == nil {
    90  		return name, err
    91  	}
    92  	if provisioningApprovalRequest_RegexpId.MatchString(nameOrId) {
    93  		return &Name{ProvisioningApprovalRequestId: nameOrId}, nil
    94  	} else {
    95  		return nil, fmt.Errorf("unable to parse '%s' as ProvisioningApprovalRequest name or id", nameOrId)
    96  	}
    97  }
    98  
    99  func (name *Name) SetFromSegments(segments gotenresource.NameSegments) error {
   100  	if len(segments) == 0 {
   101  		return status.Errorf(codes.InvalidArgument, "No segments given for ProvisioningApprovalRequest name")
   102  	}
   103  	if err := name.ParentName.SetFromSegments(segments[:len(segments)-1]); err != nil {
   104  		return err
   105  	}
   106  	if segments[len(segments)-1].CollectionLowerJson != "provisioningApprovalRequests" {
   107  		return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form ProvisioningApprovalRequest name", segments)
   108  	}
   109  	name.ProvisioningApprovalRequestId = segments[len(segments)-1].Id
   110  	return nil
   111  }
   112  
   113  func (name *Name) GetProvisioningPolicyName() *provisioning_policy.Name {
   114  	if name == nil {
   115  		return nil
   116  	}
   117  	return name.ParentName.GetProvisioningPolicyName()
   118  }
   119  
   120  func (name *Name) IsSpecified() bool {
   121  	if name == nil || name.Pattern == "" || name.ProvisioningApprovalRequestId == "" {
   122  		return false
   123  	}
   124  	return name.ParentName.IsSpecified()
   125  }
   126  
   127  func (name *Name) IsFullyQualified() bool {
   128  	if name == nil {
   129  		return false
   130  	}
   131  	if name.ParentName.IsFullyQualified() == false {
   132  		return false
   133  	}
   134  	if name.ProvisioningApprovalRequestId == "" || name.ProvisioningApprovalRequestId == gotenresource.WildcardId {
   135  		return false
   136  	}
   137  	return true
   138  }
   139  
   140  func (name *Name) FullyQualifiedName() (string, error) {
   141  	if !name.IsFullyQualified() {
   142  		return "", status.Errorf(codes.InvalidArgument, "Name for ProvisioningApprovalRequest is not fully qualified")
   143  	}
   144  	return fmt.Sprintf("//devices.edgelq.com/%s", name.String()), nil
   145  }
   146  
   147  func (name *Name) String() string {
   148  	if name == nil {
   149  		return "<nil>"
   150  	}
   151  	if valueStr, err := name.ProtoString(); err != nil {
   152  		panic(err)
   153  	} else {
   154  		return valueStr
   155  	}
   156  }
   157  
   158  func (name *Name) AsReference() *Reference {
   159  	return &Reference{Name: *name}
   160  }
   161  
   162  func (name *Name) AsRawReference() gotenresource.Reference {
   163  	return name.AsReference()
   164  }
   165  
   166  func (name *Name) GetResourceDescriptor() gotenresource.Descriptor {
   167  	return descriptor
   168  }
   169  
   170  func (name *Name) GetPattern() gotenresource.NamePattern {
   171  	if name == nil {
   172  		return ""
   173  	}
   174  	return name.Pattern
   175  }
   176  
   177  func (name *Name) GetIdParts() map[string]string {
   178  	if name != nil {
   179  		return map[string]string{
   180  			"projectId":                     name.ProjectId,
   181  			"regionId":                      name.RegionId,
   182  			"provisioningPolicyId":          name.ProvisioningPolicyId,
   183  			"provisioningApprovalRequestId": name.ProvisioningApprovalRequestId,
   184  		}
   185  	}
   186  	return map[string]string{
   187  		"projectId":                     "",
   188  		"regionId":                      "",
   189  		"provisioningPolicyId":          "",
   190  		"provisioningApprovalRequestId": "",
   191  	}
   192  }
   193  
   194  func (name *Name) GetSegments() gotenresource.NameSegments {
   195  	if name == nil || name.Pattern == "" {
   196  		return nil
   197  	}
   198  	segments := name.ParentName.GetSegments()
   199  	return append(segments, gotenresource.NameSegment{
   200  		CollectionLowerJson: "provisioningApprovalRequests",
   201  		Id:                  name.ProvisioningApprovalRequestId,
   202  	})
   203  }
   204  
   205  func (name *Name) GetIParentName() gotenresource.Name {
   206  	if name == nil {
   207  		return (*ParentName)(nil)
   208  	}
   209  	return &name.ParentName
   210  }
   211  
   212  func (name *Name) GetIUnderlyingParentName() gotenresource.Name {
   213  	if parentName := name.GetProvisioningPolicyName(); parentName != nil {
   214  		return parentName
   215  	}
   216  	return nil
   217  }
   218  
   219  // implement methods required by protobuf-go library for string-struct conversion
   220  
   221  func (name *Name) ProtoString() (string, error) {
   222  	if name == nil {
   223  		return "", nil
   224  	}
   225  	result := ""
   226  	parentPrefix, err := name.ParentName.ProtoString()
   227  	if err != nil {
   228  		return "", err
   229  	}
   230  	if parentPrefix != "" {
   231  		result += parentPrefix + "/"
   232  	}
   233  	result += "provisioningApprovalRequests/" + name.ProvisioningApprovalRequestId
   234  	return result, nil
   235  }
   236  
   237  func (name *Name) ParseProtoString(data string) error {
   238  	parsed, err := ParseName(data)
   239  	if err != nil {
   240  		return err
   241  	}
   242  	*name = *parsed
   243  	return nil
   244  }
   245  
   246  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   247  func (name *Name) GotenEqual(other interface{}) bool {
   248  	if other == nil {
   249  		return name == nil
   250  	}
   251  	other1, ok := other.(*Name)
   252  	if !ok {
   253  		other2, ok := other.(Name)
   254  		if ok {
   255  			other1 = &other2
   256  		} else {
   257  			return false
   258  		}
   259  	}
   260  	if other1 == nil {
   261  		return name == nil
   262  	} else if name == nil {
   263  		return false
   264  	}
   265  	if name.ParentName.GotenEqual(other1.ParentName) == false {
   266  		return false
   267  	}
   268  	if name.ProvisioningApprovalRequestId != other1.ProvisioningApprovalRequestId {
   269  		return false
   270  	}
   271  
   272  	return true
   273  }
   274  
   275  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   276  func (name *Name) Matches(other interface{}) bool {
   277  	if other == nil {
   278  		return name == nil
   279  	}
   280  	other1, ok := other.(*Name)
   281  	if !ok {
   282  		other2, ok := other.(Name)
   283  		if ok {
   284  			other1 = &other2
   285  		} else {
   286  			return false
   287  		}
   288  	}
   289  	if other1 == nil {
   290  		return name == nil
   291  	} else if name == nil {
   292  		return false
   293  	}
   294  	if name.ParentName.Matches(other1.ParentName) == false {
   295  		return false
   296  	}
   297  	if name.ProvisioningApprovalRequestId != other1.ProvisioningApprovalRequestId {
   298  		return name.ProvisioningApprovalRequestId == gotenresource.WildcardId
   299  	}
   300  
   301  	return true
   302  }
   303  
   304  // implement CustomTypeCliValue method
   305  func (name *Name) SetFromCliFlag(raw string) error {
   306  	parsedName, err := ParseName(raw)
   307  	if err != nil {
   308  		return err
   309  	}
   310  	*name = *parsedName
   311  	return nil
   312  }
   313  
   314  type Reference struct {
   315  	Name
   316  	provisioningApprovalRequest *ProvisioningApprovalRequest
   317  }
   318  
   319  func MakeReference(name *Name, provisioningApprovalRequest *ProvisioningApprovalRequest) (*Reference, error) {
   320  	return &Reference{
   321  		Name:                        *name,
   322  		provisioningApprovalRequest: provisioningApprovalRequest,
   323  	}, nil
   324  }
   325  
   326  func ParseReference(name string) (*Reference, error) {
   327  	parsedName, err := ParseName(name)
   328  	if err != nil {
   329  		return nil, err
   330  	}
   331  	return MakeReference(parsedName, nil)
   332  }
   333  
   334  func MustParseReference(name string) *Reference {
   335  	result, err := ParseReference(name)
   336  	if err != nil {
   337  		panic(err)
   338  	}
   339  	return result
   340  }
   341  
   342  func (ref *Reference) Resolve(resolved *ProvisioningApprovalRequest) {
   343  	ref.provisioningApprovalRequest = resolved
   344  }
   345  
   346  func (ref *Reference) ResolveRaw(res gotenresource.Resource) error {
   347  	if res == nil {
   348  		ref.Resolve(nil)
   349  		return nil
   350  	}
   351  	if typedRes, ok := res.(*ProvisioningApprovalRequest); ok {
   352  		ref.Resolve(typedRes)
   353  		return nil
   354  	}
   355  	return status.Errorf(codes.Internal, "Invalid resource type for ProvisioningApprovalRequest: %s", reflect.TypeOf(res).Elem().Name())
   356  }
   357  
   358  func (ref *Reference) Resolved() bool {
   359  	return ref != nil && ref.provisioningApprovalRequest != nil
   360  }
   361  
   362  func (ref *Reference) ClearCached() {
   363  	ref.provisioningApprovalRequest = nil
   364  }
   365  
   366  func (ref *Reference) GetProvisioningApprovalRequest() *ProvisioningApprovalRequest {
   367  	if ref == nil {
   368  		return nil
   369  	}
   370  	return ref.provisioningApprovalRequest
   371  }
   372  
   373  func (ref *Reference) GetRawResource() gotenresource.Resource {
   374  	if ref == nil {
   375  		return (*ProvisioningApprovalRequest)(nil)
   376  	}
   377  	return ref.provisioningApprovalRequest
   378  }
   379  
   380  func (ref *Reference) IsFullyQualified() bool {
   381  	if ref == nil {
   382  		return false
   383  	}
   384  	return ref.Name.IsFullyQualified()
   385  }
   386  
   387  func (ref *Reference) IsSpecified() bool {
   388  	if ref == nil {
   389  		return false
   390  	}
   391  	return ref.Name.IsSpecified()
   392  }
   393  
   394  func (ref *Reference) FullyQualifiedName() (string, error) {
   395  	if !ref.IsFullyQualified() {
   396  		return "", status.Errorf(codes.InvalidArgument, "Name for ProvisioningApprovalRequest is not fully qualified")
   397  	}
   398  	return fmt.Sprintf("//devices.edgelq.com/%s", ref.String()), nil
   399  }
   400  
   401  func (ref *Reference) GetResourceDescriptor() gotenresource.Descriptor {
   402  	return descriptor
   403  }
   404  
   405  func (ref *Reference) GetPattern() gotenresource.NamePattern {
   406  	if ref == nil {
   407  		return ""
   408  	}
   409  	return ref.Pattern
   410  }
   411  
   412  func (ref *Reference) GetIdParts() map[string]string {
   413  	if ref != nil {
   414  		return ref.Name.GetIdParts()
   415  	}
   416  	return map[string]string{
   417  		"projectId":                     "",
   418  		"regionId":                      "",
   419  		"provisioningPolicyId":          "",
   420  		"provisioningApprovalRequestId": "",
   421  	}
   422  }
   423  
   424  func (ref *Reference) GetSegments() gotenresource.NameSegments {
   425  	if ref != nil {
   426  		return ref.Name.GetSegments()
   427  	}
   428  	return nil
   429  }
   430  
   431  func (ref *Reference) GetIParentName() gotenresource.Name {
   432  	if ref == nil {
   433  		return (*ParentName)(nil)
   434  	}
   435  	return ref.Name.GetIParentName()
   436  }
   437  
   438  func (ref *Reference) GetIUnderlyingParentName() gotenresource.Name {
   439  	if ref != nil {
   440  		return ref.Name.GetIUnderlyingParentName()
   441  	}
   442  	return nil
   443  }
   444  
   445  func (ref *Reference) String() string {
   446  	if ref == nil {
   447  		return "<nil>"
   448  	}
   449  	return ref.Name.String()
   450  }
   451  
   452  // implement methods required by protobuf-go library for string-struct conversion
   453  
   454  func (ref *Reference) ProtoString() (string, error) {
   455  	if ref == nil {
   456  		return "", nil
   457  	}
   458  	return ref.Name.ProtoString()
   459  }
   460  
   461  func (ref *Reference) ParseProtoString(data string) error {
   462  	parsed, err := ParseReference(data)
   463  	if err != nil {
   464  		return err
   465  	}
   466  	*ref = *parsed
   467  	return nil
   468  }
   469  
   470  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   471  func (ref *Reference) GotenEqual(other interface{}) bool {
   472  	if other == nil {
   473  		return ref == nil
   474  	}
   475  	other1, ok := other.(*Reference)
   476  	if !ok {
   477  		other2, ok := other.(Reference)
   478  		if ok {
   479  			other1 = &other2
   480  		} else {
   481  			return false
   482  		}
   483  	}
   484  	if other1 == nil {
   485  		return ref == nil
   486  	} else if ref == nil {
   487  		return false
   488  	}
   489  
   490  	return ref.Name.GotenEqual(other1.Name)
   491  }
   492  
   493  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   494  func (name *Reference) Matches(other interface{}) bool {
   495  	if other == nil {
   496  		return name == nil
   497  	}
   498  	other1, ok := other.(*Reference)
   499  	if !ok {
   500  		other2, ok := other.(Reference)
   501  		if ok {
   502  			other1 = &other2
   503  		} else {
   504  			return false
   505  		}
   506  	}
   507  	if other1 == nil {
   508  		return name == nil
   509  	} else if name == nil {
   510  		return false
   511  	}
   512  	return name.Name.Matches(&other1.Name)
   513  }
   514  
   515  // implement CustomTypeCliValue method
   516  func (ref *Reference) SetFromCliFlag(raw string) error {
   517  	parsedRef, err := ParseReference(raw)
   518  	if err != nil {
   519  		return err
   520  	}
   521  	*ref = *parsedRef
   522  	return nil
   523  }