github.com/cloudwan/edgelq-sdk@v1.15.4/devices/resources/v1alpha2/provisioning_policy/provisioning_policy.pb.parentname.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 parentRegexPath_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])$")
    56  
    57  type ParentName struct {
    58  	NamePattern
    59  	ProjectId string `firestore:"projectId"`
    60  	RegionId  string `firestore:"regionId"`
    61  }
    62  
    63  func ParseParentName(name string) (*ParentName, error) {
    64  	var matches []string
    65  	if matches = parentRegexPath_Project_Region.FindStringSubmatch(name); matches != nil {
    66  		return NewNameBuilder().
    67  			SetProjectId(matches[1]).
    68  			SetRegionId(matches[2]).
    69  			Parent(), nil
    70  	}
    71  
    72  	return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as ProvisioningPolicy parent name", name)
    73  }
    74  
    75  func MustParseParentName(name string) *ParentName {
    76  	result, err := ParseParentName(name)
    77  	if err != nil {
    78  		panic(err)
    79  	}
    80  	return result
    81  }
    82  
    83  func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error {
    84  	if len(segments) == 2 && segments[0].CollectionLowerJson == "projects" && segments[1].CollectionLowerJson == "regions" {
    85  		name.Pattern = NamePattern_Project_Region
    86  		name.ProjectId = segments[0].Id
    87  		name.RegionId = segments[1].Id
    88  		return nil
    89  	}
    90  	return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form ProvisioningPolicy parent name", segments)
    91  }
    92  
    93  func (name *ParentName) GetProjectName() *project.Name {
    94  	if name == nil {
    95  		return nil
    96  	}
    97  
    98  	switch name.Pattern {
    99  	case NamePattern_Project_Region:
   100  		return project.NewNameBuilder().
   101  			SetId(name.ProjectId).
   102  			Name()
   103  	default:
   104  		return nil
   105  	}
   106  }
   107  
   108  func (name *ParentName) IsSpecified() bool {
   109  	if name == nil || name.Pattern == "" {
   110  		return false
   111  	}
   112  	switch name.Pattern {
   113  	case NamePattern_Project_Region:
   114  		return name.ProjectId != "" && name.RegionId != ""
   115  	}
   116  	return false
   117  }
   118  
   119  func (name *ParentName) IsFullyQualified() bool {
   120  	if name == nil || name.Pattern == "" {
   121  		return false
   122  	}
   123  
   124  	switch name.Pattern {
   125  	case NamePattern_Project_Region:
   126  		return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId && name.RegionId != "" && name.RegionId != gotenresource.WildcardId
   127  	}
   128  
   129  	return false
   130  }
   131  
   132  func (name *ParentName) FullyQualifiedName() (string, error) {
   133  	if !name.IsFullyQualified() {
   134  		return "", status.Errorf(codes.InvalidArgument, "Parent name for ProvisioningPolicy is not fully qualified")
   135  	}
   136  	return fmt.Sprintf("//devices.edgelq.com/%s", name.String()), nil
   137  }
   138  
   139  func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor {
   140  	return descriptor
   141  }
   142  
   143  func (name *ParentName) GetPattern() gotenresource.NamePattern {
   144  	if name == nil {
   145  		return ""
   146  	}
   147  	return name.Pattern
   148  }
   149  
   150  func (name *ParentName) GetIdParts() map[string]string {
   151  	if name != nil {
   152  		return map[string]string{
   153  			"projectId": name.ProjectId,
   154  			"regionId":  name.RegionId,
   155  		}
   156  	}
   157  	return map[string]string{
   158  		"projectId": "",
   159  		"regionId":  "",
   160  	}
   161  }
   162  
   163  func (name *ParentName) GetSegments() gotenresource.NameSegments {
   164  	if name == nil {
   165  		return nil
   166  	}
   167  
   168  	switch name.Pattern {
   169  	case NamePattern_Project_Region:
   170  		return gotenresource.NameSegments{
   171  			gotenresource.NameSegment{
   172  				CollectionLowerJson: "projects",
   173  				Id:                  name.ProjectId,
   174  			},
   175  			gotenresource.NameSegment{
   176  				CollectionLowerJson: "regions",
   177  				Id:                  name.RegionId,
   178  			},
   179  		}
   180  	}
   181  	return nil
   182  }
   183  
   184  func (name *ParentName) GetIParentName() gotenresource.Name {
   185  	return nil
   186  }
   187  
   188  func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name {
   189  	return nil
   190  }
   191  
   192  func (name *ParentName) String() string {
   193  	if name == nil {
   194  		return "<nil>"
   195  	}
   196  
   197  	if valueStr, err := name.ProtoString(); err != nil {
   198  		panic(err)
   199  	} else {
   200  		return valueStr
   201  	}
   202  }
   203  
   204  func (name *ParentName) DescendsFrom(ancestor string) bool {
   205  	if name == nil {
   206  		return false
   207  	}
   208  
   209  	switch name.Pattern {
   210  	case NamePattern_Project_Region:
   211  		return ancestor == "projects" || ancestor == "regions"
   212  	}
   213  
   214  	return false
   215  }
   216  
   217  func (name *ParentName) AsReference() *ParentReference {
   218  	return &ParentReference{ParentName: *name}
   219  }
   220  
   221  func (name *ParentName) AsRawReference() gotenresource.Reference {
   222  	return name.AsReference()
   223  }
   224  
   225  // implement methods required by protobuf-go library for string-struct conversion
   226  
   227  func (name *ParentName) ProtoString() (string, error) {
   228  	if name == nil {
   229  		return "", nil
   230  	}
   231  	switch name.Pattern {
   232  	case NamePattern_Project_Region:
   233  		return "projects/" + name.ProjectId + "/regions/" + name.RegionId, nil
   234  	}
   235  	return "", nil
   236  }
   237  
   238  func (name *ParentName) ParseProtoString(data string) error {
   239  	parsed, err := ParseParentName(data)
   240  	if err != nil {
   241  		return err
   242  	}
   243  	*name = *parsed
   244  	return nil
   245  }
   246  
   247  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   248  func (name *ParentName) GotenEqual(other interface{}) bool {
   249  	if other == nil {
   250  		return name == nil
   251  	}
   252  	other1, ok := other.(*ParentName)
   253  	if !ok {
   254  		other2, ok := other.(ParentName)
   255  		if ok {
   256  			other1 = &other2
   257  		} else {
   258  			return false
   259  		}
   260  	}
   261  	if other1 == nil {
   262  		return name == nil
   263  	} else if name == nil {
   264  		return false
   265  	}
   266  	if name.ProjectId != other1.ProjectId {
   267  		return false
   268  	}
   269  	if name.RegionId != other1.RegionId {
   270  		return false
   271  	}
   272  	if name.Pattern != other1.Pattern {
   273  		return false
   274  	}
   275  
   276  	return true
   277  }
   278  
   279  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   280  func (name *ParentName) Matches(other interface{}) bool {
   281  	if other == nil {
   282  		return name == nil
   283  	}
   284  	other1, ok := other.(*ParentName)
   285  	if !ok {
   286  		other2, ok := other.(ParentName)
   287  		if ok {
   288  			other1 = &other2
   289  		} else {
   290  			return false
   291  		}
   292  	}
   293  	if other1 == nil {
   294  		return name == nil
   295  	} else if name == nil {
   296  		return false
   297  	}
   298  
   299  	if name.Pattern != other1.Pattern {
   300  		return false
   301  	}
   302  	switch name.Pattern {
   303  	case NamePattern_Project_Region:
   304  		if name.ProjectId != other1.ProjectId &&
   305  			name.ProjectId != gotenresource.WildcardId {
   306  			return false
   307  		}
   308  		if name.RegionId != other1.RegionId &&
   309  			name.RegionId != gotenresource.WildcardId {
   310  			return false
   311  		}
   312  	}
   313  
   314  	return true
   315  }
   316  
   317  // implement CustomTypeCliValue method
   318  func (name *ParentName) SetFromCliFlag(raw string) error {
   319  	parsedName, err := ParseParentName(raw)
   320  	if err != nil {
   321  		return err
   322  	}
   323  	*name = *parsedName
   324  	return nil
   325  }
   326  
   327  type ParentReference struct {
   328  	ParentName
   329  	project *project.Project
   330  }
   331  
   332  func MakeParentReference(name *ParentName) (*ParentReference, error) {
   333  	return &ParentReference{
   334  		ParentName: *name,
   335  	}, nil
   336  }
   337  
   338  func ParseParentReference(name string) (*ParentReference, error) {
   339  	parsedName, err := ParseParentName(name)
   340  	if err != nil {
   341  		return nil, err
   342  	}
   343  	return MakeParentReference(parsedName)
   344  }
   345  
   346  func MustParseParentReference(name string) *ParentReference {
   347  	result, err := ParseParentReference(name)
   348  	if err != nil {
   349  		panic(err)
   350  	}
   351  	return result
   352  }
   353  func (ref *ParentReference) GetProjectReference() *project.Reference {
   354  	if ref == nil {
   355  		return nil
   356  	}
   357  
   358  	switch ref.Pattern {
   359  	case NamePattern_Project_Region:
   360  		return project.NewNameBuilder().
   361  			SetId(ref.ProjectId).
   362  			Reference()
   363  	default:
   364  		return nil
   365  	}
   366  }
   367  
   368  func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference {
   369  	if ref == nil {
   370  		return nil
   371  	}
   372  	projectRef := ref.GetProjectReference()
   373  	if projectRef != nil {
   374  		return projectRef
   375  	}
   376  
   377  	return nil
   378  }
   379  
   380  func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error {
   381  	switch typedRes := res.(type) {
   382  	case *project.Project:
   383  		if name := ref.GetProjectName(); name == nil {
   384  			return status.Errorf(codes.InvalidArgument, "cannot set Project as parent of ProvisioningPolicy, because pattern does not match")
   385  		}
   386  		ref.project = typedRes
   387  		return nil
   388  	default:
   389  		return status.Errorf(codes.Internal, "Invalid parent type for ProvisioningPolicy, got %s", reflect.TypeOf(res).Elem().Name())
   390  	}
   391  }
   392  
   393  func (ref *ParentReference) Resolved() bool {
   394  	if name := ref.GetProjectName(); name != nil {
   395  		return ref.project != nil
   396  	}
   397  	return true
   398  }
   399  
   400  func (ref *ParentReference) ClearCached() {
   401  	ref.project = nil
   402  }
   403  
   404  func (ref *ParentReference) GetProject() *project.Project {
   405  	if ref == nil {
   406  		return nil
   407  	}
   408  	return ref.project
   409  }
   410  
   411  func (ref *ParentReference) GetRawResource() gotenresource.Resource {
   412  	if name := ref.ParentName.GetProjectName(); name != nil {
   413  		return ref.project
   414  	}
   415  	return nil
   416  }
   417  
   418  func (ref *ParentReference) IsFullyQualified() bool {
   419  	if ref == nil {
   420  		return false
   421  	}
   422  	return ref.ParentName.IsFullyQualified()
   423  }
   424  
   425  func (ref *ParentReference) IsSpecified() bool {
   426  	if ref == nil {
   427  		return false
   428  	}
   429  	return ref.ParentName.IsSpecified()
   430  }
   431  
   432  func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor {
   433  	return descriptor
   434  }
   435  
   436  func (ref *ParentReference) GetPattern() gotenresource.NamePattern {
   437  	if ref == nil {
   438  		return ""
   439  	}
   440  	return ref.Pattern
   441  }
   442  
   443  func (ref *ParentReference) GetIdParts() map[string]string {
   444  	if ref != nil {
   445  		return ref.ParentName.GetIdParts()
   446  	}
   447  	return map[string]string{
   448  		"projectId": "",
   449  		"regionId":  "",
   450  	}
   451  }
   452  
   453  func (ref *ParentReference) GetSegments() gotenresource.NameSegments {
   454  	if ref != nil {
   455  		return ref.ParentName.GetSegments()
   456  	}
   457  	return nil
   458  }
   459  
   460  func (ref *ParentReference) GetIParentName() gotenresource.Name {
   461  	return nil
   462  }
   463  
   464  func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name {
   465  	return nil
   466  }
   467  
   468  func (ref *ParentReference) String() string {
   469  	if ref == nil {
   470  		return "<nil>"
   471  	}
   472  	return ref.ParentName.String()
   473  }
   474  
   475  // implement methods required by protobuf-go library for string-struct conversion
   476  
   477  func (ref *ParentReference) ProtoString() (string, error) {
   478  	if ref == nil {
   479  		return "", nil
   480  	}
   481  	return ref.ParentName.ProtoString()
   482  }
   483  
   484  func (ref *ParentReference) ParseProtoString(data string) error {
   485  	parsed, err := ParseParentReference(data)
   486  	if err != nil {
   487  		return err
   488  	}
   489  	*ref = *parsed
   490  	return nil
   491  }
   492  
   493  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   494  func (ref *ParentReference) GotenEqual(other interface{}) bool {
   495  	if other == nil {
   496  		return ref == nil
   497  	}
   498  	other1, ok := other.(*ParentReference)
   499  	if !ok {
   500  		other2, ok := other.(ParentReference)
   501  		if ok {
   502  			other1 = &other2
   503  		} else {
   504  			return false
   505  		}
   506  	}
   507  	if other1 == nil {
   508  		return ref == nil
   509  	} else if ref == nil {
   510  		return false
   511  	}
   512  	if ref.project != other1.project {
   513  		return false
   514  	}
   515  
   516  	return ref.ParentName.GotenEqual(other1.ParentName)
   517  }
   518  
   519  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   520  func (name *ParentReference) Matches(other interface{}) bool {
   521  	if other == nil {
   522  		return name == nil
   523  	}
   524  	other1, ok := other.(*ParentReference)
   525  	if !ok {
   526  		other2, ok := other.(ParentReference)
   527  		if ok {
   528  			other1 = &other2
   529  		} else {
   530  			return false
   531  		}
   532  	}
   533  	if other1 == nil {
   534  		return name == nil
   535  	} else if name == nil {
   536  		return false
   537  	}
   538  	return name.ParentName.Matches(&other1.ParentName)
   539  }
   540  
   541  // implement CustomTypeCliValue method
   542  func (ref *ParentReference) SetFromCliFlag(raw string) error {
   543  	parsedRef, err := ParseParentReference(raw)
   544  	if err != nil {
   545  		return err
   546  	}
   547  	*ref = *parsedRef
   548  	return nil
   549  }