Loggin into COUCHDB using curl - database

I would like to get the .json data from a specific http. The data I need for this is on a COUCHDB. Now when I curl http://example.com:port/mydatabase I get the message "You are not authorized to access this db. "I have now received header data with 1: roles, 2:username and a token. How do I enter my curl to get access to the database.
Tanks from Student.

The first thing to check is that you have created credentials for your database installation. You can read about that in the docs here. Once that's in place, you can do basic auth with curl by passing your credentials as part of the URL:
curl 'https://USERNAME:PASSWORD#example.com:port/mydatabase/_all_docs'
More notes on how to use curl with couchdb are available here.

Related

What is the coversation log URL for IBM Chatbot assistant?

What is the url to see the conversation logs?
I have tried https://gateway.watsonplatform.net/assistant/api/v1/workspaces/{workspace_id}/logs?version=2018-09-20&filter=(response_timestamp<2019-01-31T04:00:00.000Z)
but I am not able to see the input from the user.
The URL is correct, but the params may not. The brackets in the filter param are not needed, and the whole filter param has to be url escaped. Furthermore, you have to authenticate to use this endpoint.
curl -u "apikey:{apikey}" "https://gateway.watsonplatform.net/assistant/api/v1/workspaces/{workspace_id}/logs?version=2018-09-20"
See here for details. Furthermore, the Botium CLI has a command to automate the download of the conversation log, for example:
botium-cli import watson-logs --watsonfilter "response_timestamp>=2018-10-21, response_timestamp<2018-10-29"

How to exercise secured app engine hosted REST APIs using curl?

Let us assume that there is an app engine standard python app hosted at https://xyz.appspot.com and that its URLs are protected with:
login: admin
secure: always
How can I exercise the APIs using curl? I guess the real question is how can I authenticate to the app using curl. If the app is used from a browser, one is redirected to Google login but I am wondering how I can simulate the same from curl.
Any help is greatly appreciated.
Thanks,
Raghu
One way would be to do the authentication in browser first, and then copy the cookie from there to curl. For example in Chrome, you can open the devtools (F12) and select the Network tab.
When you access your secure resource it will appear there. Then you can right click -> Copy -> Copy as cURL (bash).
This will give you a cURL command that is authorized to call your secure resource.
Based on the suggestion from #Erfa, I visited the site in Chrome while keeping the dev tools open.
The browser takes you through login procedure and the site appears. At this point, right click on the GET request in "Network" tab and select "Save as HAR with Content" which saves the API information in a text file.
In the file, you will find a cookie that is being sent with the GET request. You can now use this same cookie with curl as follows:
$ curl --cookie "NAME=VALUE" <URL>
You can use a combination of Cloud Endpoints and API Key.
In this article https://cloud.google.com/endpoints/docs/frameworks/python/restricting-api-access-with-api-keys-frameworks from Google Cloud Platform you have an example of how to use curl authentication with this combination:
If an API or API method requires an API key, supply the key using a
query parameter named key, as shown in this cURL example:
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"message": "echo"}' \
"${HOST}/_ah/api/echo/v1/echo_api_key?key=${API_KEY}
where HOST and API_KEY are variables containing your API host name and API key,
respectively. Replace echo with the name of your API, and v1 with the
version of your API.

web app with MEAN stack

I have to deploy a login page with profile with node js, mongodb and angularjs. Can you suggest me an example of MEAN in mongoDB and not in mongoose? I have to store credentials user's with mongodb and I have to send user's data to the client, not in json.
Thanks
Mongoose is a interface to connect to mongo databases in NodeJs environment. To perform login and send data to client, you can follow these steps:
Send a login request to server.
Verify the user credentials and send a token back to user for proceed with further requests for client data. For this, you can use JWT.
Put an interceptor in angularjs which will automatically associate the token in header with each request corresponds to valid user.
At server end, you can check whether requests consist of token or not. If not, you can send unauthorized in response (401).

Create Google Cloud Project with Cloud Resource Manager API

