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

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: Device
     3  // DO NOT EDIT!!!
     4  
     5  package device
     6  
     7  import (
     8  	"context"
     9  
    10  	"google.golang.org/grpc/codes"
    11  	"google.golang.org/grpc/status"
    12  
    13  	gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
    14  	gotenresource "github.com/cloudwan/goten-sdk/runtime/resource"
    15  	"github.com/cloudwan/goten-sdk/types/watch_type"
    16  )
    17  
    18  // proto imports
    19  import (
    20  	api "github.com/cloudwan/edgelq-sdk/common/api"
    21  	project "github.com/cloudwan/edgelq-sdk/devices/resources/v1/project"
    22  	iam_attestation_domain "github.com/cloudwan/edgelq-sdk/iam/resources/v1/attestation_domain"
    23  	iam_iam_common "github.com/cloudwan/edgelq-sdk/iam/resources/v1/common"
    24  	iam_service_account "github.com/cloudwan/edgelq-sdk/iam/resources/v1/service_account"
    25  	logging_bucket "github.com/cloudwan/edgelq-sdk/logging/resources/v1/bucket"
    26  	monitoring_bucket "github.com/cloudwan/edgelq-sdk/monitoring/resources/v4/bucket"
    27  	meta "github.com/cloudwan/goten-sdk/types/meta"
    28  	latlng "google.golang.org/genproto/googleapis/type/latlng"
    29  	durationpb "google.golang.org/protobuf/types/known/durationpb"
    30  	fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb"
    31  	timestamppb "google.golang.org/protobuf/types/known/timestamppb"
    32  )
    33  
    34  // ensure the imports are used
    35  var (
    36  	_ = new(context.Context)
    37  
    38  	_ = codes.Internal
    39  	_ = status.Status{}
    40  
    41  	_ = watch_type.WatchType_STATEFUL
    42  	_ = new(gotenobject.FieldPath)
    43  	_ = new(gotenresource.ListQuery)
    44  )
    45  
    46  // make sure we're using proto imports
    47  var (
    48  	_ = &api.HealthCheckSpec{}
    49  	_ = &project.Project{}
    50  	_ = &iam_attestation_domain.AttestationDomain{}
    51  	_ = &iam_iam_common.PCR{}
    52  	_ = &iam_service_account.ServiceAccount{}
    53  	_ = &logging_bucket.Bucket{}
    54  	_ = &monitoring_bucket.Bucket{}
    55  	_ = &durationpb.Duration{}
    56  	_ = &fieldmaskpb.FieldMask{}
    57  	_ = &timestamppb.Timestamp{}
    58  	_ = &latlng.LatLng{}
    59  	_ = &meta.Meta{}
    60  )
    61  
    62  type DeviceAccess interface {
    63  	GetDevice(context.Context, *GetQuery, ...gotenresource.GetOption) (*Device, error)
    64  	BatchGetDevices(context.Context, []*Reference, ...gotenresource.BatchGetOption) error
    65  	QueryDevices(context.Context, *ListQuery, ...gotenresource.QueryOption) (*QueryResultSnapshot, error)
    66  	WatchDevice(context.Context, *GetQuery, func(*DeviceChange) error) error
    67  	WatchDevices(context.Context, *WatchQuery, func(*QueryResultChange) error) error
    68  	SaveDevice(context.Context, *Device, ...gotenresource.SaveOption) error
    69  	DeleteDevice(context.Context, *Reference, ...gotenresource.DeleteOption) error
    70  }
    71  
    72  type anyCastAccess struct {
    73  	DeviceAccess
    74  }
    75  
    76  func AsAnyCastAccess(access DeviceAccess) gotenresource.Access {
    77  	return &anyCastAccess{DeviceAccess: access}
    78  }
    79  
    80  func (a *anyCastAccess) Get(ctx context.Context, q gotenresource.GetQuery, opts ...gotenresource.GetOption) (gotenresource.Resource, error) {
    81  	if asDeviceQuery, ok := q.(*GetQuery); ok {
    82  		return a.GetDevice(ctx, asDeviceQuery, opts...)
    83  	}
    84  	return nil, status.Errorf(codes.Internal,
    85  		"Unrecognized descriptor, expected Device, got: %s",
    86  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    87  }
    88  
    89  func (a *anyCastAccess) Query(ctx context.Context, q gotenresource.ListQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    90  	if asDeviceQuery, ok := q.(*ListQuery); ok {
    91  		return a.QueryDevices(ctx, asDeviceQuery, opts...)
    92  	}
    93  	return nil, status.Errorf(codes.Internal,
    94  		"Unrecognized descriptor, expected Device, got: %s",
    95  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    96  }
    97  
    98  func (a *anyCastAccess) Search(ctx context.Context, q gotenresource.SearchQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    99  	return nil, status.Errorf(codes.Internal, "Search is not available for Device")
   100  }
   101  
   102  func (a *anyCastAccess) Watch(ctx context.Context, q gotenresource.GetQuery, cb func(ch gotenresource.ResourceChange) error) error {
   103  	if asDeviceQuery, ok := q.(*GetQuery); ok {
   104  		return a.WatchDevice(ctx, asDeviceQuery, func(change *DeviceChange) error {
   105  			return cb(change)
   106  		})
   107  	}
   108  	return status.Errorf(codes.Internal,
   109  		"Unrecognized descriptor, expected Device, got: %s",
   110  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   111  }
   112  
   113  func (a *anyCastAccess) WatchQuery(ctx context.Context, q gotenresource.WatchQuery, cb func(ch gotenresource.QueryResultChange) error) error {
   114  	if asDeviceQuery, ok := q.(*WatchQuery); ok {
   115  		return a.WatchDevices(ctx, asDeviceQuery, func(change *QueryResultChange) error {
   116  			return cb(change)
   117  		})
   118  	}
   119  	return status.Errorf(codes.Internal,
   120  		"Unrecognized descriptor, expected Device, got: %s",
   121  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   122  }
   123  
   124  func (a *anyCastAccess) Save(ctx context.Context, res gotenresource.Resource, opts ...gotenresource.SaveOption) error {
   125  	if asDeviceRes, ok := res.(*Device); ok {
   126  		return a.SaveDevice(ctx, asDeviceRes, opts...)
   127  	}
   128  	return status.Errorf(codes.Internal,
   129  		"Unrecognized descriptor, expected Device, got: %s",
   130  		res.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   131  }
   132  
   133  func (a *anyCastAccess) Delete(ctx context.Context, ref gotenresource.Reference, opts ...gotenresource.DeleteOption) error {
   134  	if asDeviceRef, ok := ref.(*Reference); ok {
   135  		return a.DeleteDevice(ctx, asDeviceRef, opts...)
   136  	}
   137  	return status.Errorf(codes.Internal,
   138  		"Unrecognized descriptor, expected Device, got: %s",
   139  		ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   140  }
   141  
   142  func (a *anyCastAccess) BatchGet(ctx context.Context, toGet []gotenresource.Reference, opts ...gotenresource.BatchGetOption) error {
   143  	deviceRefs := make([]*Reference, 0, len(toGet))
   144  	for _, ref := range toGet {
   145  		if asDeviceRef, ok := ref.(*Reference); !ok {
   146  			return status.Errorf(codes.Internal,
   147  				"Unrecognized descriptor, expected Device, got: %s",
   148  				ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   149  		} else {
   150  			deviceRefs = append(deviceRefs, asDeviceRef)
   151  		}
   152  	}
   153  	return a.BatchGetDevices(ctx, deviceRefs, opts...)
   154  }
   155  
   156  func (a *anyCastAccess) GetResourceDescriptors() []gotenresource.Descriptor {
   157  	return []gotenresource.Descriptor{
   158  		GetDescriptor(),
   159  	}
   160  }