Where do I find the paths value to use with the Xray REST API - Artifact Summary call? - rest

The XRay Rest API Artifact Summary "provides details about any artifact specified by path identifiers or checksum." The documentation ( https://www.jfrog.com/confluence/display/JFROG/Xray+REST+API#XrayRESTAPI-ArtifactSummary ) offers this template:
{
"checksums": [
""
],
"paths": [
""
]
}
This works if I use the SHA256 checksum of the artifact I'm interested in, however I can't determine the syntax to use with the paths tag.
From our Artifactory UI, the artifact ( a docker image's manifest.json file) has this repository Path: REPO_NAME/os/ubuntu20/ubuntu20/20.04.5/manifest.json
Using the SHA256 value for the manifest.json file in the call correctly returns the Artifact Summary json:
curl -ufoo:bar -H "Content-Type: application/json" -d '{"checksums" : ["<SHA256_Artifact_1>"]}' -X POST https://localhost/xray/api/v1/summary/artifact
Unforutnately, using any combination of values in the 'paths' field returns a not indexed/cached in Xray.
API calls:
curl -ufoo:bar -H "Content-Type: application/json" -d '{"paths" : ["REPO_NAME/os/ubuntu20/ubuntu20/20.04.5/manifest.json"]}' -X POST https://localhost/xray/api/v1/summary/artifact
curl -ufoo:bar -H "Content-Type: application/json" -d '{"paths" : ["os/ubuntu20/ubuntu20/20.04.5/manifest.json"]}' -X POST https://localhost/xray/api/v1/summary/artifact
curl -ufoo:bar -H "Content-Type: application/json" -d '{"paths" : ["os/ubuntu20/ubuntu20/20.04.5/manifest.json"], "repo" : "REPO_NAME"}' -X POST https://localhost/xray/api/v1/summary/artifact
curl -ufoo:bar -H "Content-Type: application/json" -d '{"paths" : ["os/ubuntu20/ubuntu20/20.04.5/manifest.json"]}' -X POST https://localhost/xray/api/v1/summary/artifact?repo=REPO_NAME
Returns string:
{"artifacts":[],"errors":[{"identifier":"REPO_NAME/os/ubuntu20/ubuntu20/20.04.5/manifest.json","error":"Artifact doesn't exist or not indexed/cached in Xray"}]}
I'm looking to use the Artifact path (which is known) to request the Artifactory Summary JSON. Any suggestions on how this is to be formatted?

Related

ADO Linking requirement & test case work items with Rest API issue

I'm trying to link a ADO Requirement work item to a ADO Test Case work item. I'm making this call:
curl -u :********** -X PATCH -H "Content-Type: application/json-patch+json" -H "Accept: application/json-patch+json" -d "[{{\"op\": \"test\", \"path\": \"/rev\",\"value\": 3 },{\"op\": \"add\", \"path\": \"/relations/-\", \"value\":\"{\"rel\": \"System.LinkTypes.Dependency-forward\",\"url\": \"https://***.***.com/{Organisation}/_apis/wit/workItems/{ID}\",\"attributes\": {\"comment\": \"Making a new link for the dependency\"}}}}]" https://***.***.com/{Organisation}/{Project}/_apis/wit/workItems/{ID}?api-version=6.0
as per: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/update?view=azure-devops-rest-7.1#add-a-link
But I'm having this error:
{"$id":"1","innerException":null,"message":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}
I found my answer, the JSON was badly parse. I used a online JSON linter to fix it. https://jsonlint.com/
curl -u :********** -X PATCH -H "Content-Type: application/json-patch+json" -H "Accept: application/json-patch+json" -d "[{\"op\": \"add\", \"path\": \"/relations/-\", \"value\":{\"rel\": \"Microsoft.VSTS.Common.TestedBy-Forward\",\"url\": \"https://***.***.com/{Organisation}/_apis/wit/workItems/{ID}\",\"attributes\": {\"comment\": \"Making a new link for the dependency\"}}}]" https://***.***.com/{Organisation}/{Project}/_apis/wit/workItems/{ID}?api-version=6.0

How do I download a file from a GitHub draft

I am using AppVeyor to set up the CI for a GitHub repository and upload the build artifacts to a draft named CI builds. The file is e.g. located under
https://github.com/an_organisation/a_project/releases/tag/untagged-1111aaaacccc0000dddd/filename.tar.gz
and can be accessed and downloaded from a browser.
Now I would like to access those uploaded artifact from another AppVeyor project (i.e. an appveyor.yml script). I tried without success to download with AppVeyor DownloadFile command, curl, and wget using the following commands
set DOWNLOAD_FILENAME=filename.tar.gz
set DOWNLOAD_ADDRESS=https://github.com/an_organisation/a_project/releases/download/untagged-1111aaaacccc0000dddd/$DOWNLOAD_FILENAME
wget --header "Authorization: token $GH_AUTH_TOKEN" --output-document=$DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS
wget --auth-no-challenge --header "Accept:application/octet-stream" --output-document=$DOWNLOAD_FILENAME "$DOWNLOAD_ADDRESS?access_token:$GH_AUTH_TOKEN"
curl -fsSL -G --user "$APPVEYOR_ACCOUNT_NAME:$GH_AUTH_TOKEN" -o $DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS
curl -fsSL -G -H "Authorization: token $GH_AUTH_TOKEN" -H "Accept: application/octet-stream" -o $DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS
curl -fsSL -G -H "Authorization: token $GH_AUTH_TOKEN" -H "Accept: application/octet-stream" -o $DOWNLOAD_FILENAME https://api.github.com/repos/an_organisation/a_project/releases/download/untagged-1111aaaacccc0000dddd/
Slowly I get a feeling that a file download from a draft via GitHub API or download link is not possible.
What is the correct command to download such a file?
TLDR Use the Get Release asset API with header Accept: application/octet-stream :
curl -OJ -L -H "Accept: application/octet-stream" \
-H "Authorization: Token $YOUR_TOKEN" \
"https://api.github.com/repos/$REPO/releases/assets/$ASSET_ID"
You need to have the assetID. In order to have it you need the releaseID if you have not already this information use GET /repos/:user/:repo/releases :
curl -s -H "Authorization: Token $YOUR_TOKEN" \
"https://api.github.com/repos/$REPO/releases" | jq '.[] | {(.name): .id}'
Then get the assets IDs use GET /repos/:user/:repo/releases/:release_id :
curl -s -H "Authorization: Token $YOUR_TOKEN" \
"https://api.github.com/repos/$REPO/releases/$RELEASE_ID" | \
jq -r '.assets[] | {(.id |tostring): .name}'
Then once you have assetID (maybe you already had it btw) you can finally use GET /repos/:user/:repo/releases/assets/:asset_id with header Accept: application/octet-stream. From the documentation :
To download the asset's binary content, set the Accept header of the
request to application/octet-stream. The API will either redirect the
client to the location, or stream it directly if possible. API clients
should handle both a 200 or 302 response.
The following download the file locally :
curl -OJ -L -H "Accept: application/octet-stream" \
-H "Authorization: Token $YOUR_TOKEN" \
"https://api.github.com/repos/$REPO/releases/assets/$ASSET_ID"

Post image object Clarifai rest api swift

I want to upload an image that captured in swift application so the image as object I need to do this thru http request
First I tried to do that with curl but I got an error that the string is too long second I tried with the example code that published in the site and that not works
Code example from the site:
curl -X POST
-H 'Authorization: Key YOUR_API_KEY'
-H "Content-Type: application/json"
-d '
{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/demographics.jpg"
}
}
}
]
}'
https://api.clarifai.com/v2/models/c0c0ac362b03416da06ab3fa36fb58e3/outputs
I want to upload an image as object UIImage that captured in swift, not as URL
Try the following curl command:
curl -X POST \
-H "Authorization: Key YOUR_API_KEY" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d '{"inputs":[{"data":{"image":{"url":"https://samples.clarifai.com/demographics.jpg"}}}]}' \
https://api.clarifai.com/v2/models/c0c0ac362b03416da06ab3fa36fb58e3/outputs
It seems to have worked for me.

