I'm developing a internal app that creates the skeleton of a solution according to internal guidelines.
As a improvement, I would like to enable the user to automatically have the solution "formalized" on our DevOps, where he would clone and start coding right away, instead of the current download as ZIP.
In order to do that, i started looking at the azure devops docs, but could not figure out a way to create a repository via API...
How can I do that?
Here is a sample of code we use in a PowerShell script to create repos
$repoBody = #{
name = "YourRepoName"
} | ConvertTo-Json
Invoke-WebRequest -method Post -Headers #{Authorization = "Basic $encodedPat"} -body $repoBody -Uri $projUrl -ContentType "application/json" -UseBasicParsing
You have the Repositories - Create Rest API:
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=5.0
Body:
{
"name": "NewRepository",
"project": {
"id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c"
}
}
This is the API call you are looking for:
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=5.0
Source: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/repositories/create?view=azure-devops-rest-5.0
In addition, if you have the AZ modules loaded in powershell, you can simply execute
az repos create --name "MyNewRepoName" --org "https://dev.azure.com/OrganizationName/" --project "ProjectNameToCreateRepoIn"
To install AZ modules in powershell use command
Install-Module -Name Az -AllowClobber -Scope CurrentUser
With AZ modules installed execute this before creating repo
Set-AzContext -SubscriptionId "YourSubscriptionID
Related
Is there a possibility to download data from IBM Analytics Workspace report/query using REST API ?
I would like to download sych data directly to the program variable using PowerShell/C#.
I have been looking for the answer online for a while but I cannot find satisfying answer leaving alone some code examples.
I would be grateful to get some code examples or links to such.
Best regards.
Pipe Invoke-RestMethod to ConvertTo-Json and then pipe to Out-File. That's a typical workflow for interacting with APIs, if you want to download data to disk.
Presumably there's some authentication needed and presumably you have an API key. So your script would look something like
$Headers = #{
api_key = $MyApiKey
}
$Uri = 'https://cloud.ibm.com/some_service/some_resource_type'
$Result = Invoke-RestMethod $Uri -Headers $Headers
$Result | ConvertTo-Json | Out-File my_data.json
Without knowing what API you want to query, no-one can give you a more specific example.
A better way to submit a question would be "How can I download data with powershell from the Foo API - the docs for this endpoint are at ibm.com/api_docs/how_to_foo"
I write test cases in Visual Studio - Specflow feature file. Post that, I use "AzureDevops Test Connector" to migrate test cases into Azure Devops - Test Plan -> Test Suite(Which are already created in Azure Devops by me).
My requirement is to update, "Area Path" and "Iteration" for the newly created test cases.
I am able to update "Area Path" and "Iteration" for Test Plan and Test suite using Azure Devops Services Rest APIs. But, there is no provision to update these values in Test Case. Any lead will be much appreciated. Below is what i tried. Thanks in advance!
.
PATCH CALL TO UPDATE AREA PATH AND ITERATION PATH - BUT IT IS NOT WORKING | SCREENSHOT FROM POSTMAN
I was able to achieve this by using "work item" instead of "Test Case". Using this, I am able to update all the field values.
Postman - add Content-Type = application/json-patch+json | under headers separately. Keep body as "raw" and "JSON" in drop down.
Azure Devops Work Items Rest API Details
How can I disable an Azure Function using code in C#?
I'm using Azure Functions Runtime version 3.x
I'm implementing a distributed circuit-breaker inspired by Serverless circuit breakers with Durable Entities. When the circuit opens I need to disable a queue-trigged Azure Function, instead of stopping the entire function app.
I see from How to disable functions in Azure Functions that the recommended way to disable a function is to set the AzureWebJobs.<FUNCTION_NAME>.Disabled app setting. But I haven't found an API for doing that in C#. I'm hoping there is something that I can call from my C# code that is equivalent to the Azure CLI's az functionapp config appsettings set command.
I saw similar questions on SO like:
azure set environment variable programmatically to disable an azure function
and How to Enable/Disable Azure Function programmatically
But those have answers from back in 2017 that use kudu APIs to change the disabled property in the function.json file, and I'm hoping that there is a better way to do that now. Especially because the Docs at How to disable functions in Azure Functions say:
The generated function.json file for a class library function is not
meant to be edited directly. If you edit that file, whatever you do to
the disabled property will have no effect.
Unfortunately I was not able to find any documentation as such. The closest I got was
https://learn.microsoft.com/en-us/rest/api/appservice/webapps/createfunction
For instance to create the function :
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}?api-version=2019-08-01
However this documentation also did not take me near to your requirement of updating the Config File. Or I may have overlooked few modules. Request you check further before implementing the below steps
So here's is what I did, I was kind of trying to reverse engineer, I ran the commands in Azure CLI and captured the traces - my thought process - the Azure CLI internally run on python and issues the API request to the Azure.
Ran the below command and captured Fiddler :
az functionapp config appsettings set --name <myFunctionApp> \
--resource-group <myResourceGroup> \
--settings AzureWebJobs.QueueTrigger.Disabled=true
And Yes ! The python process was issuing request to https://management.azure.com to update appsetting :
The set property is sent in the Request Body :
We can hardcode the properties or get it dynamically.
So I ran the below Azure CLI command
az functionapp config appsettings list --name <> --resource-group <>
I was able to see the above properties that was passed along the PUT request
Took the fiddler for the above command
Saw there is a POST Request to the below endpoint :
https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/appsettings/list?api-version=2019-08-01
These are the same set of property bags which are sent as the request bodies in the PUT in order to set the property.
So in your case you will have to request the above end point to get the list of properties. It is json output. Update the value of AzureWebJobs.QueueTrigger.Disabled to True.
Issue the Updated properties using the PUT method along with the headers such as Bearer Token & Content-Type: application/json; charset=utf-8
Request URI :
https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/appsettings?api-version=2019-08-01
Headers :
Authorization: Bearer <> Content-Type: application/json;
charset=utf-8`
Request Body:
{"kind": "<class 'str'>", "properties": }
I hope you will be able to achieve your requirement.
I hope this helps you :)
I don't recommend this for your prod. Pls try and monitor in your Dev env.
I'd like to leverage the new Google TTS using a simple rest request. To that end, I've created a Service Account which downloaded a JSON file containing a private key id, a private key, client email, client id, client_x509_cert_url, etc.
I've also set the environment variable for the system:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", jsonFile);
I then found this sample CURL request to use the WaveNet TTS engine provided by Google:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > writtenfile.txt
I want to create a simple C# webrequest from the above CURL request, but the line "gcloud auth application-default print-access-token" is a problem for me. I cannot install a CLI gcloud instance on this machine. Isn't there some way to setup the webrequest authorization access token from the JSON service account file? Surely I don't HAVE to have gcloud installed.
Looking for code sample demonstrating how to convert CURL code to a C# rest request using the service account json file without gcloud.
In case you don't want to install the gcloud packages, you can execute REST calls by using API Keys. These keys can be created directly in the GCP console and they can be passed as a parameter through the request header; in this way, you can authenticate to the service without the need of gcloud. Additionally, I suggest you to take a look on this guide that contains the steps required to make REST requests with C#.
You can use this Restlet Client tool to test the following example:
REST content Example
Header
https://texttospeech.googleapis.com/v1beta1/text:synthesize?key=<YOUR_API_KEY>
Body
{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}
Finally, in case you want to consume a Service Account JSON file, you can use the Client libraries to create and send your TTS requests to then authenticate them directly from your code; however, this method require to install the TextToSpeech packages.
Does the JIRA SOAP API allow me to link betwen two issues that are in different projects? I have looked online and not found a way to do this. The closest thing that I have seen is the createIssueWithParent method, which creates subissues (I want two issues to be linked, not subissues) and which requires the issues to be in the same project (also not what I want).
Does anyone know of a way to do this?
No easy way in SOAP but I've done this using the RESTful approach and JIRA 4.4, e.g.
#
# Add links to JIRA issues
#
# Matt Doar
# CustomWare
#
# usage: create_links.sh issue_id issue_key
# where the issue_id is the unique id for a JIRA issue, not it's issue key.
# You can see the issue id in the XML view of an issue.
# and issue_key is the other issue to be linked to.
USERNAME=admin
PASSWORD=secret
SERVER_URL="http://localhost:8080"
DASHBOARD_PAGE_URL=$SERVER_URL/secure/Dashboard.jspa
COOKIE_FILE_LOCATION=jiracoookie
# Get the authentication cookie
curl -u $USERNAME:$PASSWORD --cookie-jar $COOKIE_FILE_LOCATION -sS --output /dev/null $DASHBOARD_PAGE_URL
issueid=$1
issuekey=$2
#echo "Linking issue: $issueid and $issuekey"
curl --cookie $COOKIE_FILE_LOCATION --header "X-Atlassian-Token: no-check" -sS --output /dev/null -d "id=$issueid" -d "linkDesc=relates to" -d "linkKey=$issuekey" "$SERVER_URL/secure/LinkExistingIssue.jspa"
rm -f $COOKIE_FILE_LOCATION
I don't think that linking is possible via the SOAP API. I've done this using the XML-RPC API, with the createIssueLink function:
from com.atlassian.jira import ComponentManager
# get issue objects
authenticationContext = ComponentManager.getInstance().getJiraAuthenticationContext()
issueLinkManager = ComponentManager.getInstance().getIssueLinkManager()
# Link parent issue to subtask
issueLinkManager.createIssueLink(issue.getId(),otherIssue.getId(),10003,1,authenticationContext.getUser())