I'm trying to create a new project in the Google Cloud Platform using the Cloud Resource Manager API.
It all works fine when I use it through the API explorer however I don't quite understand how to use it as an http request outside of API Explorer.
I run the request like this:
curl -H "Content-Type: application/json" -X POST -d '{"name": "project example","projectId": "my-project-example-1234"}' https://cloudresourcemanager.googleapis.com/v1/projects?fields=response&key={MY_APY_KEY}
Response:
{
"error": {
"code": 401,
"message": "The request does not have valid authentication credentials.",
"status": "UNAUTHENTICATED"
}
}
The documentation says that this request requires an OAuth scope and that's when things get confusing to me.
Reading the documentation I could not understand how one of the required OAuth scopes can be passed with the URL when making the http request to the rest API which I'm only assuming is what I'm missing.
Rather than just tell you how to test with a working token, I'm going to try to more broadly answer what you're aiming to do.
At a pretty high level, you will need to:
Enable the Resource Manager API for your Cloud Console project.
Create an OAuth client ID for Web applications in the Cloud Console. You will need to register your authorized redirect URI. This is where your app will get the OAuth response back from Google when the end user authorizes your app. Note the client ID, you will need that next.
Start the OAuth flow by assembling your URL:
https://accounts.google.com/o/oauth2/v2/auth?
response_type=code&
client_id=<123456789example>.apps.googleusercontent.com&
scope=https://www.googleapis.com/auth/cloudplatformprojects&
redirect_uri=http://<YOUR-APP-URL>/<YOUR-OAUTH-HANDLER>
Replace in that URL the client ID and the redirect URI. I assume you'd have a button or link on your site where you would have the user click to start this flow.
Code your OAuth handler. Some more in-depth code for doing this in Go can be gleaned from this Go Sample, which was originally for G+ sign-in but much of the logic is going to be the same. You are going to get a code query parameter passed to your application, the value is a one-time authorization code that your application must exchange for your OAuth tokens that you use to make API calls on behalf of the user.
If appropriate for your app and situation, securely store your tokens for use later or for processing while your user is not active on your site (might be appropriate for batch processing).
Now that you have an access token, you can pass that to the Resource Manager API and create projects on behalf of the user. You might use the Go client library or you could call the HTTP endpoints directly in your code.
If you want more testing with curl, I'd follow the process that we wrote up accessing the App Engine Admin API. Substitute Admin API URLs and names for Resource Manager and you've got the overall flow. The difference from what's above, is I used a code flow above because I assume you want server-side and possibly refresh tokens if you need to be able to make these API calls while the user is not active on your site.
Like Alex says, you ask for scopes during OAuth authentication. One way to easily authenticate and obtain a Oauth access token is doing:
gcloud beta auth application-default login --scopes=https://www.googleapis.com/auth/cloudplatformprojects
As you can see, you can specify the scopes you want to gcloud and it will take care of authentication for you.
Then, you should be able to create a project calling:
curl -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud beta auth application-default print-access-token)" -X POST -d '{"name": "project example","projectId": "my-project-example-1234"}' https://cloudresourcemanager.googleapis.com/v1/projects?fields=response
Here, you are passing the access token obtained when you made Oauth authentication. This should be taken care of by the client libraries for you when you get the application default credentials.

How to tell if instance specfic Salesforce URL is from Sandbox or Production?

How to tell if instance specific Salesforce URL is from Sandbox or Production, if I have the URL and Session Id only?
If you know the instance & sessionId, then you can call the REST api's discovery service at {instance}/services/data/v25.0 passing the sessionId in a Authorization header, e.g. using curl this would be
curl -v -H "Authorization: OAuth {sessionId}" https://{instance}/services/data/v25.0/
This returns you the discovery data, including the users Identity Id, e.g.
"id": "https://login.salesforce.com/id/00D300000000QSfEAM/00530000000dImzAAE"
If the host is login.salesforce.com its production, if its test.salesforce.com its sandbox.

Resources