Create topic in Message-Hub via curl command

I am trying to create a topic in Message-Hub using a curl command.
I followed this yaml: https://github.com/ibm-messaging/message-hub-docs/blob/master/kafka-administration-api/KafkaTopicManagement.yaml
I'm getting HTTP 405 Method Not Allowed when running the following:
curl -X POST --tlsv1.2 -vk -H "Content-Type: application/vnd.kafka.binary.v1+json" -H "X-Auth-Token: apikey from the environment variable of my app" https://kafka-rest-prod01.messagehub.services.us-south.bluemix.net/topics -d "{ \"TopicCreateParam\" { \"name\": \"my.test\" }}"
Thanks for any help.
#jd76 three problems here:
your URL is missing the /admin/ path
your content-type should just be plain json
TopicCreateParam is just the name of the type in the swagger yml.
Try:
curl -H "Content-Type: application/json" -H "X-Auth-Token: apikey from the environment variable of my app" -d "{ \"name\": \"my.test\" }" https://kafka-rest-prod01.messagehub.services.us-south.bluemix.net/admin/topics

View individual deployment status in Wildfly with curl/API

I'm very new to Wildfly but I need to set up automated monitoring of individual deployment status via the API.
In the same way that I can view the server state with curl, eg:
curl --insecure --digest 'https://admin:password#localhost:9993/management' --header "Content-Type: application/json" -d '{"operation":"read-attribute","name":"server-state","json.pretty":1}'
Will return:
{
"outcome" => "success",
"result" => "running"
}
In the same way the from the jboss-cli, I issue:
:read-attribute(name=server-state)
And get the same result.
So, from the CLI, if I issue the following command to get the status of a specific deployment:
/deployment=bob :read-attribute(name=status)
I get the following result:
{
"outcome" => "success",
"result" => "OK"
}
But I can't work out what curl command will give me that result. I've read through a tonne of documentation and either it doesn't exist or I'm looking in the wrong spot. I've tried:
curl --insecure --digest 'https://password#localhost:9993/management' --header "Content-Type: application/json" -d '{"deployment":"bob","operation":"read-attribute","name":"status","json.pretty":1}'
but that didn't work. Any ideas?
Thanks,
Mark J.
You need to add an array for the address attribute and move the "deployment":"bob" in the array.
curl --insecure --digest 'https://password#localhost:9993/management' --header "Content-Type: application/json" -d '{"operation":"read-attribute", "address":[{"deployment":"bob"}],"name":"status","json.pretty":1}'
The address is a name/value pair object for the path the attribute you want to read. For example if you wanted to see the all the handlers associated with the root logger you could execute the following.
curl --insecure --digest 'https://password#localhost:9993/management' --header "Content-Type: application/json" -d '{"operation":"read-attribute","address":[{"subsystem":"logging"},{"root-logger":"ROOT"}],"name":"handlers","json.pretty":1}