How to fetch user using the TrueVault API - truevault

I'm trying to fetch a user from the TrueVault API using curl.
I've been using the following curl command (as per the documentation):
curl https://api.truevault.com/v2/users/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx7ce \
-X GET \
-u API_KEY:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx461"
The credentials:
user_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx7ce
api key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx461
Every time I send the request I'm getting an error:
"error": {
"code": "AUTH.UNSUCCESSFUL",
"message": "Authentication Failure.",
"type": "invalid_request_error"
},
"result": "error",
"transaction_id": "xxxxxxxx-xxxx-xxxx-xxxx-3ba883e31f99"
So I wanted to check if maybe I'm doing wrong or might be something else.
This user has all permissions (Create, Read, Update, Delete).

It looks like your Auth Header is malformed. You can read more about how to build the Auth Header here: https://docs.truevault.com/overview#authentication.
For a simple curl you can use the -u option instead of building the base64 Basic Auth header. -u expects username:password, but TrueVault's API is token-based so they want you to do "$API_KEY:". Note the empty second component! That trailing : is critical.
Try this:
curl https://api.truevault.com/v2/users/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx7ce \
-X GET \
-u "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx461:"

Related

Prefect2.0 How to trigger a flow using just curl?

Here is my dead simple flow:
from prefect import flow
import datetime
#flow
def firstflow(inreq):
retval={}
retval['type']=str(type(retval))
retval['datetime']=str(datetime.datetime.now())
print(retval)
return retval
I run prefect orion and prefect agent.
Make a trigger using web ui (deployments run) ... the agent succesfully pull and do the job.
My question is how to do the trigger using just curl?
Note : I already read http://127.0.0.1:4200/docs.
but my lame brain couldn't find how to do it.
note:
Lets say my flow id is : 7ca8a456-94d7-4aa1-80b9-64894fdca93b
Parameters I want to be processed is {'msg':'Hello world'}
blindly Tried with
curl -X POST -H 'Content-Type: application/json' http://127.0.0.1:4200/api/flow_runs \
-d '{"flow_id": "7ca8a456-94d7-4aa1-80b9-64894fdca93b", "parameters": {"msg": "Hello World"}, "tags": ["test"]}'
but prefect orion say
INFO: 127.0.0.1:53482 - "POST /flow_runs HTTP/1.1" 307 Temporary Redirect
Sincerely
-bino-
It's certainly possible to do it via curl but it might be painful especially if your flow has parameters. There's much easier way to trigger a flow that will be tracked by the backend API - run the flow Python script and it will have exactly the same effect. This is because the (ephemeral) backend API of Prefect 2.0 is always active in the background and all flow runs, even those started from a terminal, are tracked in the backend.
Regarding curl, it looks like you are missing the trailing slash after flow_runs. Changing your command to this one should work:
curl -X POST -H 'Content-Type: application/json' http://127.0.0.1:4200/api/flow_runs/ \
-d '{"flow_id": "7ca8a456-94d7-4aa1-80b9-64894fdca93b", "parameters": {"msg": "Hello World"}, "tags": ["test"]}'
The route which might be more helpful, though, is this one - it will create a flow run from a deployment and set it into a scheduled state - the default state is pending, which would cause the flow run to be stuck. This should work directly:
curl -X POST -H 'Content-Type: application/json' \
http://127.0.0.1:4200/api/deployments/your-uuid/create_flow_run \
-d '{"name": "curl", "state": {"type": "SCHEDULED"}}'

Converting cURL command to JavaScript

