service_control.go raw
1 // Code generated by sdkgen-v2. DO NOT EDIT.
2 package iamsdk
3
4 import (
5 "context"
6
7 iam "github.com/yandex-cloud/go-genproto/yandex/cloud/iam/v1"
8 operation "github.com/yandex-cloud/go-genproto/yandex/cloud/operation"
9 sdkop "github.com/yandex-cloud/go-sdk/v2/pkg/operation"
10 "github.com/yandex-cloud/go-sdk/v2/pkg/transport"
11 "google.golang.org/grpc"
12 "google.golang.org/protobuf/reflect/protoreflect"
13 )
14
15 // ServiceControlClient provides methods for managing ServiceControl resources of Yandex.Cloud IAM.
16 type ServiceControlClient interface {
17 Get(context.Context, *iam.GetServiceRequest, ...grpc.CallOption) (*iam.Service, error)
18 List(context.Context, *iam.ListServicesRequest, ...grpc.CallOption) (*iam.ListServicesResponse, error)
19 Enable(context.Context, *iam.EnableServiceRequest, ...grpc.CallOption) (*ServiceControlEnableOperation, error)
20 Disable(context.Context, *iam.DisableServiceRequest, ...grpc.CallOption) (*ServiceControlDisableOperation, error)
21 ResolveAgent(context.Context, *iam.ResolveServiceAgentRequest, ...grpc.CallOption) (*iam.ServiceAgent, error)
22 }
23
24 var _ ServiceControlClient = serviceControlClient{}
25
26 type serviceControlClient struct {
27 connector transport.Connector
28 }
29
30 // NewServiceControlClient returns ServiceControlClient implementation.
31 func NewServiceControlClient(connector transport.Connector) ServiceControlClient {
32 return serviceControlClient{connector}
33 }
34
35 // Get is an operation of Yandex.Cloud IAM ServiceControl service.
36 func (c serviceControlClient) Get(ctx context.Context, in *iam.GetServiceRequest, opts ...grpc.CallOption) (*iam.Service, error) {
37 connection, err := c.connector.GetConnection(ctx, ServiceControlGet, opts...)
38 if err != nil {
39 return nil, err
40 }
41 return iam.NewServiceControlServiceClient(connection).Get(ctx, in, opts...)
42 }
43
44 // List is an operation of Yandex.Cloud IAM ServiceControl service.
45 func (c serviceControlClient) List(ctx context.Context, in *iam.ListServicesRequest, opts ...grpc.CallOption) (*iam.ListServicesResponse, error) {
46 connection, err := c.connector.GetConnection(ctx, ServiceControlList, opts...)
47 if err != nil {
48 return nil, err
49 }
50 return iam.NewServiceControlServiceClient(connection).List(ctx, in, opts...)
51 }
52
53 // ServiceControlEnableOperation is used to monitor the state of Enable operations.
54 type ServiceControlEnableOperation struct {
55 sdkop.Operation
56 }
57
58 // Metadata retrieves the operation metadata.
59 func (o *ServiceControlEnableOperation) Metadata() *iam.EnableServiceMetadata {
60 return o.Operation.Metadata().(*iam.EnableServiceMetadata)
61 }
62
63 // Response retrieves the operation response.
64 func (o *ServiceControlEnableOperation) Response() *iam.Service {
65 return o.Operation.Response().(*iam.Service)
66 }
67
68 // Wait polls the operation until it's done.
69 func (o *ServiceControlEnableOperation) Wait(ctx context.Context, opts ...grpc.CallOption) (*iam.Service, error) {
70 abstract, err := o.Operation.Wait(ctx, opts...)
71 response, _ := abstract.(*iam.Service)
72 return response, err
73 }
74
75 // WaitInterval polls the operation until it's done with custom interval.
76 func (o *ServiceControlEnableOperation) WaitInterval(ctx context.Context, pollInterval sdkop.PollIntervalFunc, opts ...grpc.CallOption) (*iam.Service, error) {
77 abstract, err := o.Operation.WaitInterval(ctx, pollInterval, opts...)
78 response, _ := abstract.(*iam.Service)
79 return response, err
80 }
81
82 // Enable is an operation of Yandex.Cloud IAM ServiceControl service.
83 // It returns an object which should be used to monitor the operation state.
84 func (c serviceControlClient) Enable(ctx context.Context, in *iam.EnableServiceRequest, opts ...grpc.CallOption) (*ServiceControlEnableOperation, error) {
85 connection, err := c.connector.GetConnection(ctx, ServiceControlEnable, opts...)
86 if err != nil {
87 return nil, err
88 }
89 pb, err := iam.NewServiceControlServiceClient(connection).Enable(ctx, in, opts...)
90 if err != nil {
91 return nil, err
92 }
93 op, err := sdkop.NewOperation(pb, &sdkop.Concretization{
94 Poll: c.pollOperation,
95 MetadataType: (*iam.EnableServiceMetadata)(nil),
96 ResponseType: (*iam.Service)(nil),
97 })
98 if err != nil {
99 return nil, err
100 }
101 return &ServiceControlEnableOperation{*op}, nil
102 }
103
104 // ServiceControlDisableOperation is used to monitor the state of Disable operations.
105 type ServiceControlDisableOperation struct {
106 sdkop.Operation
107 }
108
109 // Metadata retrieves the operation metadata.
110 func (o *ServiceControlDisableOperation) Metadata() *iam.DisableServiceMetadata {
111 return o.Operation.Metadata().(*iam.DisableServiceMetadata)
112 }
113
114 // Response retrieves the operation response.
115 func (o *ServiceControlDisableOperation) Response() *iam.Service {
116 return o.Operation.Response().(*iam.Service)
117 }
118
119 // Wait polls the operation until it's done.
120 func (o *ServiceControlDisableOperation) Wait(ctx context.Context, opts ...grpc.CallOption) (*iam.Service, error) {
121 abstract, err := o.Operation.Wait(ctx, opts...)
122 response, _ := abstract.(*iam.Service)
123 return response, err
124 }
125
126 // WaitInterval polls the operation until it's done with custom interval.
127 func (o *ServiceControlDisableOperation) WaitInterval(ctx context.Context, pollInterval sdkop.PollIntervalFunc, opts ...grpc.CallOption) (*iam.Service, error) {
128 abstract, err := o.Operation.WaitInterval(ctx, pollInterval, opts...)
129 response, _ := abstract.(*iam.Service)
130 return response, err
131 }
132
133 // Disable is an operation of Yandex.Cloud IAM ServiceControl service.
134 // It returns an object which should be used to monitor the operation state.
135 func (c serviceControlClient) Disable(ctx context.Context, in *iam.DisableServiceRequest, opts ...grpc.CallOption) (*ServiceControlDisableOperation, error) {
136 connection, err := c.connector.GetConnection(ctx, ServiceControlDisable, opts...)
137 if err != nil {
138 return nil, err
139 }
140 pb, err := iam.NewServiceControlServiceClient(connection).Disable(ctx, in, opts...)
141 if err != nil {
142 return nil, err
143 }
144 op, err := sdkop.NewOperation(pb, &sdkop.Concretization{
145 Poll: c.pollOperation,
146 MetadataType: (*iam.DisableServiceMetadata)(nil),
147 ResponseType: (*iam.Service)(nil),
148 })
149 if err != nil {
150 return nil, err
151 }
152 return &ServiceControlDisableOperation{*op}, nil
153 }
154
155 // ResolveAgent is an operation of Yandex.Cloud IAM ServiceControl service.
156 func (c serviceControlClient) ResolveAgent(ctx context.Context, in *iam.ResolveServiceAgentRequest, opts ...grpc.CallOption) (*iam.ServiceAgent, error) {
157 connection, err := c.connector.GetConnection(ctx, ServiceControlResolveAgent, opts...)
158 if err != nil {
159 return nil, err
160 }
161 return iam.NewServiceControlServiceClient(connection).ResolveAgent(ctx, in, opts...)
162 }
163
164 // pollOperation returns the current state of the polled operation.
165 func (c serviceControlClient) pollOperation(ctx context.Context, operationId string, opts ...grpc.CallOption) (sdkop.YCOperation, error) {
166 connection, err := c.connector.GetConnection(ctx, ServiceControlOperationPoller, opts...)
167 if err != nil {
168 return nil, err
169 }
170 return operation.NewOperationServiceClient(connection).Get(ctx, &operation.GetOperationRequest{OperationId: operationId}, opts...)
171 }
172
173 var (
174 ServiceControlGet = protoreflect.FullName("yandex.cloud.iam.v1.ServiceControlService.Get")
175 ServiceControlList = protoreflect.FullName("yandex.cloud.iam.v1.ServiceControlService.List")
176 ServiceControlEnable = protoreflect.FullName("yandex.cloud.iam.v1.ServiceControlService.Enable")
177 ServiceControlDisable = protoreflect.FullName("yandex.cloud.iam.v1.ServiceControlService.Disable")
178 ServiceControlResolveAgent = protoreflect.FullName("yandex.cloud.iam.v1.ServiceControlService.ResolveAgent")
179 ServiceControlOperationPoller = protoreflect.FullName("yandex.cloud.operation.OperationService.Get")
180 )
181