rundeck - api - ansible - uri - Add Key passwd - Value not good - api

I try to add a new key password, facing the issue with the API. The key is successfully created. But, when is used is not good value.
I try to generate the key with Postman, and the key is created but the value is not correct. When I use the same value manually on the interface then it works fine.
I deleted before the key (manually)
postman:
curl --location --request POST 'https://rundeck.dev.xxxxxx.com/api/11/storage/keys/project_name/gitlab?authtoken=FdMORu02flT2R5zI' \
--header 'Content-type: application/x-rundeck-data-password' \
--header 'Cookie: AWSALB=D6Kpid4U/o7uHy9G0Pg40uvILs1toq367tPzPiCskEha7YGM3eCJldNnKyMFYBrkwOXIyvVmKAsIe9yIRm/8xOX/0mj4LIRy2wMl3qYpOvXKw3x9e+rXnjd8gEjX; AWSALBCORS=D6Kpid4U/o7uHy9G0Pg40uvILs1toq367tPzPiCskEha7YGM3eCJldNnKyMFYBrkwOXIyvVmKAsIe9yIRm/8xOX/0mj4LIRy2wMl3qYpOvXKw3x9e+rXnjd8gEjX' \
--data-raw 'XKmB1wkjsdfikjkHkKwCEW'
I try to add SCM with the key generated but still is not working. However, when I create manually the key with the same name and value the SCM import is working.
I have the same error with ansible with URI.
I deleted before the key (manually)
I create a playbook to access rundeck API
- name: "Create Keys {{ project_name }} - gitlab"
uri:
url: "{{ RD_URL }}{{ API_11 }}/storage/keys/{{ project_name }}/gitlab?authtoken={{ RD_TOKEN }}"
method: POST
body_format: raw
validate_certs: no
status_code: [201, 409]
return_content: true
headers:
Content-Type: application/x-rundeck-data-password
X-Rundeck-Auth-Token: "{{ RD_TOKEN }}"
body: '{{ GITLAB_TOKEN }}'

You can create the password via API 40 and Rundeck 3.4.9 with the following call:
#!/bin/sh
# protocol
protocol="http"
# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="40"
rdeck_token="hcFPFbJHFIqerwaRsWtuhPnPAIUoY4Kt"
# api call
curl --location --request POST "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/storage/keys/mypass" \
--header "X-Rundeck-Auth-Token: $rdeck_token" \
--header "Content-Type: application/x-rundeck-data-password" \
--data-raw "12345"
Also, I created a Job example to test the password content:
- defaultTab: nodes
description: ''
executionEnabled: true
id: 5658bb13-f9e9-494b-839c-d18f25057a4e
loglevel: INFO
name: HelloWorld
nodeFilterEditable: false
options:
- name: opt1
secure: true
storagePath: keys/mypass
valueExposed: true
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: echo ${option.opt1}
keepgoing: false
strategy: node-first
uuid: 5658bb13-f9e9-494b-839c-d18f25057a4e
Running the job, you can see the password value.
Also tested using the SCM config.
So, make sure that you're pointing to the right key in your SCM config and ensure to use the latest API version (40 at this moment) in your API Call.

Related

Run a job via the rundeck API with parameters in postman

I am trying around with the Rundeck API. I was able to get a simple Job running. But now I am trying to run a job, that has a job option. The job option for this job is an IP, so Rundeck starts the Job only on this machine.
When I use the API, I don't know how to set the parameter. I am using the tool Postman, where I only receive the message "Job options were not valid: Option 'IP' is required".
I looked it up on the rundeck documentation and I found this for postman
In the rundeck documentation is this example:
argString: argument string to pass to the job, of the form: -opt value -opt2 value ....
How can I use it for my IP?
Using this Rundeck Job Definition:
- defaultTab: nodes
description: ''
executionEnabled: true
id: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
loglevel: INFO
name: HelloWorld
nodeFilterEditable: false
options:
- name: opt1
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: echo "hello ${option.opt1}"
keepgoing: false
strategy: node-first
uuid: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
And based on this, you can do it by putting the options in JSON format (json body) on Postman:
{
"options": {
"opt1":"world"
}
}
This is the code snipped in cURL format:
curl --location --request POST 'pop-os:4440/api/38/job/9f04657a-eaab-4e79-a5f3-00d3053f6cb0/run' \
--header 'X-Rundeck-Auth-Token: GuaoD6PtH5BhobhE3bAPo4mGyfByjNya' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=node01tz8yvp4gjkly8kpj18h8u5x42.node0' \
--data-raw '{
"options": {
"opt1":"world"
}
}'
Check how looks on Postman.

How do you specify the sourceBranch for a Run of Pipelines via the REST API?

