Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f0e8161
Made PublicKeyFormat a child class of Enum
sky-sharma Apr 20, 2023
21fa451
1. import PublicKeyFormat from .resources
sky-sharma Apr 20, 2023
22f8a10
Added note about how to run from source
sky-sharma Apr 21, 2023
a2efdeb
Formatting
sky-sharma Apr 21, 2023
3abd15c
More formatting
sky-sharma Apr 21, 2023
5dbc103
Formatting
sky-sharma Apr 21, 2023
60994d9
Formatting
sky-sharma Apr 21, 2023
873e657
Clearer info. on running from source
sky-sharma Apr 21, 2023
87468a7
1. Import PublicKeyCredential & DeviceCredential
sky-sharma Apr 28, 2023
43062e4
Added code to _create_device_body to:
sky-sharma Apr 28, 2023
67668e6
Add PublicKeyCredential & DeviceCredential classes
sky-sharma Apr 28, 2023
30ad6dc
Changed PublicKeyCredential constructor params:
sky-sharma Apr 28, 2023
6f12451
1. bug: DeviceCredential constructor calls
sky-sharma Apr 28, 2023
61c4b09
1. Removed unnecessary var from
sky-sharma Apr 28, 2023
15d9bf9
1. Import DeviceCredential
sky-sharma Apr 28, 2023
5c117d9
1. Removed the config and state conversion code
sky-sharma Apr 29, 2023
a030f00
In classes PublicKeyCredential & DeviceCredential
sky-sharma Apr 29, 2023
9f36892
Document changes from last version in UPGRADING.md
sky-sharma May 3, 2023
98604ef
Turned ClearBlade and Google License info. into comments
sky-sharma May 3, 2023
61be8e2
Formatting changes
sky-sharma May 3, 2023
d77e5b5
In 'convert_credentials_for_create_update' check
sky-sharma May 3, 2023
62e9bfe
Formatting
sky-sharma May 3, 2023
cac59c5
Formatting
sky-sharma May 3, 2023
6f5ba64
Formatting
sky-sharma May 3, 2023
4c812ce
Formatting
sky-sharma May 3, 2023
51f1f3f
Formatting
sky-sharma May 4, 2023
1aeb131
Prefixed license info.
sky-sharma May 4, 2023
8900abd
bug: if expirationTime type 'datetime', isoformat
sky-sharma May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,20 @@ Note about types of times and binaryData
1. All times: **DatetimeWithNanoseconds** (defined in the **proto.datetime_helpers** module)
2. All **binaryData** (CONFIG, STATE etc.): **BYTE ARRAYS**

- If this environment variable is not set, or is set to any unexpeced values, then the default types listed previously are used.
- If this environment variable is not set, or is set to any unexpeced values, then the default types listed previously are used.

Note about running from source instead of PyPi (pip) module:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- To temporarily use the source code in this repo. instead of the installed PyPi (pip) module do the following:

1. Clone this repo.
2. Checkout the desired branch using **git checkout <branch>**.
3. In your code find where **clearblade** or **clearblade.cloud** is being imported.
4. Precede that line with **import sys** and **sys.path.insert(0, <path_to_python-iot>)**. The path must end with "python-iot". So for example:

.. code-block:: console

import sys
sys.path.insert(0, "path/to/python-iot")

from clearblade.cloud import iot_v1
232 changes: 113 additions & 119 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,157 +1,151 @@
# 2.0.0 Migration Guide

The 2.0 release of the `google-cloud-iot` client is a significant upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), and includes substantial interface changes. Existing code written for earlier versions of this library will likely require updates to use this version. This document describes the changes that have been made, and what you need to do to update your usage.

If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-iot/issues).

## Supported Python Versions

> **WARNING**: Breaking change

The 2.0.0 release requires Python 3.6+.

<!-- "Copyright 2023 ClearBlade Inc."

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2023 ClearBlade Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->

## Method Calls

> **WARNING**: Breaking change

Methods expect request objects. We provide a script that will convert most common use cases.

* Install the library with `libcst`.

```py
python3 -m pip install google-cloud-iot[libcst]
```

* The script `fixup_iot_v1_keywords.py` is shipped with the library. It expects
an input directory (with the code to convert) and an empty destination directory.
# 2.0.0 Migration Guide

```sh
$ fixup_iot_v1_keywords.py --input-directory .samples/ --output-directory samples/
```
The 2.0 release of the `clearblade-cloud-iot` client is a significant upgrade based on addition of two new classes in **iot_v1**:

**Before:**
```py
from google.cloud import iot_v1
- **DeviceCredential**
- **PublicKeyCredential**

client = iot_v1.DeviceManagerClient()
The release also includes enhancements to these classes already present in **iot_v1**:

registry = client.get_device_registry("registry_name")
```
- **DeviceConfig**
- **DeviceState**

The version was made with the intent of minimizing required code changes. **However these changes should be considrered Breaking changes**.

