github.com/cloudwan/edgelq-sdk@v1.15.4/limits/resources/v1/plan_assignment_request/plan_assignment_request.pb.parentname.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: PlanAssignmentRequest
     3  // DO NOT EDIT!!!
     4  
     5  package plan_assignment_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  	iam_organization "github.com/cloudwan/edgelq-sdk/iam/resources/v1/organization"
    25  	iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project"
    26  	accepted_plan "github.com/cloudwan/edgelq-sdk/limits/resources/v1/accepted_plan"
    27  	common "github.com/cloudwan/edgelq-sdk/limits/resources/v1/common"
    28  	plan "github.com/cloudwan/edgelq-sdk/limits/resources/v1/plan"
    29  	plan_assignment "github.com/cloudwan/edgelq-sdk/limits/resources/v1/plan_assignment"
    30  	meta_service "github.com/cloudwan/goten-sdk/meta-service/resources/v1/service"
    31  	meta "github.com/cloudwan/goten-sdk/types/meta"
    32  )
    33  
    34  // ensure the imports are used
    35  var (
    36  	_ = codes.NotFound
    37  	_ = new(fmt.Stringer)
    38  	_ = new(proto.Message)
    39  	_ = status.Status{}
    40  	_ = url.URL{}
    41  	_ = strings.Builder{}
    42  
    43  	_ = new(goten.GotenMessage)
    44  	_ = new(gotenresource.ListQuery)
    45  )
    46  
    47  // make sure we're using proto imports
    48  var (
    49  	_ = &iam_organization.Organization{}
    50  	_ = &iam_project.Project{}
    51  	_ = &accepted_plan.AcceptedPlan{}
    52  	_ = &common.RegionalPlanAssignment{}
    53  	_ = &plan.Plan{}
    54  	_ = &plan_assignment.PlanAssignment{}
    55  	_ = &meta_service.Service{}
    56  	_ = &meta.Meta{}
    57  )
    58  
    59  var parentRegexPath_Project = regexp.MustCompile("^projects/(?P<project_id>-|[\\w][\\w.-]{0,127})$")
    60  var parentRegexPath_Organization = regexp.MustCompile("^organizations/(?P<organization_id>-|[\\w][\\w.-]{0,127})$")
    61  
    62  type ParentName struct {
    63  	NamePattern
    64  	ProjectId      string `firestore:"projectId"`
    65  	OrganizationId string `firestore:"organizationId"`
    66  }
    67  
    68  func ParseParentName(name string) (*ParentName, error) {
    69  	var matches []string
    70  	if matches = parentRegexPath_Project.FindStringSubmatch(name); matches != nil {
    71  		return NewNameBuilder().
    72  			SetProjectId(matches[1]).
    73  			Parent(), nil
    74  	}
    75  	if matches = parentRegexPath_Organization.FindStringSubmatch(name); matches != nil {
    76  		return NewNameBuilder().
    77  			SetOrganizationId(matches[1]).
    78  			Parent(), nil
    79  	}
    80  
    81  	return nil, status.Errorf(codes.InvalidArgument, "unable to parse '%s' as PlanAssignmentRequest parent name", name)
    82  }
    83  
    84  func MustParseParentName(name string) *ParentName {
    85  	result, err := ParseParentName(name)
    86  	if err != nil {
    87  		panic(err)
    88  	}
    89  	return result
    90  }
    91  
    92  func (name *ParentName) SetFromSegments(segments gotenresource.NameSegments) error {
    93  	if len(segments) == 1 && segments[0].CollectionLowerJson == "projects" {
    94  		name.Pattern = NamePattern_Project
    95  		name.ProjectId = segments[0].Id
    96  		return nil
    97  	} else if len(segments) == 1 && segments[0].CollectionLowerJson == "organizations" {
    98  		name.Pattern = NamePattern_Organization
    99  		name.OrganizationId = segments[0].Id
   100  		return nil
   101  	}
   102  	return status.Errorf(codes.InvalidArgument, "unable to use segments %s to form PlanAssignmentRequest parent name", segments)
   103  }
   104  
   105  func (name *ParentName) GetProjectName() *iam_project.Name {
   106  	if name == nil {
   107  		return nil
   108  	}
   109  
   110  	switch name.Pattern {
   111  	case NamePattern_Project:
   112  		return iam_project.NewNameBuilder().
   113  			SetId(name.ProjectId).
   114  			Name()
   115  	default:
   116  		return nil
   117  	}
   118  }
   119  
   120  func (name *ParentName) GetOrganizationName() *iam_organization.Name {
   121  	if name == nil {
   122  		return nil
   123  	}
   124  
   125  	switch name.Pattern {
   126  	case NamePattern_Organization:
   127  		return iam_organization.NewNameBuilder().
   128  			SetId(name.OrganizationId).
   129  			Name()
   130  	default:
   131  		return nil
   132  	}
   133  }
   134  
   135  func (name *ParentName) IsSpecified() bool {
   136  	if name == nil || name.Pattern == "" {
   137  		return false
   138  	}
   139  	switch name.Pattern {
   140  	case NamePattern_Project:
   141  		return name.ProjectId != ""
   142  	case NamePattern_Organization:
   143  		return name.OrganizationId != ""
   144  	}
   145  	return false
   146  }
   147  
   148  func (name *ParentName) IsFullyQualified() bool {
   149  	if name == nil || name.Pattern == "" {
   150  		return false
   151  	}
   152  
   153  	switch name.Pattern {
   154  	case NamePattern_Project:
   155  		return name.ProjectId != "" && name.ProjectId != gotenresource.WildcardId
   156  	case NamePattern_Organization:
   157  		return name.OrganizationId != "" && name.OrganizationId != gotenresource.WildcardId
   158  	}
   159  
   160  	return false
   161  }
   162  
   163  func (name *ParentName) FullyQualifiedName() (string, error) {
   164  	if !name.IsFullyQualified() {
   165  		return "", status.Errorf(codes.InvalidArgument, "Parent name for PlanAssignmentRequest is not fully qualified")
   166  	}
   167  	return fmt.Sprintf("//limits.edgelq.com/%s", name.String()), nil
   168  }
   169  
   170  func (name *ParentName) GetResourceDescriptor() gotenresource.Descriptor {
   171  	return descriptor
   172  }
   173  
   174  func (name *ParentName) GetPattern() gotenresource.NamePattern {
   175  	if name == nil {
   176  		return ""
   177  	}
   178  	return name.Pattern
   179  }
   180  
   181  func (name *ParentName) GetIdParts() map[string]string {
   182  	if name != nil {
   183  		return map[string]string{
   184  			"projectId":      name.ProjectId,
   185  			"organizationId": name.OrganizationId,
   186  		}
   187  	}
   188  	return map[string]string{
   189  		"projectId":      "",
   190  		"organizationId": "",
   191  	}
   192  }
   193  
   194  func (name *ParentName) GetSegments() gotenresource.NameSegments {
   195  	if name == nil {
   196  		return nil
   197  	}
   198  
   199  	switch name.Pattern {
   200  	case NamePattern_Project:
   201  		return gotenresource.NameSegments{
   202  			gotenresource.NameSegment{
   203  				CollectionLowerJson: "projects",
   204  				Id:                  name.ProjectId,
   205  			},
   206  		}
   207  	case NamePattern_Organization:
   208  		return gotenresource.NameSegments{
   209  			gotenresource.NameSegment{
   210  				CollectionLowerJson: "organizations",
   211  				Id:                  name.OrganizationId,
   212  			},
   213  		}
   214  	}
   215  	return nil
   216  }
   217  
   218  func (name *ParentName) GetIParentName() gotenresource.Name {
   219  	return nil
   220  }
   221  
   222  func (name *ParentName) GetIUnderlyingParentName() gotenresource.Name {
   223  	return nil
   224  }
   225  
   226  func (name *ParentName) String() string {
   227  	if name == nil {
   228  		return "<nil>"
   229  	}
   230  
   231  	if valueStr, err := name.ProtoString(); err != nil {
   232  		panic(err)
   233  	} else {
   234  		return valueStr
   235  	}
   236  }
   237  
   238  func (name *ParentName) DescendsFrom(ancestor string) bool {
   239  	if name == nil {
   240  		return false
   241  	}
   242  
   243  	switch name.Pattern {
   244  	case NamePattern_Project:
   245  		return ancestor == "projects"
   246  	case NamePattern_Organization:
   247  		return ancestor == "organizations"
   248  	}
   249  
   250  	return false
   251  }
   252  
   253  func (name *ParentName) AsReference() *ParentReference {
   254  	return &ParentReference{ParentName: *name}
   255  }
   256  
   257  func (name *ParentName) AsRawReference() gotenresource.Reference {
   258  	return name.AsReference()
   259  }
   260  
   261  // implement methods required by protobuf-go library for string-struct conversion
   262  
   263  func (name *ParentName) ProtoString() (string, error) {
   264  	if name == nil {
   265  		return "", nil
   266  	}
   267  	switch name.Pattern {
   268  	case NamePattern_Project:
   269  		return "projects/" + name.ProjectId, nil
   270  	case NamePattern_Organization:
   271  		return "organizations/" + name.OrganizationId, nil
   272  	}
   273  	return "", nil
   274  }
   275  
   276  func (name *ParentName) ParseProtoString(data string) error {
   277  	parsed, err := ParseParentName(data)
   278  	if err != nil {
   279  		return err
   280  	}
   281  	*name = *parsed
   282  	return nil
   283  }
   284  
   285  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   286  func (name *ParentName) GotenEqual(other interface{}) bool {
   287  	if other == nil {
   288  		return name == nil
   289  	}
   290  	other1, ok := other.(*ParentName)
   291  	if !ok {
   292  		other2, ok := other.(ParentName)
   293  		if ok {
   294  			other1 = &other2
   295  		} else {
   296  			return false
   297  		}
   298  	}
   299  	if other1 == nil {
   300  		return name == nil
   301  	} else if name == nil {
   302  		return false
   303  	}
   304  	if name.ProjectId != other1.ProjectId {
   305  		return false
   306  	}
   307  	if name.OrganizationId != other1.OrganizationId {
   308  		return false
   309  	}
   310  	if name.Pattern != other1.Pattern {
   311  		return false
   312  	}
   313  
   314  	return true
   315  }
   316  
   317  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   318  func (name *ParentName) Matches(other interface{}) bool {
   319  	if other == nil {
   320  		return name == nil
   321  	}
   322  	other1, ok := other.(*ParentName)
   323  	if !ok {
   324  		other2, ok := other.(ParentName)
   325  		if ok {
   326  			other1 = &other2
   327  		} else {
   328  			return false
   329  		}
   330  	}
   331  	if other1 == nil {
   332  		return name == nil
   333  	} else if name == nil {
   334  		return false
   335  	}
   336  
   337  	if name.Pattern != other1.Pattern {
   338  		return false
   339  	}
   340  	switch name.Pattern {
   341  	case NamePattern_Project:
   342  		if name.ProjectId != other1.ProjectId &&
   343  			name.ProjectId != gotenresource.WildcardId {
   344  			return false
   345  		}
   346  	case NamePattern_Organization:
   347  		if name.OrganizationId != other1.OrganizationId &&
   348  			name.OrganizationId != gotenresource.WildcardId {
   349  			return false
   350  		}
   351  	}
   352  
   353  	return true
   354  }
   355  
   356  // implement CustomTypeCliValue method
   357  func (name *ParentName) SetFromCliFlag(raw string) error {
   358  	parsedName, err := ParseParentName(raw)
   359  	if err != nil {
   360  		return err
   361  	}
   362  	*name = *parsedName
   363  	return nil
   364  }
   365  
   366  type ParentReference struct {
   367  	ParentName
   368  	project      *iam_project.Project
   369  	organization *iam_organization.Organization
   370  }
   371  
   372  func MakeParentReference(name *ParentName) (*ParentReference, error) {
   373  	return &ParentReference{
   374  		ParentName: *name,
   375  	}, nil
   376  }
   377  
   378  func ParseParentReference(name string) (*ParentReference, error) {
   379  	parsedName, err := ParseParentName(name)
   380  	if err != nil {
   381  		return nil, err
   382  	}
   383  	return MakeParentReference(parsedName)
   384  }
   385  
   386  func MustParseParentReference(name string) *ParentReference {
   387  	result, err := ParseParentReference(name)
   388  	if err != nil {
   389  		panic(err)
   390  	}
   391  	return result
   392  }
   393  func (ref *ParentReference) GetProjectReference() *iam_project.Reference {
   394  	if ref == nil {
   395  		return nil
   396  	}
   397  
   398  	switch ref.Pattern {
   399  	case NamePattern_Project:
   400  		return iam_project.NewNameBuilder().
   401  			SetId(ref.ProjectId).
   402  			Reference()
   403  	default:
   404  		return nil
   405  	}
   406  }
   407  func (ref *ParentReference) GetOrganizationReference() *iam_organization.Reference {
   408  	if ref == nil {
   409  		return nil
   410  	}
   411  
   412  	switch ref.Pattern {
   413  	case NamePattern_Organization:
   414  		return iam_organization.NewNameBuilder().
   415  			SetId(ref.OrganizationId).
   416  			Reference()
   417  	default:
   418  		return nil
   419  	}
   420  }
   421  
   422  func (ref *ParentReference) GetUnderlyingReference() gotenresource.Reference {
   423  	if ref == nil {
   424  		return nil
   425  	}
   426  	projectRef := ref.GetProjectReference()
   427  	if projectRef != nil {
   428  		return projectRef
   429  	}
   430  	organizationRef := ref.GetOrganizationReference()
   431  	if organizationRef != nil {
   432  		return organizationRef
   433  	}
   434  
   435  	return nil
   436  }
   437  
   438  func (ref *ParentReference) ResolveRaw(res gotenresource.Resource) error {
   439  	switch typedRes := res.(type) {
   440  	case *iam_project.Project:
   441  		if name := ref.GetProjectName(); name == nil {
   442  			return status.Errorf(codes.InvalidArgument, "cannot set Project as parent of PlanAssignmentRequest, because pattern does not match")
   443  		}
   444  		ref.project = typedRes
   445  		return nil
   446  	case *iam_organization.Organization:
   447  		if name := ref.GetOrganizationName(); name == nil {
   448  			return status.Errorf(codes.InvalidArgument, "cannot set Organization as parent of PlanAssignmentRequest, because pattern does not match")
   449  		}
   450  		ref.organization = typedRes
   451  		return nil
   452  	default:
   453  		return status.Errorf(codes.Internal, "Invalid parent type for PlanAssignmentRequest, got %s", reflect.TypeOf(res).Elem().Name())
   454  	}
   455  }
   456  
   457  func (ref *ParentReference) Resolved() bool {
   458  	if name := ref.GetProjectName(); name != nil {
   459  		return ref.project != nil
   460  	}
   461  	if name := ref.GetOrganizationName(); name != nil {
   462  		return ref.organization != nil
   463  	}
   464  	return true
   465  }
   466  
   467  func (ref *ParentReference) ClearCached() {
   468  	ref.project = nil
   469  	ref.organization = nil
   470  }
   471  
   472  func (ref *ParentReference) GetProject() *iam_project.Project {
   473  	if ref == nil {
   474  		return nil
   475  	}
   476  	return ref.project
   477  }
   478  func (ref *ParentReference) GetOrganization() *iam_organization.Organization {
   479  	if ref == nil {
   480  		return nil
   481  	}
   482  	return ref.organization
   483  }
   484  
   485  func (ref *ParentReference) GetRawResource() gotenresource.Resource {
   486  	if name := ref.ParentName.GetProjectName(); name != nil {
   487  		return ref.project
   488  	}
   489  	if name := ref.ParentName.GetOrganizationName(); name != nil {
   490  		return ref.organization
   491  	}
   492  	return nil
   493  }
   494  
   495  func (ref *ParentReference) IsFullyQualified() bool {
   496  	if ref == nil {
   497  		return false
   498  	}
   499  	return ref.ParentName.IsFullyQualified()
   500  }
   501  
   502  func (ref *ParentReference) IsSpecified() bool {
   503  	if ref == nil {
   504  		return false
   505  	}
   506  	return ref.ParentName.IsSpecified()
   507  }
   508  
   509  func (ref *ParentReference) GetResourceDescriptor() gotenresource.Descriptor {
   510  	return descriptor
   511  }
   512  
   513  func (ref *ParentReference) GetPattern() gotenresource.NamePattern {
   514  	if ref == nil {
   515  		return ""
   516  	}
   517  	return ref.Pattern
   518  }
   519  
   520  func (ref *ParentReference) GetIdParts() map[string]string {
   521  	if ref != nil {
   522  		return ref.ParentName.GetIdParts()
   523  	}
   524  	return map[string]string{
   525  		"projectId":      "",
   526  		"organizationId": "",
   527  	}
   528  }
   529  
   530  func (ref *ParentReference) GetSegments() gotenresource.NameSegments {
   531  	if ref != nil {
   532  		return ref.ParentName.GetSegments()
   533  	}
   534  	return nil
   535  }
   536  
   537  func (ref *ParentReference) GetIParentName() gotenresource.Name {
   538  	return nil
   539  }
   540  
   541  func (ref *ParentReference) GetIUnderlyingParentName() gotenresource.Name {
   542  	return nil
   543  }
   544  
   545  func (ref *ParentReference) String() string {
   546  	if ref == nil {
   547  		return "<nil>"
   548  	}
   549  	return ref.ParentName.String()
   550  }
   551  
   552  // implement methods required by protobuf-go library for string-struct conversion
   553  
   554  func (ref *ParentReference) ProtoString() (string, error) {
   555  	if ref == nil {
   556  		return "", nil
   557  	}
   558  	return ref.ParentName.ProtoString()
   559  }
   560  
   561  func (ref *ParentReference) ParseProtoString(data string) error {
   562  	parsed, err := ParseParentReference(data)
   563  	if err != nil {
   564  		return err
   565  	}
   566  	*ref = *parsed
   567  	return nil
   568  }
   569  
   570  // GotenEqual returns true if other is of same type and paths are equal (implements goten.Equaler interface)
   571  func (ref *ParentReference) GotenEqual(other interface{}) bool {
   572  	if other == nil {
   573  		return ref == nil
   574  	}
   575  	other1, ok := other.(*ParentReference)
   576  	if !ok {
   577  		other2, ok := other.(ParentReference)
   578  		if ok {
   579  			other1 = &other2
   580  		} else {
   581  			return false
   582  		}
   583  	}
   584  	if other1 == nil {
   585  		return ref == nil
   586  	} else if ref == nil {
   587  		return false
   588  	}
   589  	if ref.project != other1.project {
   590  		return false
   591  	}
   592  	if ref.organization != other1.organization {
   593  		return false
   594  	}
   595  
   596  	return ref.ParentName.GotenEqual(other1.ParentName)
   597  }
   598  
   599  // Matches is same as GotenEqual, but also will accept "other" if name is wildcard.
   600  func (name *ParentReference) Matches(other interface{}) bool {
   601  	if other == nil {
   602  		return name == nil
   603  	}
   604  	other1, ok := other.(*ParentReference)
   605  	if !ok {
   606  		other2, ok := other.(ParentReference)
   607  		if ok {
   608  			other1 = &other2
   609  		} else {
   610  			return false
   611  		}
   612  	}
   613  	if other1 == nil {
   614  		return name == nil
   615  	} else if name == nil {
   616  		return false
   617  	}
   618  	return name.ParentName.Matches(&other1.ParentName)
   619  }
   620  
   621  // implement CustomTypeCliValue method
   622  func (ref *ParentReference) SetFromCliFlag(raw string) error {
   623  	parsedRef, err := ParseParentReference(raw)
   624  	if err != nil {
   625  		return err
   626  	}
   627  	*ref = *parsedRef
   628  	return nil
   629  }