I've been trying to run a pipeline for a particular branch of the repository I'm using.
In the UI, there is a convenient option, but I don't understand what to try in the request.
No matter what I do I always run from master.
How do I change that? I tried filling out the repository parameters but to no avail: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0#repositoryresourceparameters
Here is an example request:
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"previewRun": true,
"resources": {
"repositories": {
"refName": "refs/heads/<redacted>"
}
},
"runParameters":
{
"namespace" : "<redacted>",
"image" : "<redacted>",
"tag" : "<redacted>",
"package" : "<redacted>",
"version" : "8.4.4"
}
}'
From your screenshot, it seems that you are using the YAML pipeline.
I have tested your example , and the root cause of this issue is that the request body(data-raw) has some issues.
You could try my sample
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"stagesToSkip":[],
"resources":
{
"repositories":
{
"self":{"refName":"refs/heads/{Branchname}"}
}
},
"templateParameters":
{
"namespace":"{value}",
"image":"{value}",
"tag":"{value}",
"package":"{value}",
"version":"{value}"
},
"variables":{}
}'
Result:
For Http Request (you can test it with Postman)
1. Get pipeline api url like this
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1
Source: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1
Fill in your organization, project and pipelineId.
(all of this can be found in the link when you open your pipeline definition in Azure DevOps)
2. Add Basic Auth headers
key: Authorization, value:"Basic [your azure Person Access Token from Azure Dev Ops with Access to Pipeline goes here]"
Should look like this
"Basic OndzNWdz43FKfjdi98hjKDJFH8kkg9854HJKHF9D8RFEHui4387lkNXE="
And set content type to application/json
like this
key: Content-Type, value: application/json
3. Put this JSON Into Raw Body
{
"templateParameters":{
"inputName":"johnsmith"
},
"resources":{
"repositories":{
"self":{
"refName":"refs/heads/feature/#JIRATask01_Blabla"
}
}
},
"variables":{
}
}
Replace refName value with branch you want to run the pipeline for.
If you have multiple repo pipeline look into this topic (but i haven't tested that solution):
Azure DevOps API to Trigger Multi Repo changing branches

How to invoke AWS lambda while running EventGateway locally

I am trying to invoke an AWS Lambda function from a locally running EventGateway (version: 0.9.1) instance. However, the subscription call is failing due to an "Event Type: http.request not found".
The lambda has been deployed independently using serverless framework, and the ARN has been injected in the registration call:
The lambda is just a hello world type of lambda listening for http request:
functions:
hello-world:
handler: bin/hello-serverless
events:
- http:
path: /hello
method: get
My function registration call looks like this:
curl --request POST \
--url http://127.0.0.1:4001/v1/spaces/default/functions \
--header 'content-type: application/json' \
--data \
'{"functionId": "helloserverless", "type": "awslambda", "provider":{ "arn": "<lambda-arn>", "region": "ap-southeast-2", "accessKeyId": "<my-access-key>", "secretAccessKey": "<my-secret-key"}}'
Now, when I try to subscribe to an event:
--url http://127.0.0.1:4001/v1/spaces/default/subscriptions \
--header 'content-type: application/json' \
--data '{"functionId": "helloserverless", "type": "sync", "path": "/hello", "method": "GET", "eventType": "http.request"}'
I get the following error:
{"errors":[{"message":"Event Type \"http.request\" not found."}]}
Any pointer to the right solution or working example is pretty much appreciated.
If you want to call a function like an endpoint you need to have your application running. There is a plugin called serverless-offline to help you on this.
In case you want to call your function using serverless options, the command is called INVOKE. https://serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/

paypal authentication failure in sandbox

I encounter an issue when I try to use the Paypal sandbox API.
I've created my 2 sandbox accounts (the facilitator and the buyer), and I've created my app to get the credentials.
Then, I use the curl example provided by Paypal to get a token :
curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "my-client-id:my-secret" \
-d "grant_type=client_credentials"
I get a 200 response, with an "access_token".
Then, I use this access token to get another resource, for example :
curl -v -X GET https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true \
-H "Content-Type: application/json" \
-H "Authorization: Bearer the-token-received-above"
Then, I get a 401 error :
{
"name":"AUTHENTICATION_FAILURE",
"message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.",
"links":[{
"href":"https://developer.paypal.com/docs/api/overview/#error",
"rel":"information_link"
}]
}
I don't understand what I'm doing wrong, since I've followed every step decribed in the Paypal doc (at least, I think I have... probably not)
Thanks for your help
curl -v -X GET "https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer the-token-received-above"
Actually had this exact same issue but didn't know what was wrong with my curl. For me, the issue was I forgot to put "Bearer" in the Authorization section.
For this, you are required to wrap the URL with quotation marks.
After get access_token. Please try this
try {
$params = array('access_token' => $jsonResponse->access_token);
$userInfo = OpenIdUserinfo::getUserinfo($params, $this->_api_context);
} catch (Exception $ex) {
ResultPrinter::printError("User Information", "User Info", null, $params, $ex);
exit(1);
}
ResultPrinter::printResult("User Information", "User Info", $userInfo->getUserId(), $params, $userInfo);
Don't forget to add
use PayPal\Api\OpenIdTokeninfo;
use PayPal\Api\OpenIdUserinfo;
That's worked for me.

write ansible-playbook for webservices

How do I use POST with Ansbile
curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json"-u user:A231212123432 "https://www.example.com"
Request Body
{
"a":"1"
"b":"2"
"c":"3"
}
According to the docs it would work like this:
- url: https://www.example.com
method: POST
user: user
password: A231212123432
HEADER_Content-Type: "application/json"
body: '{ "a":"1" "b":"2" "c":"3" }'