resources.proto 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. // Copyright 2020 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. // http://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. syntax = "proto3";
  15. package google.cloud.iot.v1;
  16. import "google/api/resource.proto";
  17. import "google/protobuf/timestamp.proto";
  18. import "google/rpc/status.proto";
  19. option cc_enable_arenas = true;
  20. option go_package = "google.golang.org/genproto/googleapis/cloud/iot/v1;iot";
  21. option java_multiple_files = true;
  22. option java_outer_classname = "ResourcesProto";
  23. option java_package = "com.google.cloud.iot.v1";
  24. // The device resource.
  25. message Device {
  26. option (google.api.resource) = {
  27. type: "cloudiot.googleapis.com/Device"
  28. pattern: "projects/{project}/locations/{location}/registries/{registry}/devices/{device}"
  29. };
  30. // The user-defined device identifier. The device ID must be unique
  31. // within a device registry.
  32. string id = 1;
  33. // The resource path name. For example,
  34. // `projects/p1/locations/us-central1/registries/registry0/devices/dev0` or
  35. // `projects/p1/locations/us-central1/registries/registry0/devices/{num_id}`.
  36. // When `name` is populated as a response from the service, it always ends
  37. // in the device numeric ID.
  38. string name = 2;
  39. // [Output only] A server-defined unique numeric ID for the device. This is a
  40. // more compact way to identify devices, and it is globally unique.
  41. uint64 num_id = 3;
  42. // The credentials used to authenticate this device. To allow credential
  43. // rotation without interruption, multiple device credentials can be bound to
  44. // this device. No more than 3 credentials can be bound to a single device at
  45. // a time. When new credentials are added to a device, they are verified
  46. // against the registry credentials. For details, see the description of the
  47. // `DeviceRegistry.credentials` field.
  48. repeated DeviceCredential credentials = 12;
  49. // [Output only] The last time an MQTT `PINGREQ` was received. This field
  50. // applies only to devices connecting through MQTT. MQTT clients usually only
  51. // send `PINGREQ` messages if the connection is idle, and no other messages
  52. // have been sent. Timestamps are periodically collected and written to
  53. // storage; they may be stale by a few minutes.
  54. google.protobuf.Timestamp last_heartbeat_time = 7;
  55. // [Output only] The last time a telemetry event was received. Timestamps are
  56. // periodically collected and written to storage; they may be stale by a few
  57. // minutes.
  58. google.protobuf.Timestamp last_event_time = 8;
  59. // [Output only] The last time a state event was received. Timestamps are
  60. // periodically collected and written to storage; they may be stale by a few
  61. // minutes.
  62. google.protobuf.Timestamp last_state_time = 20;
  63. // [Output only] The last time a cloud-to-device config version acknowledgment
  64. // was received from the device. This field is only for configurations
  65. // sent through MQTT.
  66. google.protobuf.Timestamp last_config_ack_time = 14;
  67. // [Output only] The last time a cloud-to-device config version was sent to
  68. // the device.
  69. google.protobuf.Timestamp last_config_send_time = 18;
  70. // If a device is blocked, connections or requests from this device will fail.
  71. // Can be used to temporarily prevent the device from connecting if, for
  72. // example, the sensor is generating bad data and needs maintenance.
  73. bool blocked = 19;
  74. // [Output only] The time the most recent error occurred, such as a failure to
  75. // publish to Cloud Pub/Sub. This field is the timestamp of
  76. // 'last_error_status'.
  77. google.protobuf.Timestamp last_error_time = 10;
  78. // [Output only] The error message of the most recent error, such as a failure
  79. // to publish to Cloud Pub/Sub. 'last_error_time' is the timestamp of this
  80. // field. If no errors have occurred, this field has an empty message
  81. // and the status code 0 == OK. Otherwise, this field is expected to have a
  82. // status code other than OK.
  83. google.rpc.Status last_error_status = 11;
  84. // The most recent device configuration, which is eventually sent from
  85. // Cloud IoT Core to the device. If not present on creation, the
  86. // configuration will be initialized with an empty payload and version value
  87. // of `1`. To update this field after creation, use the
  88. // `DeviceManager.ModifyCloudToDeviceConfig` method.
  89. DeviceConfig config = 13;
  90. // [Output only] The state most recently received from the device. If no state
  91. // has been reported, this field is not present.
  92. DeviceState state = 16;
  93. // **Beta Feature**
  94. //
  95. // The logging verbosity for device activity. If unspecified,
  96. // DeviceRegistry.log_level will be used.
  97. LogLevel log_level = 21;
  98. // The metadata key-value pairs assigned to the device. This metadata is not
  99. // interpreted or indexed by Cloud IoT Core. It can be used to add contextual
  100. // information for the device.
  101. //
  102. // Keys must conform to the regular expression [a-zA-Z][a-zA-Z0-9-_.+~%]+ and
  103. // be less than 128 bytes in length.
  104. //
  105. // Values are free-form strings. Each value must be less than or equal to 32
  106. // KB in size.
  107. //
  108. // The total size of all keys and values must be less than 256 KB, and the
  109. // maximum number of key-value pairs is 500.
  110. map<string, string> metadata = 17;
  111. // Gateway-related configuration and state.
  112. GatewayConfig gateway_config = 24;
  113. }
  114. // Gateway-related configuration and state.
  115. message GatewayConfig {
  116. // Indicates whether the device is a gateway.
  117. GatewayType gateway_type = 1;
  118. // Indicates how to authorize and/or authenticate devices to access the
  119. // gateway.
  120. GatewayAuthMethod gateway_auth_method = 2;
  121. // [Output only] The ID of the gateway the device accessed most recently.
  122. string last_accessed_gateway_id = 3;
  123. // [Output only] The most recent time at which the device accessed the gateway
  124. // specified in `last_accessed_gateway`.
  125. google.protobuf.Timestamp last_accessed_gateway_time = 4;
  126. }
  127. // A container for a group of devices.
  128. message DeviceRegistry {
  129. option (google.api.resource) = {
  130. type: "cloudiot.googleapis.com/Registry"
  131. pattern: "projects/{project}/locations/{location}/registries/{registry}"
  132. };
  133. // The identifier of this device registry. For example, `myRegistry`.
  134. string id = 1;
  135. // The resource path name. For example,
  136. // `projects/example-project/locations/us-central1/registries/my-registry`.
  137. string name = 2;
  138. // The configuration for notification of telemetry events received from the
  139. // device. All telemetry events that were successfully published by the
  140. // device and acknowledged by Cloud IoT Core are guaranteed to be
  141. // delivered to Cloud Pub/Sub. If multiple configurations match a message,
  142. // only the first matching configuration is used. If you try to publish a
  143. // device telemetry event using MQTT without specifying a Cloud Pub/Sub topic
  144. // for the device's registry, the connection closes automatically. If you try
  145. // to do so using an HTTP connection, an error is returned. Up to 10
  146. // configurations may be provided.
  147. repeated EventNotificationConfig event_notification_configs = 10;
  148. // The configuration for notification of new states received from the device.
  149. // State updates are guaranteed to be stored in the state history, but
  150. // notifications to Cloud Pub/Sub are not guaranteed. For example, if
  151. // permissions are misconfigured or the specified topic doesn't exist, no
  152. // notification will be published but the state will still be stored in Cloud
  153. // IoT Core.
  154. StateNotificationConfig state_notification_config = 7;
  155. // The MQTT configuration for this device registry.
  156. MqttConfig mqtt_config = 4;
  157. // The DeviceService (HTTP) configuration for this device registry.
  158. HttpConfig http_config = 9;
  159. // **Beta Feature**
  160. //
  161. // The default logging verbosity for activity from devices in this registry.
  162. // The verbosity level can be overridden by Device.log_level.
  163. LogLevel log_level = 11;
  164. // The credentials used to verify the device credentials. No more than 10
  165. // credentials can be bound to a single registry at a time. The verification
  166. // process occurs at the time of device creation or update. If this field is
  167. // empty, no verification is performed. Otherwise, the credentials of a newly
  168. // created device or added credentials of an updated device should be signed
  169. // with one of these registry credentials.
  170. //
  171. // Note, however, that existing devices will never be affected by
  172. // modifications to this list of credentials: after a device has been
  173. // successfully created in a registry, it should be able to connect even if
  174. // its registry credentials are revoked, deleted, or modified.
  175. repeated RegistryCredential credentials = 8;
  176. }
  177. // The configuration of MQTT for a device registry.
  178. message MqttConfig {
  179. // If enabled, allows connections using the MQTT protocol. Otherwise, MQTT
  180. // connections to this registry will fail.
  181. MqttState mqtt_enabled_state = 1;
  182. }
  183. // Indicates whether an MQTT connection is enabled or disabled. See the field
  184. // description for details.
  185. enum MqttState {
  186. // No MQTT state specified. If not specified, MQTT will be enabled by default.
  187. MQTT_STATE_UNSPECIFIED = 0;
  188. // Enables a MQTT connection.
  189. MQTT_ENABLED = 1;
  190. // Disables a MQTT connection.
  191. MQTT_DISABLED = 2;
  192. }
  193. // The configuration of the HTTP bridge for a device registry.
  194. message HttpConfig {
  195. // If enabled, allows devices to use DeviceService via the HTTP protocol.
  196. // Otherwise, any requests to DeviceService will fail for this registry.
  197. HttpState http_enabled_state = 1;
  198. }
  199. // Indicates whether DeviceService (HTTP) is enabled or disabled for the
  200. // registry. See the field description for details.
  201. enum HttpState {
  202. // No HTTP state specified. If not specified, DeviceService will be
  203. // enabled by default.
  204. HTTP_STATE_UNSPECIFIED = 0;
  205. // Enables DeviceService (HTTP) service for the registry.
  206. HTTP_ENABLED = 1;
  207. // Disables DeviceService (HTTP) service for the registry.
  208. HTTP_DISABLED = 2;
  209. }
  210. // **Beta Feature**
  211. //
  212. // The logging verbosity for device activity. Specifies which events should be
  213. // written to logs. For example, if the LogLevel is ERROR, only events that
  214. // terminate in errors will be logged. LogLevel is inclusive; enabling INFO
  215. // logging will also enable ERROR logging.
  216. enum LogLevel {
  217. // No logging specified. If not specified, logging will be disabled.
  218. LOG_LEVEL_UNSPECIFIED = 0;
  219. // Disables logging.
  220. NONE = 10;
  221. // Error events will be logged.
  222. ERROR = 20;
  223. // Informational events will be logged, such as connections and
  224. // disconnections.
  225. INFO = 30;
  226. // All events will be logged.
  227. DEBUG = 40;
  228. }
  229. // Gateway type.
  230. enum GatewayType {
  231. // If unspecified, the device is considered a non-gateway device.
  232. GATEWAY_TYPE_UNSPECIFIED = 0;
  233. // The device is a gateway.
  234. GATEWAY = 1;
  235. // The device is not a gateway.
  236. NON_GATEWAY = 2;
  237. }
  238. // The gateway authorization/authentication method. This setting determines how
  239. // Cloud IoT Core authorizes/authenticate devices to access the gateway.
  240. enum GatewayAuthMethod {
  241. // No authentication/authorization method specified. No devices are allowed to
  242. // access the gateway.
  243. GATEWAY_AUTH_METHOD_UNSPECIFIED = 0;
  244. // The device is authenticated through the gateway association only. Device
  245. // credentials are ignored even if provided.
  246. ASSOCIATION_ONLY = 1;
  247. // The device is authenticated through its own credentials. Gateway
  248. // association is not checked.
  249. DEVICE_AUTH_TOKEN_ONLY = 2;
  250. // The device is authenticated through both device credentials and gateway
  251. // association. The device must be bound to the gateway and must provide its
  252. // own credentials.
  253. ASSOCIATION_AND_DEVICE_AUTH_TOKEN = 3;
  254. }
  255. // The configuration for forwarding telemetry events.
  256. message EventNotificationConfig {
  257. // If the subfolder name matches this string exactly, this configuration will
  258. // be used. The string must not include the leading '/' character. If empty,
  259. // all strings are matched. This field is used only for telemetry events;
  260. // subfolders are not supported for state changes.
  261. string subfolder_matches = 2;
  262. // A Cloud Pub/Sub topic name. For example,
  263. // `projects/myProject/topics/deviceEvents`.
  264. string pubsub_topic_name = 1;
  265. }
  266. // The configuration for notification of new states received from the device.
  267. message StateNotificationConfig {
  268. // A Cloud Pub/Sub topic name. For example,
  269. // `projects/myProject/topics/deviceEvents`.
  270. string pubsub_topic_name = 1;
  271. }
  272. // A server-stored registry credential used to validate device credentials.
  273. message RegistryCredential {
  274. // The credential data. Reserved for expansion in the future.
  275. oneof credential {
  276. // A public key certificate used to verify the device credentials.
  277. PublicKeyCertificate public_key_certificate = 1;
  278. }
  279. }
  280. // Details of an X.509 certificate. For informational purposes only.
  281. message X509CertificateDetails {
  282. // The entity that signed the certificate.
  283. string issuer = 1;
  284. // The entity the certificate and public key belong to.
  285. string subject = 2;
  286. // The time the certificate becomes valid.
  287. google.protobuf.Timestamp start_time = 3;
  288. // The time the certificate becomes invalid.
  289. google.protobuf.Timestamp expiry_time = 4;
  290. // The algorithm used to sign the certificate.
  291. string signature_algorithm = 5;
  292. // The type of public key in the certificate.
  293. string public_key_type = 6;
  294. }
  295. // A public key certificate format and data.
  296. message PublicKeyCertificate {
  297. // The certificate format.
  298. PublicKeyCertificateFormat format = 1;
  299. // The certificate data.
  300. string certificate = 2;
  301. // [Output only] The certificate details. Used only for X.509 certificates.
  302. X509CertificateDetails x509_details = 3;
  303. }
  304. // The supported formats for the public key.
  305. enum PublicKeyCertificateFormat {
  306. // The format has not been specified. This is an invalid default value and
  307. // must not be used.
  308. UNSPECIFIED_PUBLIC_KEY_CERTIFICATE_FORMAT = 0;
  309. // An X.509v3 certificate ([RFC5280](https://www.ietf.org/rfc/rfc5280.txt)),
  310. // encoded in base64, and wrapped by `-----BEGIN CERTIFICATE-----` and
  311. // `-----END CERTIFICATE-----`.
  312. X509_CERTIFICATE_PEM = 1;
  313. }
  314. // A server-stored device credential used for authentication.
  315. message DeviceCredential {
  316. // The credential data. Reserved for expansion in the future.
  317. oneof credential {
  318. // A public key used to verify the signature of JSON Web Tokens (JWTs).
  319. // When adding a new device credential, either via device creation or via
  320. // modifications, this public key credential may be required to be signed by
  321. // one of the registry level certificates. More specifically, if the
  322. // registry contains at least one certificate, any new device credential
  323. // must be signed by one of the registry certificates. As a result,
  324. // when the registry contains certificates, only X.509 certificates are
  325. // accepted as device credentials. However, if the registry does
  326. // not contain a certificate, self-signed certificates and public keys will
  327. // be accepted. New device credentials must be different from every
  328. // registry-level certificate.
  329. PublicKeyCredential public_key = 2;
  330. }
  331. // [Optional] The time at which this credential becomes invalid. This
  332. // credential will be ignored for new client authentication requests after
  333. // this timestamp; however, it will not be automatically deleted.
  334. google.protobuf.Timestamp expiration_time = 6;
  335. }
  336. // A public key format and data.
  337. message PublicKeyCredential {
  338. // The format of the key.
  339. PublicKeyFormat format = 1;
  340. // The key data.
  341. string key = 2;
  342. }
  343. // The supported formats for the public key.
  344. enum PublicKeyFormat {
  345. // The format has not been specified. This is an invalid default value and
  346. // must not be used.
  347. UNSPECIFIED_PUBLIC_KEY_FORMAT = 0;
  348. // An RSA public key encoded in base64, and wrapped by
  349. // `-----BEGIN PUBLIC KEY-----` and `-----END PUBLIC KEY-----`. This can be
  350. // used to verify `RS256` signatures in JWT tokens ([RFC7518](
  351. // https://www.ietf.org/rfc/rfc7518.txt)).
  352. RSA_PEM = 3;
  353. // As RSA_PEM, but wrapped in an X.509v3 certificate ([RFC5280](
  354. // https://www.ietf.org/rfc/rfc5280.txt)), encoded in base64, and wrapped by
  355. // `-----BEGIN CERTIFICATE-----` and `-----END CERTIFICATE-----`.
  356. RSA_X509_PEM = 1;
  357. // Public key for the ECDSA algorithm using P-256 and SHA-256, encoded in
  358. // base64, and wrapped by `-----BEGIN PUBLIC KEY-----` and `-----END
  359. // PUBLIC KEY-----`. This can be used to verify JWT tokens with the `ES256`
  360. // algorithm ([RFC7518](https://www.ietf.org/rfc/rfc7518.txt)). This curve is
  361. // defined in [OpenSSL](https://www.openssl.org/) as the `prime256v1` curve.
  362. ES256_PEM = 2;
  363. // As ES256_PEM, but wrapped in an X.509v3 certificate ([RFC5280](
  364. // https://www.ietf.org/rfc/rfc5280.txt)), encoded in base64, and wrapped by
  365. // `-----BEGIN CERTIFICATE-----` and `-----END CERTIFICATE-----`.
  366. ES256_X509_PEM = 4;
  367. }
  368. // The device configuration. Eventually delivered to devices.
  369. message DeviceConfig {
  370. // [Output only] The version of this update. The version number is assigned by
  371. // the server, and is always greater than 0 after device creation. The
  372. // version must be 0 on the `CreateDevice` request if a `config` is
  373. // specified; the response of `CreateDevice` will always have a value of 1.
  374. int64 version = 1;
  375. // [Output only] The time at which this configuration version was updated in
  376. // Cloud IoT Core. This timestamp is set by the server.
  377. google.protobuf.Timestamp cloud_update_time = 2;
  378. // [Output only] The time at which Cloud IoT Core received the
  379. // acknowledgment from the device, indicating that the device has received
  380. // this configuration version. If this field is not present, the device has
  381. // not yet acknowledged that it received this version. Note that when
  382. // the config was sent to the device, many config versions may have been
  383. // available in Cloud IoT Core while the device was disconnected, and on
  384. // connection, only the latest version is sent to the device. Some
  385. // versions may never be sent to the device, and therefore are never
  386. // acknowledged. This timestamp is set by Cloud IoT Core.
  387. google.protobuf.Timestamp device_ack_time = 3;
  388. // The device configuration data.
  389. bytes binary_data = 4;
  390. }
  391. // The device state, as reported by the device.
  392. message DeviceState {
  393. // [Output only] The time at which this state version was updated in Cloud
  394. // IoT Core.
  395. google.protobuf.Timestamp update_time = 1;
  396. // The device state data.
  397. bytes binary_data = 2;
  398. }