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

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