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

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