github.com/cloudwan/edgelq-sdk@v1.15.4/limits/resources/v1alpha2/plan/plan.pb.access.go (about)

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: Plan
     3  // DO NOT EDIT!!!
     4  
     5  package plan
     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  	iam_iam_common "github.com/cloudwan/edgelq-sdk/iam/resources/v1alpha2/common"
    21  	common "github.com/cloudwan/edgelq-sdk/limits/resources/v1alpha2/common"
    22  	meta_service "github.com/cloudwan/edgelq-sdk/meta/resources/v1alpha2/service"
    23  	meta "github.com/cloudwan/goten-sdk/types/meta"
    24  )
    25  
    26  // ensure the imports are used
    27  var (
    28  	_ = new(context.Context)
    29  
    30  	_ = codes.Internal
    31  	_ = status.Status{}
    32  
    33  	_ = watch_type.WatchType_STATEFUL
    34  	_ = new(gotenobject.FieldPath)
    35  	_ = new(gotenresource.ListQuery)
    36  )
    37  
    38  // make sure we're using proto imports
    39  var (
    40  	_ = &iam_iam_common.PCR{}
    41  	_ = &common.Allowance{}
    42  	_ = &meta_service.Service{}
    43  	_ = &meta.Meta{}
    44  )
    45  
    46  type PlanAccess interface {
    47  	GetPlan(context.Context, *GetQuery, ...gotenresource.GetOption) (*Plan, error)
    48  	BatchGetPlans(context.Context, []*Reference, ...gotenresource.BatchGetOption) error
    49  	QueryPlans(context.Context, *ListQuery, ...gotenresource.QueryOption) (*QueryResultSnapshot, error)
    50  	WatchPlan(context.Context, *GetQuery, func(*PlanChange) error) error
    51  	WatchPlans(context.Context, *WatchQuery, func(*QueryResultChange) error) error
    52  	SavePlan(context.Context, *Plan, ...gotenresource.SaveOption) error
    53  	DeletePlan(context.Context, *Reference, ...gotenresource.DeleteOption) error
    54  }
    55  
    56  type anyCastAccess struct {
    57  	PlanAccess
    58  }
    59  
    60  func AsAnyCastAccess(access PlanAccess) gotenresource.Access {
    61  	return &anyCastAccess{PlanAccess: access}
    62  }
    63  
    64  func (a *anyCastAccess) Get(ctx context.Context, q gotenresource.GetQuery, opts ...gotenresource.GetOption) (gotenresource.Resource, error) {
    65  	if asPlanQuery, ok := q.(*GetQuery); ok {
    66  		return a.GetPlan(ctx, asPlanQuery, opts...)
    67  	}
    68  	return nil, status.Errorf(codes.Internal,
    69  		"Unrecognized descriptor, expected Plan, got: %s",
    70  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    71  }
    72  
    73  func (a *anyCastAccess) Query(ctx context.Context, q gotenresource.ListQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    74  	if asPlanQuery, ok := q.(*ListQuery); ok {
    75  		return a.QueryPlans(ctx, asPlanQuery, opts...)
    76  	}
    77  	return nil, status.Errorf(codes.Internal,
    78  		"Unrecognized descriptor, expected Plan, got: %s",
    79  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    80  }
    81  
    82  func (a *anyCastAccess) Search(ctx context.Context, q gotenresource.SearchQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    83  	return nil, status.Errorf(codes.Internal, "Search is not available for Plan")
    84  }
    85  
    86  func (a *anyCastAccess) Watch(ctx context.Context, q gotenresource.GetQuery, cb func(ch gotenresource.ResourceChange) error) error {
    87  	if asPlanQuery, ok := q.(*GetQuery); ok {
    88  		return a.WatchPlan(ctx, asPlanQuery, func(change *PlanChange) error {
    89  			return cb(change)
    90  		})
    91  	}
    92  	return status.Errorf(codes.Internal,
    93  		"Unrecognized descriptor, expected Plan, got: %s",
    94  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    95  }
    96  
    97  func (a *anyCastAccess) WatchQuery(ctx context.Context, q gotenresource.WatchQuery, cb func(ch gotenresource.QueryResultChange) error) error {
    98  	if asPlanQuery, ok := q.(*WatchQuery); ok {
    99  		return a.WatchPlans(ctx, asPlanQuery, func(change *QueryResultChange) error {
   100  			return cb(change)
   101  		})
   102  	}
   103  	return status.Errorf(codes.Internal,
   104  		"Unrecognized descriptor, expected Plan, got: %s",
   105  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   106  }
   107  
   108  func (a *anyCastAccess) Save(ctx context.Context, res gotenresource.Resource, opts ...gotenresource.SaveOption) error {
   109  	if asPlanRes, ok := res.(*Plan); ok {
   110  		return a.SavePlan(ctx, asPlanRes, opts...)
   111  	}
   112  	return status.Errorf(codes.Internal,
   113  		"Unrecognized descriptor, expected Plan, got: %s",
   114  		res.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   115  }
   116  
   117  func (a *anyCastAccess) Delete(ctx context.Context, ref gotenresource.Reference, opts ...gotenresource.DeleteOption) error {
   118  	if asPlanRef, ok := ref.(*Reference); ok {
   119  		return a.DeletePlan(ctx, asPlanRef, opts...)
   120  	}
   121  	return status.Errorf(codes.Internal,
   122  		"Unrecognized descriptor, expected Plan, got: %s",
   123  		ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   124  }
   125  
   126  func (a *anyCastAccess) BatchGet(ctx context.Context, toGet []gotenresource.Reference, opts ...gotenresource.BatchGetOption) error {
   127  	planRefs := make([]*Reference, 0, len(toGet))
   128  	for _, ref := range toGet {
   129  		if asPlanRef, ok := ref.(*Reference); !ok {
   130  			return status.Errorf(codes.Internal,
   131  				"Unrecognized descriptor, expected Plan, got: %s",
   132  				ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   133  		} else {
   134  			planRefs = append(planRefs, asPlanRef)
   135  		}
   136  	}
   137  	return a.BatchGetPlans(ctx, planRefs, opts...)
   138  }
   139  
   140  func (a *anyCastAccess) GetResourceDescriptors() []gotenresource.Descriptor {
   141  	return []gotenresource.Descriptor{
   142  		GetDescriptor(),
   143  	}
   144  }