Azure Container Service using Rest API - azure

I would like to create azure container with resource group and cluster of specific Orchestrator Kubernetes cluster.
I know by using CLI its possible but I want to do this using Azure Rest API's for Container service from link given here
learn.microsoft.com/en-us/rest/api/container-service/containerservices/createorupdate
Registered my app in AAD and gave required permissions.
Got access token and making request to below api as per link
PUT management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}?api-version=2017-01-31
but I am getting error as
{
"error": {
"code": "InvalidResource"
"message": "The resource definition is invalid."
}
}
I understand we get this error when there is nothing in request body.
So my real question here is if I want to create container service with resource group and cluster using API request.
Request Body
{
"id": "myCluster",
"name": "myCluster",
"type": "Microsoft.ContainerService/containerServices",
"location": "southindia",
"tags": {
"tag": "test"
},
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes"
},
"servicePrincipalProfile": {
"clientId": "<clientid>,
"secret": "<secret>"
},
"masterProfile": {
"count": 1,
"dnsPrefix": "testabc"
},
"agentPoolProfiles": {
"name": "agentPool1234",
"count": 2,
"vmSize": "Standard_A1",
"dnsPrefix": "testabcagents"
},
"linuxProfile": {
"adminUsername": "kubeadmin",
"ssh": {
"publicKeys": [
{
"keyData": "sshkey"
}
]
}
}
}
}
Response getting
{
"code": "BadRequest",
"message": "An error has occurred in subscription <subscriptionid>, resourceGroup: tobeDeletedResourceGroup request: OrchestratorType has unknown orchestrator: ."
}
Please help me out on this

Two things are missing from Azure REST API documentation.
1) It requires version of orchestratorRelease with orchestratorType like this. "orchestratorProfile": {
"orchestratorType": "Kubernetes",
"orchestratorRelease": "1.7"
}
2) Next error i got about missing vmSize in Properties.MasterProfile.VMSize.
So I have added following updates to json
"masterProfile": {
"count": 1,
"dnsPrefix": "testabc",
"vmSize": "Standard_D2_v2"
}
Its very surprising and annoying that documentation is missing these 2 important json parameters.

agentPoolProfiles should be an array of json objects. I pulled this example from azure-cli's mock unit tests to help give you a frame of reference.
https://gist.github.com/bacongobbler/470b8d139536144edf91174916ec4036

Related

Error HTTP 401 when trying to sent a message from Azure Data Factory to Service Bus

I have tried to reproduce Hugh Woods experiment (https://medium.com/asos-techblog/sending-messages-from-azure-data-factory-to-service-bus-86d4be6dd357) in my azure environment to sent messages from Azure DataFactory to Azure Service Bus.
I have followed the instructions, assigning the "Azure Service Bus Data Sender" role to my data factory’s managed identity.
But when I tried to sent a message to Service Bus I got this error:
Error code : 2108
Failure type : User configuration issue
Details : Invoking Web Activity failed with HttpStatusCode -
'401 : Unauthorized', message - ''
Source : Pipeline Service Bus REST API
What am I doing wrong in this case? I have this configuration in my pipeline:
{
"name": "Service Bus REST API",
"properties": {
"activities": [
{
"name": "Service Bus REST API",
"description": "Teste",
"type": "WebActivity",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"url": "https://sb-namespace-dv.servicebus.windows.net/sbt-azure-adf-ntt-data-test/messages",
"method": "POST",
"headers": {
"CustomHeader-Version": "\"1.0\"",
"Content-Type": "application/json",
"BrokerProperties": {
"value": "#concat('{\"CorrelationId\": \"',pipeline().RunId,'\"}')",
"type": "Expression"
}
},
"body": {
"value": "{\"message\":{\"value\":\"#variables('OutputDetails')\",\"type\":\"Expression\"}}",
"type": "Expression"
},
"httpRequestTimeout": "00:10:00",
"authentication": {
"type": "MSI",
"resource": "https://servicebus.azure.net"
}
}
}
],
"folder": {
"name": "999_Others/9910_DevTest/TesteServiceBusADF"
},
"annotations": []
}
}
I have followed all steps of Hugh Woods article. I have expecting to get the same results of his experiment (below), but I did not have success.
{
message : "Snapshot Avaliable"
}
The message you are getting is HTTP 401 Unauthorized. So the call to write data to the service bus is being refused.
There are 2 possibilities:
The authentication is not set up correctly
You tested it before the role assignments had propagated (can take 5 mins)
See: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-managed-service-identity

how to pass parameters in azure pipeline using rest api?

