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

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