-
Notifications
You must be signed in to change notification settings - Fork 261
docs: replace curl examples with Scaleway CLI commands #5844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ tags: iot iot-hub io-hub-api api curl mqtt jq json | |
| import Requirements from '@macros/iam/requirements.mdx' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Github won't let me comment the lines 2 to 6: update mentions of API/curl to CLI |
||
|
|
||
|
|
||
| In this tutorial we will use the API through the well known utility [curl](https://curl.haxx.se/). This will show you how to create Hubs and Devices, as well as more advanced features of the Scaleway IoT Hub: Hub Events and Routes. | ||
| In this tutorial we will use the Scaleway CLI. This will show you how to create Hubs and Devices, as well as more advanced features of the Scaleway IoT Hub: Hub Events and Routes. | ||
|
|
||
| The API reference is here: [IoT API](https://www.scaleway.com/en/developers/api/iot-hub/) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link CLI doc? |
||
|
|
||
|
|
@@ -17,7 +17,7 @@ The API reference is here: [IoT API](https://www.scaleway.com/en/developers/api/ | |
| - A Scaleway account logged into the [console](https://console.scaleway.com) | ||
| - [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization | ||
| - A valid [API key](/iam/how-to/create-api-keys/). | ||
| - Installed `curl`, `mosquitto-clients` (mqtt client), and `jq` (json parsing tool) | ||
| - Installed the Scaleway CLI, `mosquitto-clients` (mqtt client), and `jq` (json parsing tool) | ||
|
|
||
| You already set the `SCW_SECRET_KEY` variable above, now set the following variables from the same terminal on your local computer: | ||
|
|
||
|
|
@@ -38,11 +38,10 @@ The Hub creation is done through a REST endpoint. To create a Hub, you will need | |
| We will save the output to `hub.json` file: | ||
|
|
||
| ```bash | ||
| curl -sS -H "X-Auth-Token: $SCW_SECRET_KEY" -d '{ | ||
| "project_id": "'$SCW_DEFAULT_PROJECT_ID'", | ||
| "name": "my_first_hub", | ||
| "product_plan": "plan_dedicated" | ||
| }' $IOT_API/hubs > hub.json | ||
| scw iot hub create \ | ||
| --name=my_first_hub \ | ||
| --product-plan=plan_dedicated \ | ||
| --region=fr-par > hub.json | ||
|
|
||
| jq < hub.json | ||
| ``` | ||
|
|
@@ -74,7 +73,9 @@ jq < hub.json | |
| We can poll the hub status until it is ready: | ||
|
|
||
| ```bash | ||
| curl -sS -H "X-Auth-Token: $SCW_SECRET_KEY" $IOT_API/hubs/$(jq -r '.id' hub.json) | jq -r '.status' | ||
| scw iot hub get \ | ||
| --hub-id=$(jq -r '.id' hub.json) \ | ||
| --region=fr-par | jq -r '.status' | ||
| ``` | ||
|
|
||
| At some point, the status will switch to `ready`. | ||
|
|
@@ -93,11 +94,11 @@ Now we need to create 2 devices. You need to provide: | |
| We will save the response to a file so we can use the fields later. | ||
|
|
||
| ```bash | ||
| curl -sS -H "X-Auth-Token: $SCW_SECRET_KEY" -d '{ | ||
| "hub_id": "'$(jq -r '.id' hub.json)'", | ||
| "name": "my_first_device", | ||
| "allow_insecure": true | ||
| }' $IOT_API/devices > dev1.json | ||
| scw iot device create \ | ||
| --hub-id=$(jq -r '.id' hub.json) \ | ||
| --name=my_first_device \ | ||
| --allow-insecure=true \ | ||
| --region=fr-par > dev1.json | ||
|
|
||
| jq < dev1.json | ||
| ``` | ||
|
|
@@ -139,11 +140,11 @@ jq < dev1.json | |
| Let's now create a second device: | ||
|
|
||
| ```bash | ||
| curl -sS -H "X-Auth-Token: $SCW_SECRET_KEY" -d '{ | ||
| "hub_id": "'$(jq -r '.id' hub.json)'", | ||
| "name": "my_second_device", | ||
| "allow_insecure": true | ||
| }' $IOT_API/devices > dev2.json | ||
| scw iot device create \ | ||
| --hub-id=$(jq -r '.id' hub.json) \ | ||
| --name=my_second_device \ | ||
| --allow-insecure=true \ | ||
| --region=fr-par > dev2.json | ||
|
|
||
| jq < dev2.json | ||
| ``` | ||
|
|
@@ -186,9 +187,8 @@ If you require security, you can also connect your device to the Hub using TLS m | |
| First, download the IoT Hub's server CA: | ||
|
|
||
| ```bash | ||
| curl -sS -O https://iot.s3.nl-ams.scw.cloud/certificates/fr-par/iot-hub-ca.pem | ||
| sha1sum iot-hub-ca.pem | ||
| # 13cf3e59ed52d4c4b6bc249e85539d5fd5d572fb iot-hub-ca.pem | ||
| # The certificate is automatically handled by the CLI | ||
| # No need to download it manually when using the Scaleway CLI | ||
| ``` | ||
|
|
||
| Now, extract the certificates from the device JSON files, so that the mosquitto clients may use them: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -52,13 +52,9 @@ An output similar to the following should display: | |||||
|
|
||||||
| Paste the following command to create your data encryption key via the Key Manager API. Make sure that you replace the placeholder values with your own. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not commenting other occurrences in order not to spam to much, but there seems to be a few similar API mentions left that should be replaced with the CLI |
||||||
| ```bash | ||||||
| curl --location 'https://api.scaleway.com/key-manager/v1alpha1/regions/fr-par/keys/<your_key_id>/generate-data-key' \ | ||||||
| --header 'Content-Type: application/json' \ | ||||||
| --header 'X-Auth-Token: <your_secret_key>' \ | ||||||
| --data '{ | ||||||
| "algorithm": "aes_256_gcm" | ||||||
| }' | ||||||
| ``` | ||||||
| scw keymanager key generate-data-key <your_key_id> \ | ||||||
| --algorithm=aes_256_gcm \ | ||||||
| --region=fr-par | ||||||
|
|
||||||
| Key Manager also supports the `GenerateDataKey` request without a plaintext operation, which only returns an encrypted data encryption key. | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,17 +32,17 @@ This page shows you how to send a simple transactional email in `JSON` format to | |
| 2. Run the following command to retrieve your domain's ID, as you will need it in the next step. The output should return your domain's information. | ||
|
|
||
| ``` | ||
| curl -X GET \ | ||
| -H "X-Auth-Token: $SCW_SECRET_KEY" \ | ||
| "https://api.scaleway.com/transactional-email/v1alpha1/regions/fr-par/domains" | ||
| scw tem domain list \ | ||
| --region=fr-par | ||
| ``` | ||
|
|
||
|
|
||
| 3. Run the following command to ensure that your domain is verified: | ||
|
|
||
| ``` | ||
| curl -X GET "https://api.scaleway.com/transactional-email/v1alpha1/regions/$REGION/domains/<domain-id>" \ | ||
| -H "X-Auth-Token: $SCW_SECRET_KEY" | ||
| scw tem domain get \ | ||
| --domain-id=<domain-id> \ | ||
| --region=$REGION | ||
| ``` | ||
|
|
||
| 4. Copy the following template. Make sure that you replace the placeholder information with your own. | ||
|
|
@@ -80,9 +80,13 @@ This page shows you how to send a simple transactional email in `JSON` format to | |
| } | ||
| EOF | ||
|
|
||
| curl -X POST "https://api.scaleway.com/transactional-email/v1alpha1/regions/$REGION/emails" \ | ||
| -H "X-Auth-Token: $SCW_SECRET_KEY" \ | ||
| -d @mail.json | ||
| scw tem email create \ | ||
| [email protected] \ | ||
| [email protected] \ | ||
| --subject="This is a subject" \ | ||
| --text="This is a short sentence." \ | ||
| --project-id=<Scaleway Project ID> \ | ||
| --region=$REGION | ||
| ``` | ||
|
|
||
| 5. Once you have added your own information to the template above, run it in your terminal. An output similar to the following should display: | ||
|
|
@@ -94,10 +98,9 @@ This page shows you how to send a simple transactional email in `JSON` format to | |
| 6. Run the following command to check that your email has been sent. Make sure that you replace `$EMAIL_ID` with the ID of the email you retrieved in the output of the previous step. | ||
|
|
||
| ``` | ||
| curl --request GET \ | ||
| --url https://api.scaleway.com/transactional-email/v1alpha1/regions/fr-par/emails/$EMAIL_ID \ | ||
| --header 'X-Auth-Token: $SCW_SECRET_KEY' | ||
|
|
||
| scw tem email get \ | ||
| --email-id=$EMAIL_ID \ | ||
| --region=fr-par | ||
| ``` | ||
|
|
||
| You should get an output similar to the following: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,9 +57,13 @@ cat > mail.json <<EOF | |
| } | ||
| EOF | ||
|
|
||
| curl -X POST "https://api.scaleway.com/transactional-email/v1alpha1/regions/$REGION/emails" \ | ||
| -H "X-Auth-Token: $TOKEN" \ | ||
| -d @mail.json | ||
| scw tem email create \ | ||
| [email protected] \ | ||
| [email protected] \ | ||
| --subject="This is a subject" \ | ||
| --text="This is a short sentence." \ | ||
| --project-id=<Scaleway Project ID> \ | ||
| --region=$REGION | ||
| ``` | ||
| <Message type="important"> | ||
| - If you have not configured your environment on your local machine, make sure you replace `\<project_id\>` with your [Project ID](/organizations-and-projects/concepts/#project), `$REGION` with `fr-par` and `$TOKEN` with your secret key. If you do not replace the Project ID, the API displays a "permission denied" error message. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.