You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

634 lines
26 KiB

  1. // Copyright 2019 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Code generated by gapic-generator. DO NOT EDIT.
  15. package iot
  16. import (
  17. "context"
  18. "fmt"
  19. "math"
  20. "time"
  21. "github.com/golang/protobuf/proto"
  22. gax "github.com/googleapis/gax-go/v2"
  23. "google.golang.org/api/iterator"
  24. "google.golang.org/api/option"
  25. "google.golang.org/api/transport"
  26. iotpb "google.golang.org/genproto/googleapis/cloud/iot/v1"
  27. iampb "google.golang.org/genproto/googleapis/iam/v1"
  28. "google.golang.org/grpc"
  29. "google.golang.org/grpc/codes"
  30. "google.golang.org/grpc/metadata"
  31. )
  32. // DeviceManagerCallOptions contains the retry settings for each method of DeviceManagerClient.
  33. type DeviceManagerCallOptions struct {
  34. CreateDeviceRegistry []gax.CallOption
  35. GetDeviceRegistry []gax.CallOption
  36. UpdateDeviceRegistry []gax.CallOption
  37. DeleteDeviceRegistry []gax.CallOption
  38. ListDeviceRegistries []gax.CallOption
  39. CreateDevice []gax.CallOption
  40. GetDevice []gax.CallOption
  41. UpdateDevice []gax.CallOption
  42. DeleteDevice []gax.CallOption
  43. ListDevices []gax.CallOption
  44. ModifyCloudToDeviceConfig []gax.CallOption
  45. ListDeviceConfigVersions []gax.CallOption
  46. ListDeviceStates []gax.CallOption
  47. SetIamPolicy []gax.CallOption
  48. GetIamPolicy []gax.CallOption
  49. TestIamPermissions []gax.CallOption
  50. SendCommandToDevice []gax.CallOption
  51. BindDeviceToGateway []gax.CallOption
  52. UnbindDeviceFromGateway []gax.CallOption
  53. }
  54. func defaultDeviceManagerClientOptions() []option.ClientOption {
  55. return []option.ClientOption{
  56. option.WithEndpoint("cloudiot.googleapis.com:443"),
  57. option.WithScopes(DefaultAuthScopes()...),
  58. }
  59. }
  60. func defaultDeviceManagerCallOptions() *DeviceManagerCallOptions {
  61. retry := map[[2]string][]gax.CallOption{
  62. {"default", "idempotent"}: {
  63. gax.WithRetry(func() gax.Retryer {
  64. return gax.OnCodes([]codes.Code{
  65. codes.DeadlineExceeded,
  66. codes.Unavailable,
  67. }, gax.Backoff{
  68. Initial: 100 * time.Millisecond,
  69. Max: 60000 * time.Millisecond,
  70. Multiplier: 1.3,
  71. })
  72. }),
  73. },
  74. {"rate_limited_aware", "rate_limited_aware"}: {
  75. gax.WithRetry(func() gax.Retryer {
  76. return gax.OnCodes([]codes.Code{
  77. codes.DeadlineExceeded,
  78. codes.ResourceExhausted,
  79. codes.Unavailable,
  80. }, gax.Backoff{
  81. Initial: 1000 * time.Millisecond,
  82. Max: 60000 * time.Millisecond,
  83. Multiplier: 1.3,
  84. })
  85. }),
  86. },
  87. }
  88. return &DeviceManagerCallOptions{
  89. CreateDeviceRegistry: retry[[2]string{"default", "non_idempotent"}],
  90. GetDeviceRegistry: retry[[2]string{"default", "idempotent"}],
  91. UpdateDeviceRegistry: retry[[2]string{"default", "non_idempotent"}],
  92. DeleteDeviceRegistry: retry[[2]string{"default", "idempotent"}],
  93. ListDeviceRegistries: retry[[2]string{"default", "idempotent"}],
  94. CreateDevice: retry[[2]string{"default", "non_idempotent"}],
  95. GetDevice: retry[[2]string{"default", "idempotent"}],
  96. UpdateDevice: retry[[2]string{"default", "non_idempotent"}],
  97. DeleteDevice: retry[[2]string{"default", "idempotent"}],
  98. ListDevices: retry[[2]string{"default", "idempotent"}],
  99. ModifyCloudToDeviceConfig: retry[[2]string{"rate_limited_aware", "rate_limited_aware"}],
  100. ListDeviceConfigVersions: retry[[2]string{"default", "idempotent"}],
  101. ListDeviceStates: retry[[2]string{"default", "idempotent"}],
  102. SetIamPolicy: retry[[2]string{"default", "non_idempotent"}],
  103. GetIamPolicy: retry[[2]string{"default", "non_idempotent"}],
  104. TestIamPermissions: retry[[2]string{"default", "non_idempotent"}],
  105. SendCommandToDevice: retry[[2]string{"rate_limited_aware", "rate_limited_aware"}],
  106. BindDeviceToGateway: retry[[2]string{"default", "non_idempotent"}],
  107. UnbindDeviceFromGateway: retry[[2]string{"default", "non_idempotent"}],
  108. }
  109. }
  110. // DeviceManagerClient is a client for interacting with Cloud IoT API.
  111. //
  112. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  113. type DeviceManagerClient struct {
  114. // The connection to the service.
  115. conn *grpc.ClientConn
  116. // The gRPC API client.
  117. deviceManagerClient iotpb.DeviceManagerClient
  118. // The call options for this service.
  119. CallOptions *DeviceManagerCallOptions
  120. // The x-goog-* metadata to be sent with each request.
  121. xGoogMetadata metadata.MD
  122. }
  123. // NewDeviceManagerClient creates a new device manager client.
  124. //
  125. // Internet of Things (IoT) service. Securely connect and manage IoT devices.
  126. func NewDeviceManagerClient(ctx context.Context, opts ...option.ClientOption) (*DeviceManagerClient, error) {
  127. conn, err := transport.DialGRPC(ctx, append(defaultDeviceManagerClientOptions(), opts...)...)
  128. if err != nil {
  129. return nil, err
  130. }
  131. c := &DeviceManagerClient{
  132. conn: conn,
  133. CallOptions: defaultDeviceManagerCallOptions(),
  134. deviceManagerClient: iotpb.NewDeviceManagerClient(conn),
  135. }
  136. c.setGoogleClientInfo()
  137. return c, nil
  138. }
  139. // Connection returns the client's connection to the API service.
  140. func (c *DeviceManagerClient) Connection() *grpc.ClientConn {
  141. return c.conn
  142. }
  143. // Close closes the connection to the API service. The user should invoke this when
  144. // the client is no longer required.
  145. func (c *DeviceManagerClient) Close() error {
  146. return c.conn.Close()
  147. }
  148. // setGoogleClientInfo sets the name and version of the application in
  149. // the `x-goog-api-client` header passed on each request. Intended for
  150. // use by Google-written clients.
  151. func (c *DeviceManagerClient) setGoogleClientInfo(keyval ...string) {
  152. kv := append([]string{"gl-go", versionGo()}, keyval...)
  153. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  154. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  155. }
  156. // CreateDeviceRegistry creates a device registry that contains devices.
  157. func (c *DeviceManagerClient) CreateDeviceRegistry(ctx context.Context, req *iotpb.CreateDeviceRegistryRequest, opts ...gax.CallOption) (*iotpb.DeviceRegistry, error) {
  158. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
  159. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  160. opts = append(c.CallOptions.CreateDeviceRegistry[0:len(c.CallOptions.CreateDeviceRegistry):len(c.CallOptions.CreateDeviceRegistry)], opts...)
  161. var resp *iotpb.DeviceRegistry
  162. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  163. var err error
  164. resp, err = c.deviceManagerClient.CreateDeviceRegistry(ctx, req, settings.GRPC...)
  165. return err
  166. }, opts...)
  167. if err != nil {
  168. return nil, err
  169. }
  170. return resp, nil
  171. }
  172. // GetDeviceRegistry gets a device registry configuration.
  173. func (c *DeviceManagerClient) GetDeviceRegistry(ctx context.Context, req *iotpb.GetDeviceRegistryRequest, opts ...gax.CallOption) (*iotpb.DeviceRegistry, error) {
  174. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  175. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  176. opts = append(c.CallOptions.GetDeviceRegistry[0:len(c.CallOptions.GetDeviceRegistry):len(c.CallOptions.GetDeviceRegistry)], opts...)
  177. var resp *iotpb.DeviceRegistry
  178. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  179. var err error
  180. resp, err = c.deviceManagerClient.GetDeviceRegistry(ctx, req, settings.GRPC...)
  181. return err
  182. }, opts...)
  183. if err != nil {
  184. return nil, err
  185. }
  186. return resp, nil
  187. }
  188. // UpdateDeviceRegistry updates a device registry configuration.
  189. func (c *DeviceManagerClient) UpdateDeviceRegistry(ctx context.Context, req *iotpb.UpdateDeviceRegistryRequest, opts ...gax.CallOption) (*iotpb.DeviceRegistry, error) {
  190. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "device_registry.name", req.GetDeviceRegistry().GetName()))
  191. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  192. opts = append(c.CallOptions.UpdateDeviceRegistry[0:len(c.CallOptions.UpdateDeviceRegistry):len(c.CallOptions.UpdateDeviceRegistry)], opts...)
  193. var resp *iotpb.DeviceRegistry
  194. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  195. var err error
  196. resp, err = c.deviceManagerClient.UpdateDeviceRegistry(ctx, req, settings.GRPC...)
  197. return err
  198. }, opts...)
  199. if err != nil {
  200. return nil, err
  201. }
  202. return resp, nil
  203. }
  204. // DeleteDeviceRegistry deletes a device registry configuration.
  205. func (c *DeviceManagerClient) DeleteDeviceRegistry(ctx context.Context, req *iotpb.DeleteDeviceRegistryRequest, opts ...gax.CallOption) error {
  206. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  207. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  208. opts = append(c.CallOptions.DeleteDeviceRegistry[0:len(c.CallOptions.DeleteDeviceRegistry):len(c.CallOptions.DeleteDeviceRegistry)], opts...)
  209. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  210. var err error
  211. _, err = c.deviceManagerClient.DeleteDeviceRegistry(ctx, req, settings.GRPC...)
  212. return err
  213. }, opts...)
  214. return err
  215. }
  216. // ListDeviceRegistries lists device registries.
  217. func (c *DeviceManagerClient) ListDeviceRegistries(ctx context.Context, req *iotpb.ListDeviceRegistriesRequest, opts ...gax.CallOption) *DeviceRegistryIterator {
  218. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
  219. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  220. opts = append(c.CallOptions.ListDeviceRegistries[0:len(c.CallOptions.ListDeviceRegistries):len(c.CallOptions.ListDeviceRegistries)], opts...)
  221. it := &DeviceRegistryIterator{}
  222. req = proto.Clone(req).(*iotpb.ListDeviceRegistriesRequest)
  223. it.InternalFetch = func(pageSize int, pageToken string) ([]*iotpb.DeviceRegistry, string, error) {
  224. var resp *iotpb.ListDeviceRegistriesResponse
  225. req.PageToken = pageToken
  226. if pageSize > math.MaxInt32 {
  227. req.PageSize = math.MaxInt32
  228. } else {
  229. req.PageSize = int32(pageSize)
  230. }
  231. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  232. var err error
  233. resp, err = c.deviceManagerClient.ListDeviceRegistries(ctx, req, settings.GRPC...)
  234. return err
  235. }, opts...)
  236. if err != nil {
  237. return nil, "", err
  238. }
  239. return resp.DeviceRegistries, resp.NextPageToken, nil
  240. }
  241. fetch := func(pageSize int, pageToken string) (string, error) {
  242. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  243. if err != nil {
  244. return "", err
  245. }
  246. it.items = append(it.items, items...)
  247. return nextPageToken, nil
  248. }
  249. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  250. it.pageInfo.MaxSize = int(req.PageSize)
  251. return it
  252. }
  253. // CreateDevice creates a device in a device registry.
  254. func (c *DeviceManagerClient) CreateDevice(ctx context.Context, req *iotpb.CreateDeviceRequest, opts ...gax.CallOption) (*iotpb.Device, error) {
  255. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
  256. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  257. opts = append(c.CallOptions.CreateDevice[0:len(c.CallOptions.CreateDevice):len(c.CallOptions.CreateDevice)], opts...)
  258. var resp *iotpb.Device
  259. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  260. var err error
  261. resp, err = c.deviceManagerClient.CreateDevice(ctx, req, settings.GRPC...)
  262. return err
  263. }, opts...)
  264. if err != nil {
  265. return nil, err
  266. }
  267. return resp, nil
  268. }
  269. // GetDevice gets details about a device.
  270. func (c *DeviceManagerClient) GetDevice(ctx context.Context, req *iotpb.GetDeviceRequest, opts ...gax.CallOption) (*iotpb.Device, error) {
  271. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  272. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  273. opts = append(c.CallOptions.GetDevice[0:len(c.CallOptions.GetDevice):len(c.CallOptions.GetDevice)], opts...)
  274. var resp *iotpb.Device
  275. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  276. var err error
  277. resp, err = c.deviceManagerClient.GetDevice(ctx, req, settings.GRPC...)
  278. return err
  279. }, opts...)
  280. if err != nil {
  281. return nil, err
  282. }
  283. return resp, nil
  284. }
  285. // UpdateDevice updates a device.
  286. func (c *DeviceManagerClient) UpdateDevice(ctx context.Context, req *iotpb.UpdateDeviceRequest, opts ...gax.CallOption) (*iotpb.Device, error) {
  287. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "device.name", req.GetDevice().GetName()))
  288. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  289. opts = append(c.CallOptions.UpdateDevice[0:len(c.CallOptions.UpdateDevice):len(c.CallOptions.UpdateDevice)], opts...)
  290. var resp *iotpb.Device
  291. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  292. var err error
  293. resp, err = c.deviceManagerClient.UpdateDevice(ctx, req, settings.GRPC...)
  294. return err
  295. }, opts...)
  296. if err != nil {
  297. return nil, err
  298. }
  299. return resp, nil
  300. }
  301. // DeleteDevice deletes a device.
  302. func (c *DeviceManagerClient) DeleteDevice(ctx context.Context, req *iotpb.DeleteDeviceRequest, opts ...gax.CallOption) error {
  303. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  304. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  305. opts = append(c.CallOptions.DeleteDevice[0:len(c.CallOptions.DeleteDevice):len(c.CallOptions.DeleteDevice)], opts...)
  306. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  307. var err error
  308. _, err = c.deviceManagerClient.DeleteDevice(ctx, req, settings.GRPC...)
  309. return err
  310. }, opts...)
  311. return err
  312. }
  313. // ListDevices list devices in a device registry.
  314. func (c *DeviceManagerClient) ListDevices(ctx context.Context, req *iotpb.ListDevicesRequest, opts ...gax.CallOption) *DeviceIterator {
  315. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
  316. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  317. opts = append(c.CallOptions.ListDevices[0:len(c.CallOptions.ListDevices):len(c.CallOptions.ListDevices)], opts...)
  318. it := &DeviceIterator{}
  319. req = proto.Clone(req).(*iotpb.ListDevicesRequest)
  320. it.InternalFetch = func(pageSize int, pageToken string) ([]*iotpb.Device, string, error) {
  321. var resp *iotpb.ListDevicesResponse
  322. req.PageToken = pageToken
  323. if pageSize > math.MaxInt32 {
  324. req.PageSize = math.MaxInt32
  325. } else {
  326. req.PageSize = int32(pageSize)
  327. }
  328. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  329. var err error
  330. resp, err = c.deviceManagerClient.ListDevices(ctx, req, settings.GRPC...)
  331. return err
  332. }, opts...)
  333. if err != nil {
  334. return nil, "", err
  335. }
  336. return resp.Devices, resp.NextPageToken, nil
  337. }
  338. fetch := func(pageSize int, pageToken string) (string, error) {
  339. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  340. if err != nil {
  341. return "", err
  342. }
  343. it.items = append(it.items, items...)
  344. return nextPageToken, nil
  345. }
  346. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  347. it.pageInfo.MaxSize = int(req.PageSize)
  348. return it
  349. }
  350. // ModifyCloudToDeviceConfig modifies the configuration for the device, which is eventually sent from
  351. // the Cloud IoT Core servers. Returns the modified configuration version and
  352. // its metadata.
  353. func (c *DeviceManagerClient) ModifyCloudToDeviceConfig(ctx context.Context, req *iotpb.ModifyCloudToDeviceConfigRequest, opts ...gax.CallOption) (*iotpb.DeviceConfig, error) {
  354. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  355. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  356. opts = append(c.CallOptions.ModifyCloudToDeviceConfig[0:len(c.CallOptions.ModifyCloudToDeviceConfig):len(c.CallOptions.ModifyCloudToDeviceConfig)], opts...)
  357. var resp *iotpb.DeviceConfig
  358. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  359. var err error
  360. resp, err = c.deviceManagerClient.ModifyCloudToDeviceConfig(ctx, req, settings.GRPC...)
  361. return err
  362. }, opts...)
  363. if err != nil {
  364. return nil, err
  365. }
  366. return resp, nil
  367. }
  368. // ListDeviceConfigVersions lists the last few versions of the device configuration in descending
  369. // order (i.e.: newest first).
  370. func (c *DeviceManagerClient) ListDeviceConfigVersions(ctx context.Context, req *iotpb.ListDeviceConfigVersionsRequest, opts ...gax.CallOption) (*iotpb.ListDeviceConfigVersionsResponse, error) {
  371. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  372. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  373. opts = append(c.CallOptions.ListDeviceConfigVersions[0:len(c.CallOptions.ListDeviceConfigVersions):len(c.CallOptions.ListDeviceConfigVersions)], opts...)
  374. var resp *iotpb.ListDeviceConfigVersionsResponse
  375. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  376. var err error
  377. resp, err = c.deviceManagerClient.ListDeviceConfigVersions(ctx, req, settings.GRPC...)
  378. return err
  379. }, opts...)
  380. if err != nil {
  381. return nil, err
  382. }
  383. return resp, nil
  384. }
  385. // ListDeviceStates lists the last few versions of the device state in descending order (i.e.:
  386. // newest first).
  387. func (c *DeviceManagerClient) ListDeviceStates(ctx context.Context, req *iotpb.ListDeviceStatesRequest, opts ...gax.CallOption) (*iotpb.ListDeviceStatesResponse, error) {
  388. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  389. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  390. opts = append(c.CallOptions.ListDeviceStates[0:len(c.CallOptions.ListDeviceStates):len(c.CallOptions.ListDeviceStates)], opts...)
  391. var resp *iotpb.ListDeviceStatesResponse
  392. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  393. var err error
  394. resp, err = c.deviceManagerClient.ListDeviceStates(ctx, req, settings.GRPC...)
  395. return err
  396. }, opts...)
  397. if err != nil {
  398. return nil, err
  399. }
  400. return resp, nil
  401. }
  402. // SetIamPolicy sets the access control policy on the specified resource. Replaces any
  403. // existing policy.
  404. func (c *DeviceManagerClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  405. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", req.GetResource()))
  406. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  407. opts = append(c.CallOptions.SetIamPolicy[0:len(c.CallOptions.SetIamPolicy):len(c.CallOptions.SetIamPolicy)], opts...)
  408. var resp *iampb.Policy
  409. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  410. var err error
  411. resp, err = c.deviceManagerClient.SetIamPolicy(ctx, req, settings.GRPC...)
  412. return err
  413. }, opts...)
  414. if err != nil {
  415. return nil, err
  416. }
  417. return resp, nil
  418. }
  419. // GetIamPolicy gets the access control policy for a resource.
  420. // Returns an empty policy if the resource exists and does not have a policy
  421. // set.
  422. func (c *DeviceManagerClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
  423. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", req.GetResource()))
  424. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  425. opts = append(c.CallOptions.GetIamPolicy[0:len(c.CallOptions.GetIamPolicy):len(c.CallOptions.GetIamPolicy)], opts...)
  426. var resp *iampb.Policy
  427. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  428. var err error
  429. resp, err = c.deviceManagerClient.GetIamPolicy(ctx, req, settings.GRPC...)
  430. return err
  431. }, opts...)
  432. if err != nil {
  433. return nil, err
  434. }
  435. return resp, nil
  436. }
  437. // TestIamPermissions returns permissions that a caller has on the specified resource.
  438. // If the resource does not exist, this will return an empty set of
  439. // permissions, not a NOT_FOUND error.
  440. func (c *DeviceManagerClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
  441. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", req.GetResource()))
  442. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  443. opts = append(c.CallOptions.TestIamPermissions[0:len(c.CallOptions.TestIamPermissions):len(c.CallOptions.TestIamPermissions)], opts...)
  444. var resp *iampb.TestIamPermissionsResponse
  445. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  446. var err error
  447. resp, err = c.deviceManagerClient.TestIamPermissions(ctx, req, settings.GRPC...)
  448. return err
  449. }, opts...)
  450. if err != nil {
  451. return nil, err
  452. }
  453. return resp, nil
  454. }
  455. // SendCommandToDevice sends a command to the specified device. In order for a device to be able
  456. // to receive commands, it must:
  457. // 1) be connected to Cloud IoT Core using the MQTT protocol, and
  458. // 2) be subscribed to the group of MQTT topics specified by
  459. // /devices/{device-id}/commands/#. This subscription will receive commands
  460. // at the top-level topic /devices/{device-id}/commands as well as commands
  461. // for subfolders, like /devices/{device-id}/commands/subfolder.
  462. // Note that subscribing to specific subfolders is not supported.
  463. // If the command could not be delivered to the device, this method will
  464. // return an error; in particular, if the device is not subscribed, this
  465. // method will return FAILED_PRECONDITION. Otherwise, this method will
  466. // return OK. If the subscription is QoS 1, at least once delivery will be
  467. // guaranteed; for QoS 0, no acknowledgment will be expected from the device.
  468. func (c *DeviceManagerClient) SendCommandToDevice(ctx context.Context, req *iotpb.SendCommandToDeviceRequest, opts ...gax.CallOption) (*iotpb.SendCommandToDeviceResponse, error) {
  469. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName()))
  470. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  471. opts = append(c.CallOptions.SendCommandToDevice[0:len(c.CallOptions.SendCommandToDevice):len(c.CallOptions.SendCommandToDevice)], opts...)
  472. var resp *iotpb.SendCommandToDeviceResponse
  473. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  474. var err error
  475. resp, err = c.deviceManagerClient.SendCommandToDevice(ctx, req, settings.GRPC...)
  476. return err
  477. }, opts...)
  478. if err != nil {
  479. return nil, err
  480. }
  481. return resp, nil
  482. }
  483. // BindDeviceToGateway associates the device with the gateway.
  484. func (c *DeviceManagerClient) BindDeviceToGateway(ctx context.Context, req *iotpb.BindDeviceToGatewayRequest, opts ...gax.CallOption) (*iotpb.BindDeviceToGatewayResponse, error) {
  485. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
  486. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  487. opts = append(c.CallOptions.BindDeviceToGateway[0:len(c.CallOptions.BindDeviceToGateway):len(c.CallOptions.BindDeviceToGateway)], opts...)
  488. var resp *iotpb.BindDeviceToGatewayResponse
  489. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  490. var err error
  491. resp, err = c.deviceManagerClient.BindDeviceToGateway(ctx, req, settings.GRPC...)
  492. return err
  493. }, opts...)
  494. if err != nil {
  495. return nil, err
  496. }
  497. return resp, nil
  498. }
  499. // UnbindDeviceFromGateway deletes the association between the device and the gateway.
  500. func (c *DeviceManagerClient) UnbindDeviceFromGateway(ctx context.Context, req *iotpb.UnbindDeviceFromGatewayRequest, opts ...gax.CallOption) (*iotpb.UnbindDeviceFromGatewayResponse, error) {
  501. md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent()))
  502. ctx = insertMetadata(ctx, c.xGoogMetadata, md)
  503. opts = append(c.CallOptions.UnbindDeviceFromGateway[0:len(c.CallOptions.UnbindDeviceFromGateway):len(c.CallOptions.UnbindDeviceFromGateway)], opts...)
  504. var resp *iotpb.UnbindDeviceFromGatewayResponse
  505. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  506. var err error
  507. resp, err = c.deviceManagerClient.UnbindDeviceFromGateway(ctx, req, settings.GRPC...)
  508. return err
  509. }, opts...)
  510. if err != nil {
  511. return nil, err
  512. }
  513. return resp, nil
  514. }
  515. // DeviceIterator manages a stream of *iotpb.Device.
  516. type DeviceIterator struct {
  517. items []*iotpb.Device
  518. pageInfo *iterator.PageInfo
  519. nextFunc func() error
  520. // InternalFetch is for use by the Google Cloud Libraries only.
  521. // It is not part of the stable interface of this package.
  522. //
  523. // InternalFetch returns results from a single call to the underlying RPC.
  524. // The number of results is no greater than pageSize.
  525. // If there are no more results, nextPageToken is empty and err is nil.
  526. InternalFetch func(pageSize int, pageToken string) (results []*iotpb.Device, nextPageToken string, err error)
  527. }
  528. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  529. func (it *DeviceIterator) PageInfo() *iterator.PageInfo {
  530. return it.pageInfo
  531. }
  532. // Next returns the next result. Its second return value is iterator.Done if there are no more
  533. // results. Once Next returns Done, all subsequent calls will return Done.
  534. func (it *DeviceIterator) Next() (*iotpb.Device, error) {
  535. var item *iotpb.Device
  536. if err := it.nextFunc(); err != nil {
  537. return item, err
  538. }
  539. item = it.items[0]
  540. it.items = it.items[1:]
  541. return item, nil
  542. }
  543. func (it *DeviceIterator) bufLen() int {
  544. return len(it.items)
  545. }
  546. func (it *DeviceIterator) takeBuf() interface{} {
  547. b := it.items
  548. it.items = nil
  549. return b
  550. }
  551. // DeviceRegistryIterator manages a stream of *iotpb.DeviceRegistry.
  552. type DeviceRegistryIterator struct {
  553. items []*iotpb.DeviceRegistry
  554. pageInfo *iterator.PageInfo
  555. nextFunc func() error
  556. // InternalFetch is for use by the Google Cloud Libraries only.
  557. // It is not part of the stable interface of this package.
  558. //
  559. // InternalFetch returns results from a single call to the underlying RPC.
  560. // The number of results is no greater than pageSize.
  561. // If there are no more results, nextPageToken is empty and err is nil.
  562. InternalFetch func(pageSize int, pageToken string) (results []*iotpb.DeviceRegistry, nextPageToken string, err error)
  563. }
  564. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  565. func (it *DeviceRegistryIterator) PageInfo() *iterator.PageInfo {
  566. return it.pageInfo
  567. }
  568. // Next returns the next result. Its second return value is iterator.Done if there are no more
  569. // results. Once Next returns Done, all subsequent calls will return Done.
  570. func (it *DeviceRegistryIterator) Next() (*iotpb.DeviceRegistry, error) {
  571. var item *iotpb.DeviceRegistry
  572. if err := it.nextFunc(); err != nil {
  573. return item, err
  574. }
  575. item = it.items[0]
  576. it.items = it.items[1:]
  577. return item, nil
  578. }
  579. func (it *DeviceRegistryIterator) bufLen() int {
  580. return len(it.items)
  581. }
  582. func (it *DeviceRegistryIterator) takeBuf() interface{} {
  583. b := it.items
  584. it.items = nil
  585. return b
  586. }