I'm trying to call an Instagram API call from my server (nodeJS) and I am not sure how to do so.
curl -X POST https://api.instagram.com/oauth/access_token \
-F client_id=123456... \
-F client_secret=123abc... \
-F grant_type=authorization_code \
-F redirect_uri=https://google.sg/ \
-F code=123abc
This command returns the desired output when I run it on the command line, but I can't seem to find a way to do the same in JavaScript. Here is what I've tried:
axios
.post("https://api.instagram.com/oauth/access_token", {
client_id: 123456...,
client_secret: "123abc...",
grant_type: "authorization_code",
redirect_uri: "https://google.sg",
code:
"123abc...",
})
This is what is logged in by the catch block:
data: {
error_type: 'OAuthException',
code: 400,
error_message: 'Missing required field client_id'
}
I think -F refers to form data, but I can't seem to find a way to do that in axios.
edit: I've tried it with just client_id, and it returns the same error.
edit 2: I don't think this is a fix but Postman Agent has a nifty function to translate the HTTP request into code:
It can be accessed via Code on the right.
Just see that in your CURL request you have the redirect_uri: https://google.sg/
And in your axios params you have: https://google.sg
You are missing a / in the axios parameter.
The way Oauth2 works is that it appends parameters to the redirect_uri specified in your api settings, so if you set it to https://google.sg/, it is expected that it is indeed the same url, without any changes.
The response you should be getting would be:
https://google.sg/access_token=#xxxx
As you had specified, the response would be different, like so:
https://google.sg?access_token=#xxxx
That is not only a non-valid URL, but it also doesn't match the one you specified.
For this reason it is recommended that you set a standard path, for example:
https://google.sg/oauth
So in the end you would get:
https://google.sg/oauth?access_token=#xxxx

Paypal integration issue with KillBill in a node app

I am trying to integrate paypal payment gateway in my Node app in which i'm calling KillBill api provided for Paypal gateway in itsw documentation it is described that we will recieve a url in location header.
But on hitting it in postman i'm recieving html of that page instead of its url in Headers with key "location".
How to integrate it in node app so that if i make request to its url i get back the url of page to be redirected and can do anything i want.
KillBill docs link https://github.com/killbill/killbill-paypal-express-plugin
following is the api i'm using of paypal integration provided by kill bill
curl -v \
-X POST \
-u admin:password \
-H 'X-Killbill-ApiKey: bob' \
-H 'X-Killbill-ApiSecret: lazar' \
-H 'X-Killbill-CreatedBy: admin' \
-H 'Content-Type: application/json' \
-d '{
"kb_account_id": "13d26090-b8d7-11e2-9e96-0800200c9a66",
"currency": "USD",
"options": {
"return_url": "http://www.google.com/?q=SUCCESS",
"cancel_return_url": "http://www.google.com/?q=FAILURE",
"billing_agreement": {
"description": "Your subscription"
}
}
}' \
http://127.0.0.1:8080/plugins/killbill-paypal-express/1.0/setup-checkout
I have sort it some way i just converted that response html into a circular Json array and than found the URL of that html page in some index of that array as a key value pair of an object. Don't know that if it is a perfect solution but it works fine and according to my requirements.

create repo using github api (only curl and no oauth)

