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

     1  // Code generated by protoc-gen-goten-resource
     2  // Resource: Policy
     3  // DO NOT EDIT!!!
     4  
     5  package policy
     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  	rcommon "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/common"
    21  	document "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/document"
    22  	notification_channel "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/notification_channel"
    23  	policy_template "github.com/cloudwan/edgelq-sdk/alerting/resources/v1/policy_template"
    24  	iam_project "github.com/cloudwan/edgelq-sdk/iam/resources/v1/project"
    25  	meta "github.com/cloudwan/goten-sdk/types/meta"
    26  	fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb"
    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  	_ = &document.Document{}
    44  	_ = &notification_channel.NotificationChannel{}
    45  	_ = &policy_template.PolicyTemplate{}
    46  	_ = &rcommon.LogCndSpec{}
    47  	_ = &iam_project.Project{}
    48  	_ = &fieldmaskpb.FieldMask{}
    49  	_ = &meta.Meta{}
    50  )
    51  
    52  type PolicyAccess interface {
    53  	GetPolicy(context.Context, *GetQuery, ...gotenresource.GetOption) (*Policy, error)
    54  	BatchGetPolicies(context.Context, []*Reference, ...gotenresource.BatchGetOption) error
    55  	QueryPolicies(context.Context, *ListQuery, ...gotenresource.QueryOption) (*QueryResultSnapshot, error)
    56  	SearchPolicies(context.Context, *SearchQuery, ...gotenresource.QueryOption) (*QueryResultSnapshot, error)
    57  	WatchPolicy(context.Context, *GetQuery, func(*PolicyChange) error) error
    58  	WatchPolicies(context.Context, *WatchQuery, func(*QueryResultChange) error) error
    59  	SavePolicy(context.Context, *Policy, ...gotenresource.SaveOption) error
    60  	DeletePolicy(context.Context, *Reference, ...gotenresource.DeleteOption) error
    61  }
    62  
    63  type anyCastAccess struct {
    64  	PolicyAccess
    65  }
    66  
    67  func AsAnyCastAccess(access PolicyAccess) gotenresource.Access {
    68  	return &anyCastAccess{PolicyAccess: access}
    69  }
    70  
    71  func (a *anyCastAccess) Get(ctx context.Context, q gotenresource.GetQuery, opts ...gotenresource.GetOption) (gotenresource.Resource, error) {
    72  	if asPolicyQuery, ok := q.(*GetQuery); ok {
    73  		return a.GetPolicy(ctx, asPolicyQuery, opts...)
    74  	}
    75  	return nil, status.Errorf(codes.Internal,
    76  		"Unrecognized descriptor, expected Policy, got: %s",
    77  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    78  }
    79  
    80  func (a *anyCastAccess) Query(ctx context.Context, q gotenresource.ListQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    81  	if asPolicyQuery, ok := q.(*ListQuery); ok {
    82  		return a.QueryPolicies(ctx, asPolicyQuery, opts...)
    83  	}
    84  	return nil, status.Errorf(codes.Internal,
    85  		"Unrecognized descriptor, expected Policy, got: %s",
    86  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    87  }
    88  
    89  func (a *anyCastAccess) Search(ctx context.Context, q gotenresource.SearchQuery, opts ...gotenresource.QueryOption) (gotenresource.QueryResultSnapshot, error) {
    90  	if asPolicyQuery, ok := q.(*SearchQuery); ok {
    91  		return a.SearchPolicies(ctx, asPolicyQuery, opts...)
    92  	}
    93  	return nil, status.Errorf(codes.Internal,
    94  		"Unrecognized descriptor, expected Policy, got: %s",
    95  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
    96  }
    97  
    98  func (a *anyCastAccess) Watch(ctx context.Context, q gotenresource.GetQuery, cb func(ch gotenresource.ResourceChange) error) error {
    99  	if asPolicyQuery, ok := q.(*GetQuery); ok {
   100  		return a.WatchPolicy(ctx, asPolicyQuery, func(change *PolicyChange) error {
   101  			return cb(change)
   102  		})
   103  	}
   104  	return status.Errorf(codes.Internal,
   105  		"Unrecognized descriptor, expected Policy, got: %s",
   106  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   107  }
   108  
   109  func (a *anyCastAccess) WatchQuery(ctx context.Context, q gotenresource.WatchQuery, cb func(ch gotenresource.QueryResultChange) error) error {
   110  	if asPolicyQuery, ok := q.(*WatchQuery); ok {
   111  		return a.WatchPolicies(ctx, asPolicyQuery, func(change *QueryResultChange) error {
   112  			return cb(change)
   113  		})
   114  	}
   115  	return status.Errorf(codes.Internal,
   116  		"Unrecognized descriptor, expected Policy, got: %s",
   117  		q.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   118  }
   119  
   120  func (a *anyCastAccess) Save(ctx context.Context, res gotenresource.Resource, opts ...gotenresource.SaveOption) error {
   121  	if asPolicyRes, ok := res.(*Policy); ok {
   122  		return a.SavePolicy(ctx, asPolicyRes, opts...)
   123  	}
   124  	return status.Errorf(codes.Internal,
   125  		"Unrecognized descriptor, expected Policy, got: %s",
   126  		res.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   127  }
   128  
   129  func (a *anyCastAccess) Delete(ctx context.Context, ref gotenresource.Reference, opts ...gotenresource.DeleteOption) error {
   130  	if asPolicyRef, ok := ref.(*Reference); ok {
   131  		return a.DeletePolicy(ctx, asPolicyRef, opts...)
   132  	}
   133  	return status.Errorf(codes.Internal,
   134  		"Unrecognized descriptor, expected Policy, got: %s",
   135  		ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   136  }
   137  
   138  func (a *anyCastAccess) BatchGet(ctx context.Context, toGet []gotenresource.Reference, opts ...gotenresource.BatchGetOption) error {
   139  	policyRefs := make([]*Reference, 0, len(toGet))
   140  	for _, ref := range toGet {
   141  		if asPolicyRef, ok := ref.(*Reference); !ok {
   142  			return status.Errorf(codes.Internal,
   143  				"Unrecognized descriptor, expected Policy, got: %s",
   144  				ref.GetResourceDescriptor().GetResourceTypeName().FullyQualifiedTypeName())
   145  		} else {
   146  			policyRefs = append(policyRefs, asPolicyRef)
   147  		}
   148  	}
   149  	return a.BatchGetPolicies(ctx, policyRefs, opts...)
   150  }
   151  
   152  func (a *anyCastAccess) GetResourceDescriptors() []gotenresource.Descriptor {
   153  	return []gotenresource.Descriptor{
   154  		GetDescriptor(),
   155  	}
   156  }