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

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