I'm using postman to make rest requests to the azure API to run a pipeline that is in synapse, in terms of permissions and the token I already get them and it works, the problem is that the pipeline receives 3 parameters but I don't know how to pass them, so I have this request, example:
https://hvdhgsad.dev.azuresynapse.net/pipelines/pipeName/createRun?api-version=2020-12-01
and the parameters I added them in the body:
{
"parameters": {
"p_dir": {
"type": "string",
"defaultValue": "val1"
},
"container": {
"type": "string",
"defaultValue": "val"
},
"p_folder": {
"type": "string",
"defaultValue": "val3"
}
}
}
but when I validate the run that was launched with the request I get this.
{
"id": "xxxxxxxxxxxxxxx",
"runId": "xxxxxxxxxxxxxxxxxxxxx",
"debugRunId": null,
"runGroupId": "xxxxxxxxxxxxxxxxxxxx",
"pipelineName": "xxxxxxxxxxxxxxxxx",
"parameters": {
"p_dir": "",
"p_folder": "",
"container": ""
},
"invokedBy": {
"id": "xxxxxxxxxxxxxxxxx",
"name": "Manual",
"invokedByType": "Manual"
},
"runStart": "2021-07-20T05:56:04.2468861Z",
"runEnd": "2021-07-20T05:59:10.1734654Z",
"durationInMs": 185926,
"status": "Failed",
"message": "Operation on target Data flow1 failed: {\"StatusCode\":\"DF-Executor-SourceInvalidPayload\",\"Message\":\"Job failed due to reason: Data preview, debug, and pipeline data flow execution failed because container does not exist\",\"Details\":\"\"}",
"lastUpdated": "2021-07-20T05:59:10.1734654Z",
"annotations": [],
"runDimension": {},
"isLatest": true
}
the params are empty, so I don't know what's wrong or missing.
what is the correct way to pass them???
ref: https://learn.microsoft.com/en-us/rest/api/synapse/data-plane/pipeline/create-pipeline-run#examples
Just created an account to answer this as i've had the same issue.
I resolved this by just having the name of the variable and its subsequent value in the body JSON.
e.g.
{"variable": "value", "variable": "value"}
Found this by following the documentation you had posted, under request body it passes the name of the variable and the value directly into the JSON body.
{
"OutputBlobNameList": [
"exampleoutput.csv"
]
}
This particular example is a list/array so it confused me by adding the brackets [] if you are passing string parameters this is unneeded.

Azure REST API for running builds or pipelines

I am trying to automate the creation of Azure Pipelines for a particular branch using their REST api.
However, I am struggling to use almost all their API's, as their documentation lacks examples.
Things like List and Get are simple enough.
However, when it comes to queuing a build:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.0
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=6.0
{
"parameters": <parameters>, // how do i send paramters
"definition": {
"id": 1
},
"sourceBranch": "refs/heads/feature/my-pipeline",
"sourceVersion": "d265f01aeb4e677a25725f44f20ceb3ff1d7d767"
}
I am currently struggling to send parameters.
I have tried:
Simple JSON like:
"parameters": {
"appId": "bab",
"platform": "android",
"isDemo": true
}
and stringify version of JSON like:
"parameters": "{\"appId\": \"bab\",\"platform\": \"android\",\"isDemo\": true}"
but none seems to work.
It keeps giving me the error:
{
"$id": "1",
"customProperties": {
"ValidationResults": [
{
"result": "error",
"message": "A value for the 'appId' parameter must be provided."
},
{
"result": "error",
"message": "A value for the 'platform' parameter must be provided."
},
{
"result": "error",
"message": "A value for the 'isDemo' parameter must be provided."
}
]
},
"innerException": null,
"message": "Could not queue the build because there were validation errors or warnings.",
"typeName": "Microsoft.TeamFoundation.Build.WebApi.BuildRequestValidationFailedException, Microsoft.TeamFoundation.Build2.WebApi",
"typeKey": "BuildRequestValidationFailedException",
"errorCode": 0,
"eventId": 3000
}
The docs is very unclear in how to send this data: https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-6.1#propertiescollection
Thank you very much for you help.
I believe you cannot pass runtime parameters trough the Queue API. Instead, use Runs API
With that, your request body (use Content-type: application/json) should look something similar to this:
{
"resources": {
"repositories": {
"self": {
"refName": "refs/heads/feature/my-pipeline"
}
}
},
"templateParameters": {
"appId": "bab"
"platform": "android"
"isDemo": true
}
}
I just realized that in the api-version=6.0 you can also send templateParameters on the Queue Service:
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?sourceBuildId={BUILD_BUILDID}&api-version=6.0
{
"templateParameters": { "doReleaseBuild": "True" },
"definition": {
"id": 1
},
"sourceBranch": "refs/heads/feature/my-pipeline",
"sourceVersion": "d265f01aeb4e677a25725f44f20ceb3ff1d7d767"
}

