github.com/cloudwan/edgelq-sdk@v1.15.4/monitoring/resources/v4/alerting_policy/alerting_policy.pb.access.go (about)

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