Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pushd "$script_dir/../.." || {
exit 1
}

echo "Deleting the examples in the resource-manager directory and the management directory..."
rm -r resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples
rm -r IoTOperations.Management/examples/2024-08-15-preview
# echo "Deleting the examples in the resource-manager directory and the management directory..."
# rm -r resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples
# rm -r IoTOperations.Management/examples/2024-08-15-preview

echo "Generating the specs and the examples!"

Expand All @@ -22,62 +22,68 @@ echo "Compiling the typespecs in the iotoperations directory..."
npx tsp compile IoTOperations.Management/.

# Generate examples for all the openapi specs
echo "Generating examples for all the openapi specs..."
oav generate-examples resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/iotoperations.json --max -p
# echo "Generating examples for all the openapi specs..."
# oav generate-examples resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/iotoperations.json --max -p

# Search each example file and replace the default string with resource-name123
for file in resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples/*.json; do
jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp ^[a-z0-9][a-z0-9-]*[a-z0-9]$" then "resource-name123" else . end)' $file > temp.json && mv temp.json $file
jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp ^[0-9]+[KMGTPE]$" then "500M" else . end)' $file > temp.json && mv temp.json $file
jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp ^https://.*$" then "https://www.example.com" else . end)' $file > temp.json && mv temp.json $file
jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp .+\\..+\\.kusto\\.windows\\.net" then "<cluster>.<region>.kusto.windows.net" else . end)' $file > temp.json && mv temp.json $file
jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp .+\\.blob\\.core\\.windows\\.net" then "<account>.blob.core.windows.net" else . end)' $file > temp.json && mv temp.json $file
jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp .+\\.fabric\\.microsoft\\.com" then "https://<host>.fabric.microsoft.com" else . end)' $file > temp.json && mv temp.json $file
done

for file in resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples/*.json; do

# The following Jq commands replace ids with properly formatted ARM Ids
operationId=$(jq -r '.operationId' $file)
if [[ $operationId == Instance* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("Instance") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
elif [[ $operationId == BrokerAuthentication* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("BrokerAuthentication") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123/authentications/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
elif [[ $operationId == BrokerAuthorization* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("BrokerAuthorization") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123/authorizations/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
elif [[ $operationId == BrokerListener* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("BrokerListener") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123/listeners/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
elif [[ $operationId == Broker* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("Broker") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
elif [[ $operationId == DataflowProfile* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("DataflowProfile") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/dataflowProfiles/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
elif [[ $operationId == DataflowEndpoint* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("DataflowEndpoint") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/dataflowEndpoints/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
elif [[ $operationId == Dataflow* ]]; then
jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("Dataflow") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/dataflowProfiles/resource-name123/dataflows/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
fi

# The following Jq command chops down numbers that are greater than 10000 to 10000, the OAV generate examples tool will not respect the min/max value required by typespec
jq 'walk(if type == "number" then . % 10000 else . end)' $file > temp.json && mv temp.json $file

# Set spanChannelCapacity to correct value for minimum.
jq 'walk(if type == "object" and .spanChannelCapacity? then .spanChannelCapacity = 1000 else . end)' $file > temp.json && mv temp.json $file

# Replace description strings with some Lorem Ipsum text.
jq 'walk(if type == "object" and .description? then .description = "Lorem ipsum odor amet, consectetuer adipiscing elit." else . end)' $file > temp.json && mv temp.json $file

# Replace identity strings with GUIDs.
jq 'walk(if type == "object" and .principalId? then .principalId = "4a6e4195-75b8-4685-aa0c-0b5704779327" else . end)' $file > temp.json && mv temp.json $file
jq 'walk(if type == "object" and .tenantId? then .tenantId = "ed060aa2-71ff-4d3f-99c4-a9138356fdec" else . end)' $file > temp.json && mv temp.json $file
jq 'walk(if type == "object" and .clientId? then .clientId = "fb90f267-8872-431a-a76a-a1cec5d3c4d2" else . end)' $file > temp.json && mv temp.json $file
done

#####################################################################
#
# Don't make any changes to examples for now through this script.
#
#####################################################################
# for file in resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples/*.json; do
# jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp ^[a-z0-9][a-z0-9-]*[a-z0-9]$" then "resource-name123" else . end)' $file > temp.json && mv temp.json $file
# jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp ^[0-9]+[KMGTPE]$" then "500M" else . end)' $file > temp.json && mv temp.json $file
# jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp ^https://.*$" then "https://www.example.com" else . end)' $file > temp.json && mv temp.json $file
# jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp .+\\..+\\.kusto\\.windows\\.net" then "<cluster>.<region>.kusto.windows.net" else . end)' $file > temp.json && mv temp.json $file
# jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp .+\\.blob\\.core\\.windows\\.net" then "<account>.blob.core.windows.net" else . end)' $file > temp.json && mv temp.json $file
# jq 'walk(if type == "string" and . == "Replace this value with a string matching RegExp .+\\.fabric\\.microsoft\\.com" then "https://<host>.fabric.microsoft.com" else . end)' $file > temp.json && mv temp.json $file
# done

# for file in resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples/*.json; do

# # The following Jq commands replace ids with properly formatted ARM Ids
# operationId=$(jq -r '.operationId' $file)
# if [[ $operationId == Instance* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("Instance") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# elif [[ $operationId == BrokerAuthentication* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("BrokerAuthentication") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123/authentications/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# elif [[ $operationId == BrokerAuthorization* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("BrokerAuthorization") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123/authorizations/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# elif [[ $operationId == BrokerListener* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("BrokerListener") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123/listeners/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# elif [[ $operationId == Broker* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("Broker") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/brokers/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# elif [[ $operationId == DataflowProfile* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("DataflowProfile") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/dataflowProfiles/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# elif [[ $operationId == DataflowEndpoint* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("DataflowEndpoint") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/dataflowEndpoints/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# elif [[ $operationId == Dataflow* ]]; then
# jq --arg operationId "$operationId" 'walk(if type == "object" and .id? then if $operationId | startswith("Dataflow") then .id = "/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup123/providers/Microsoft.IoTOperations/instances/resource-name123/dataflowProfiles/resource-name123/dataflows/resource-name123" else . end else . end)' $file > temp.json && mv temp.json $file
# fi

# # The following Jq command chops down numbers that are greater than 10000 to 10000, the OAV generate examples tool will not respect the min/max value required by typespec
# jq 'walk(if type == "number" then . % 10000 else . end)' $file > temp.json && mv temp.json $file

# # Set spanChannelCapacity to correct value for minimum.
# jq 'walk(if type == "object" and .spanChannelCapacity? then .spanChannelCapacity = 1000 else . end)' $file > temp.json && mv temp.json $file

# # Replace description strings with some Lorem Ipsum text.
# jq 'walk(if type == "object" and .description? then .description = "Lorem ipsum odor amet, consectetuer adipiscing elit." else . end)' $file > temp.json && mv temp.json $file

# # Replace identity strings with GUIDs.
# jq 'walk(if type == "object" and .principalId? then .principalId = "4a6e4195-75b8-4685-aa0c-0b5704779327" else . end)' $file > temp.json && mv temp.json $file
# jq 'walk(if type == "object" and .tenantId? then .tenantId = "ed060aa2-71ff-4d3f-99c4-a9138356fdec" else . end)' $file > temp.json && mv temp.json $file
# jq 'walk(if type == "object" and .clientId? then .clientId = "fb90f267-8872-431a-a76a-a1cec5d3c4d2" else . end)' $file > temp.json && mv temp.json $file
# done

# Copy the examples to the management directory
echo "Copying the examples to the management directory..."
cp -r resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples/. IoTOperations.Management/examples/2024-08-15-preview/
# echo "Copying the examples to the management directory..."
# cp -r resource-manager/Microsoft.IoTOperations/preview/2024-08-15-preview/examples/. IoTOperations.Management/examples/2024-08-15-preview/

# Recompile the typespecs in the management directory
echo "Recompiling the typespecs in the management directory..."
# echo "Recompiling the typespecs in the management directory..."
npx tsp compile IoTOperations.Management/.
npx tsv IoTOperations.Management/.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "BrokerListener_CreateOrUpdate_Complex",
"title": "BrokerListener_CreateOrUpdate_Simple",
"operationId": "BrokerListener_CreateOrUpdate",
"parameters": {
"api-version": "2024-08-15-preview",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"title": "BrokerAuthentication_CreateOrUpdate_Complex",
"operationId": "BrokerAuthentication_CreateOrUpdate",
"parameters": {
"api-version": "2024-08-15-preview",
"subscriptionId": "F8C729F9-DF9C-4743-848F-96EE433D8E53",
"resourceGroupName": "rgiotoperations",
"instanceName": "resource-name123",
"brokerName": "resource-name123",
"authenticationName": "resource-name123",
"resource": {
"properties": {
"authenticationMethods": [
{
"method": "ServiceAccountToken",
"serviceAccountTokenSettings": {
"audiences": [
"aio-mq"
]
}
},
{
"method": "X509",
"x509Settings": {
"trustedClientCaCert": "my-ca",
"authorizationAttributes": {
"root": {
"subject": "CN = Contoso Root CA Cert, OU = Engineering, C = US",
"attributes": {
"organization": "contoso"
}
},
"intermediate": {
"subject": "CN = Contoso Intermediate CA",
"attributes": {
"city": "seattle",
"foo": "bar"
}
},
"smart-fan": {
"subject": "CN = smart-fan",
"attributes": {
"building": "17"
}
}
}
}
}
]
},
"extendedLocation": {
"name": "qmbrfwcpwwhggszhrdjv",
"type": "CustomLocation"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"title": "BrokerAuthorization_CreateOrUpdate_Complex",
"operationId": "BrokerAuthorization_CreateOrUpdate",
"parameters": {
"api-version": "2024-08-15-preview",
"subscriptionId": "F8C729F9-DF9C-4743-848F-96EE433D8E53",
"resourceGroupName": "rgiotoperations",
"instanceName": "resource-name123",
"brokerName": "resource-name123",
"authorizationName": "resource-name123",
"resource": {
"properties": {
"authorizationPolicies": {
"enableCache": true,
"rules": [
{
"principals": {
"usernames": [
"temperature-sensor",
"humidity-sensor"
],
"attributes": [
{
"building": 17,
"organization": "contoso"
}
]
},
"brokerResources": [
{
"method": "Connect",
"clientIds": [
"{principal.attributes.building}*"
]
},
{
"method": "Publish",
"topics": [
"sensors/{principal.attributes.building}/{principal.clientId}/telemetry/*"
]
},
{
"method": "Subscribe",
"topics": [
"commands/{principal.attributes.organization}"
]
}
],
"stateStoreResources": [
{
"method": "Read",
"keyType": "Pattern",
"keys": [
"myreadkey",
"myotherkey?",
"mynumerickeysuffix[0-9]",
"clients:{principal.clientId}:*"
]
},
{
"method": "ReadWrite",
"keyType": "Binary",
"keys": [
"MTE2IDEwMSAxMTUgMTE2"
]
}
]
}
]
}
},
"extendedLocation": {
"name": "qmbrfwcpwwhggszhrdjv",
"type": "CustomLocation"
}
}
}
}
Loading