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

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