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