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

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