github.com/cloudwan/edgelq-sdk@v1.15.4/secrets/resources/v1alpha2/secret/secret.pb.parentname.go (about)

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