Azure B2C, Object reference not set error on IDP initiated custom provider configuration

I'm working on a customer project, and we are validating if we are having a problem with the customer's IDP solution or is this a B2C configuration item. In the validation, I'm connecting Azure AD (different subscription) to the Azure B2C instance on another configuration. The processing goes well, except in the end we get Object reference not set to an instance of an object.
Azure AD is initialzing a SSO (IDP Initated session) to B2C to mimic what the customer's solution will be doing.
I've been trying to track down what the object reference is, but not having any luck. Any help is appreciated.
37
{
"Kind": "HandlerResult",
"Content": {
"Result": true,
"RecorderRecord": {
"Values": [
{
"Key": "EnabledForUserJourneysTrue",
"Value": {
"Values": [
{
"Key": "CurrentStep",
"Value": 5
},
{
"Key": "TechnicalProfileEnabled",
"Value": {
"EnabledRule": "Always",
"EnabledResult": true,
"TechnicalProfile": "SAMLAssert"
}
}
]
}
}
]
},
"PredicateResult": "True"
}
}
38
{
"Kind": "Predicate",
"Content": "Web.TPEngine.StateMachineHandlers.IsSendClaimsProtocolAnApiHandler"
}
39
{
"Kind": "HandlerResult",
"Content": {
"Result": true,
"PredicateResult": "False"
}
}
40
{
"Kind": "Predicate",
"Content": "Web.TPEngine.StateMachineHandlers.IsPresentationTokenGeneratedHandler"
}
41
{
"Kind": "HandlerResult",
"Content": {
"Result": true,
"PredicateResult": "False"
}
}
42
{
"Kind": "Action",
"Content": "Web.TPEngine.StateMachineHandlers.PresentationTokenGenerationHandler"
}
43
{
"Kind": "FatalException",
"Content": {
"Time": "10:04 PM",
"Exception": {
"Kind": "Handled",
"HResult": "80004003",
"Message": "Object reference not set to an instance of an object.",
"Data": {}
}
}
}
I received this same error with an SP-initiated custom policy setup between a partner application and our Azure B2C and was able to resolve it. For anyone not familiar with troubleshooting custom policies, you can read these trace logs in App Insights.
The service provider's metadata file contained an AssertionConsumerService element that looked like
<AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="[SP login response endpoint]"/>
By modifying this element to include "index" and "isDefault", the error vanished:
<AssertionConsumerService index="0" isDefault="true" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="[SP login response endpoint]"/>
I took these attributes from Microsoft's SAML test app metadata.

Can't deploy arm template with NotificationHub + ApnsCredentials

I am using arm template to deploy Azure NotificationHub
Here is
{
"apiVersion": "2017-04-01",
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs",
"name": "[parameters('notificationHub_name')]",
"location": "[parameters('location')]",
"properties": {
"GcmCredential": {
"properties": {
"googleApiKey": "[parameters('googleApiKey')]",
"gcmEndpoint": "[parameters('googleEndpoint')]"
}
},
"ApnsCredential": {
"properties": {
"appId": "[parameters('apnsAppId')]",
"appName": "[parameters('apnsAppNameId')]",
"keyId": "[parameters('apnsKeyId')]",
"token": "[parameters('apnsToken')]",
"endpoint": "[parameters('apnsEndpoint')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('notificationHub_namespace'))]"
]
}
But I got error without details BadRequest
{
"code": "DeploymentFailed",
"details": [
{
"code": "BadRequest",
"message": {
"error": {
"message": "Bad Request",
"code": "BadRequest"
}
}
]
}
I test my parameters from azure portal and it works - so I assume that parameters are correct.
The question is how to deploy NotificationHub with ApnsCredentials using ARM?
Above arm template is correct.
My parameters were bad.
I found solution by previewing requests sent from azure portal.
I was using endpoints for certificates:
Sandbox endpoint: gateway.sandbox.push.apple.com,
Production endpoint: gateway.push.apple.com
Endpoints for token authorization are different :
Sandbox Endpoint: https://api.development.push.apple.com:443/3/device
Production Endpoint: https://api.push.apple.com:443/3/device
Here you can find details:
https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-http2-token-authentification#configure-via-management-api-rest

Resources