I'm trying to create a github repo using the v3 api, but I always get a Not Found error. I want to do it only with curl and without oauth. This is what I'm trying:
curl -u myusername https://api.github.com/users/repos -d '{"name": "reponame"}'
What am I missing?
You can't do it without an Access Token.
Also, please feel free to look at my GitHub open source project Git-Captain.
I created a web-application with a Node.js back-end and HTML/JS front-end that you can setup to have an API do many of these calls for you. It has a step-by-step for a windows server and I'll be adding a Linux step-by-step soon.
It would only take a slight tweak to the project to add a new end-point to the source to do this for you.
To answer your question,
The GitHub API documentation explains exactly how to do what you are requesting on this link.
Giving this example:
as you requested in CURL and obviously replace the token "5199..." with your own:
curl -i -H "Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" \
-d '{ \
"name": "blog", \
"auto_init": true, \
"private": true, \
"gitignore_template": "nanoc" \
}' \
https://api.github.com/user/repos
OR
Not in CURL and according to this StackOverflow question you can do the following:
https://api.github.com/orgs/<organisation_name>/repos?access_token=<generated token>
or
https://api.github.com/users/<username>/repos?access_token=<generated token>
In body, pass this as a payload:
{
<br/>"name": "<Repo Name>",<br/>
"description": "<Whateveryour description is>",<br/>
"homepage": "https://github.com",<br/>
"private": false,<br/>
}
You can get a "personal access token in GitHub" by going to Settings->Developer Settings-> Personal Access Tokens->Generate new token
OR do all of the following
Write a script (let's call this script #1) that takes the username,password, and repoName as a parameter.
That script will call script #2, which is curl -u ' USER-NAME-HERE' https://api.github.com/user/repos -d '{"name": "REPO-NAME-HERE"}' which will prompt for your user password,
have your script #1 listen for script #2's response and then have it enter in the password which the user passed in as a parameter in script#1
Finally programmatically hit enter which fires off the curl to create your repo.
UPDATE*
So for some reason, the CURL won't work at all, but the Git-Hub API end point https://api.github.com/user/repos does indeed work. Using POSTMAN, I was able to create a new POST with the URL being https://api.github.com/user/repos and the BODY set to:
{
"name": "Hello-World",
"description": "This is your first repository",
"homepage": "https://github.com",
"private": false,
"has_issues": true,
"has_projects": true,
"has_wiki": true
}
Then I went to the 'Authorization' section of postman and under 'Type' I selected "Basic Auth" entered my username and password.
Clicked update request and then send and my repo was created!

Access Public URLs from IBM Cloud storage

I have created a IBM cloud Object storage service and i have created objects i.e image files in it.
I am looking for the steps to access the images as public URLs. I did some initial research and found there are cURL commands using swift Client to do this.
Reference links
How to access files in container in Object Storage Service in Bluemix? AND
Public URLs For Objects In Bluemix Object Storage Service
from the above links, it says the following steps
Set up the swift CLI . Can you link me the steps to set up Swift CLI ? ( the link in the reference link dosen't work anymore ).
2.Change the container ACL to read with following PUT request
curl -X PUT "https://dal.objectstorage.open.softlayer.com/v1/AUTH_123/mycontainer" \
-H "X-Auth-Token: token123" \
-H "X-Container-Read: .r:*"
But i am not sure what to input on X-Auth-Token header ? i have the following information from the service credentials of COS.
{
"apikey": "X7aDm6yu123123hXwqvq1231232HgOtIGeZiAOEg",
"endpoints": "https://cos-service.bluemix.net/endpoints",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/f9aabca54c702be8386b2a3f9815b4e4:d145a33e-e8b1-446f-a87d-69431eaec0b1::",
"iam_apikey_name": "auto-generated-apikey-bed16ed5-1373-47bc-b268-5e0f521bc802",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/f9aabca54c702be8386b2a3f9815b4e4::serviceid:ServiceId-36c373a0-4bb9-4316-bc4b-86ea4c98dcd7",
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/f9aabca54c702be8386b2a3f9815b4e4:d145a33e-e8b1-446f-a87d-69431eaec0b1::"
}
Any help would be really appreciated. Thanks
The bearer token is from IAM.
https://console.bluemix.net/docs/services/cloud-object-storage/getting-started-cli.html#gather-key-information
See this doc on generating pre-signed urls (temporary).
https://console.bluemix.net/docs/services/cloud-object-storage/api-reference/api-reference-objects.html#object-operations
To do a one-off request like that, you can get oauth tokens from the command line using ibmcloud iam oauth-tokens. To specifically get an IAM Token, I use:
export IAM_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk ' {print $4} '`
Then follow that up with your cURL command:
curl -H "Authorization: Bearer $IAM_TOKEN" ...
An application should request tokens based on the apiKey as mentioned.
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Cache-Control: no-cache" -d 'apikey=<your api key here>&grant_type=urn:ibm:params:oauth:grant-type:apikey' "https://iam.bluemix.net/identity/token"
Here's an example using NPM's request-promise:
const response = await rp({
url: 'https://iam.bluemix.net/identity/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
method: "POST",
body: `apikey=${apiKey}&grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey`,
json: true
});
const token = response.access_token;

Resources