**After:**
```py
from google.cloud import iot_v1
#

client = iot_v1.DeviceManagerClient()
1. If **device** is an object of class **Device**.

registry = client.get_device_registry(request={'name': "registry_name"})
```
**Before**:
device.credentials is of type **[dict]** (i.e. list of dicts).

### More Details
**After**:
device.credentials is of type **[DeviceCredential]** (i.e. list of objects of class DeviceCredential).

In `google-cloud-iot<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters.
The **DeviceCredential** class has these features for usability:

**Before:**
```py
def create_device(
self,
parent,
device,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
```
- A **get** method that mimics the **get** method of a dict.
- Allows accessing attributes using dot notation OR square-brackets.
- Supports camel-case as well as snake-case for accessing attributes:

In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional.
e.g. All these are valid for retrieving the public key:

Some methods have additional keyword only parameters. The available parameters depend on the `google.api.method_signature` annotation specified by the API producer.
- **public_key = device.credentials[0]['publicKey']**
- **public_key = device.credentials[0]['public_key']**
- **public_key = device.credentials[0].get('publicKey')**
- **public_key = device.credentials[0].get('public_key')**
- **public_key = device.credentials[0].publicKey**
- **public_key = device.credentials[0].public_key**

#

**After:**
```py
def create_device(
self,
request: device_manager.CreateDeviceRequest = None,
*,
parent: str = None,
device: resources.Device = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> resources.Device:
```
2. This refers to pub_key mentioned in the previous section.

> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive.
> Passing both will result in an error.
**Before**:
public_key was of type **dict**.

**After**:
public_key is an object of class **PublicKeyCredential**.

Both of these calls are valid:
The **PublicKeyCredential** class has these features for usability:

```py
response = client.create_device(
request={
"parent": parent,
"device": device,
}
)
```
- A **get** method that mimics the **get** method of a dict.
- Allows accessing attributes using dot notation OR square-brackets.

```py
response = client.create_device(
parent=parent,
device=device,
)
```
e.g. All these are valid for retrieving the public key format:

This call is invalid because it mixes `request` with a keyword argument `device`. Executing this code
will result in an error.
- **format = public_key['format']**
- **format = public_key.get('format')**
- **format = public_key.format**

```py
response = client.create_device(
request={
"parent": parent,
},
device=device
)
```
#

3. This section refers to **dev_config** which holds device config.

**Before**:
dev_config is of type **dict**.

## Enums and Types
**After**:
dev_config is an object of class **DeviceConfig**.

The **DeviceConfig** class has these features for usability:

> **WARNING**: Breaking change
- A **get** method that mimics the **get** method of a dict.
- Allows accessing attributes using dot notation OR square-brackets.
- Supports camel-case as well as snake-case for accessing attributes:

The submodules `enums` and `types` have been removed.
e.g. All these are valid for retrieving the cloud_update_time:

**Before:**
```py
from google.cloud import iot_v1
- **cloud_update_time = device.credentials[0]['cloudUpdateTime']**
- **cloud_update_time = device.credentials[0]['cloud_update_time']**
- **cloud_update_time = device.credentials[0].get('cloudUpdateTime')**
- **cloud_update_time = device.credentials[0].get('cloud_update_time')**
- **cloud_update_time = device.credentials[0].cloudUpdateTime**
- **cloud_update_time = device.credentials[0].cloud_update_time**

gateway_type = iot_v1.enums.GatewayType.GATEWAY
device = iot_v1.types.Device(name="name")
```
#

4. This section refers to **dev_state** which contains device state.

**After:**
```py
from google.cloud import iot_v1
**Before**:
dev_state is of type **dict**.

gateway_type = iot_v1.GatewayType.GATEWAY
device = iot_v1.Device(name="name")
```
**After**:
dev_state is an object of class **DeviceState**.

## Location Path Helper Method
The **DeviceState** class has these features for usability:

Location path helper method has been removed. Please construct
the path manually.
- A **get** method that mimics the **get** method of a dict.
- Allows accessing attributes using dot notation OR square-brackets.
- Supports camel-case as well as snake-case for accessing attributes:

```py
project = 'my-project'
location = 'location'
e.g. All these are valid for retrieving the binary_data:

location_path = f'projects/{project}/locations/{location}'
```
- **binary_data = device.credentials[0]['binaryData']**
- **binary_data = device.credentials[0]['binary_data']**
- **binary_data = device.credentials[0].get('binaryData')**
- **binary_data = device.credentials[0].get('binary_data')**
- **binary_data = device.credentials[0].binaryData**
- **binary_data = device.credentials[0].binary_data**
44 changes: 44 additions & 0 deletions clearblade/cloud/iot_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
"""
"Copyright 2023 ClearBlade Inc."

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2023 ClearBlade Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from .client import DeviceManagerClient, DeviceManagerAsyncClient
from .device_types import *
from .registry_types import *
Expand Down
44 changes: 44 additions & 0 deletions clearblade/cloud/iot_v1/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
"""
"Copyright 2023 ClearBlade Inc."

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2023 ClearBlade Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from .device_types import *
from .devices import *
from .registry import *
Expand Down
Loading