I am trying to upload my custom plugin to datafusion using CDAP RESTAPI reference. I followed the steps as per documentation but I still didn't find the way to add the plugin JSON file using REST API.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" "${CDAP_ENDPOINT}/api/v3/namespaces/vega_demo/artifacts/example" -H "Artifact-Extends: system:cdap-data-pipeline[6.0.0,10.0.0-SNAPSHOT)/system:cdap-data-streams[6.0.0,10.0.0-SNAPSHOT)" --data-binary #/path/to/example-1.0.0-SNAPSHOT.jar #/path/to/example-1.0.0-SNAPSHOT.json
Artifact added successfullycurl: (6) Could not resolve host:
Plugin is loaded but the config json file is not loaded causing errors in plugin
Per the command used, I suggest to verify if you are setting correctly the endpoint.
export INSTANCE_ID=your-instance-id
export CDAP_ENDPOINT=$(gcloud beta data-fusion instances describe \
--location=us-central1 \
--format="value(apiEndpoint)" \
${INSTANCE_ID})
Per the official CDAP documentation, it seems that the endpoint should not include the part api before v3.
Also, if your instance belongs to Basic edition, the namespace is default; otherwise, when using Enterpise edition you can create the namespace.
When using the curl method, it seems you need to add the config information within the headers due this method doesn't include the json load
On the other hand, if you are having issues to use curl, I would suggest to use the UI.
Taking this example to upload the plugin mysql-connector-java-5.1.35.jar to Data fusion with curl, the configuration file should be like:
{
"parents": [ "system:cdap-data-pipeline[6.1.1,6.1.1]", "system:cdap-data-streams[6.1.1,6.1.1]" ],
"plugins": [
{
"name": "mysql",
"type": "jdbc",
"className": "com.mysql.jdbc.Driver"
}
]
}
due using curl you can only upload the jar file, to include the information from the configuration file, you should use the HTTP Headers to include this information as this:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
"${CDAP_ENDPOINT}/v3/namespaces/default/artifacts/example" \
-H 'Artifact-Plugins: [ { "name": "mysql", "type": "jdbc", "className": "com.mysql.jdbc.Driver" } ]' \
-H "Artifact-Version: 5.1.35" \
-H "Artifact-Extends: system:cdap-data-pipeline[6.1.1, 6.1.1]/system:cdap-data-streams[6.1.1, 6.1.1]" \
--data-binary #mysql-connector-java-5.1.35.jar
Related
I am testing AWS Config APIs using postman and cannot figure out root cause of 403 forbidden error. The authorization is setup using AWS Signature (4) with the awsAccessKeyId and awsSecretAccessKey of the user who has following policies attached:
AWSConfigRoleForOrganizations, AWSConfigRole, AWSConfigUserAccess
and AWSConfigRulesExecutionRole
curl --location --request POST 'https://config.us-west-2.amazonaws.com/?Action=ListDiscoveredResources&AUTHPARAMS&Version=2010-05-08' \
--header 'X-Amz-Content-Sha256: {generatedHash}' \
--header 'X-Amz-Date: 20200531T194002Z' \
--header 'Authorization: AWS4-HMAC-SHA256 Credential={accessKeyId}/20200531/us-west-2/config/aws4_request, SignedHeaders=content-length;host;x-amz-content-sha256;x-amz-date, Signature={signature}' \
--header 'Content-Type: text/plain' \
--data-raw '{
"resourceType": "AWS::EC2::Instance"
}
I cannot find any example of URL parameter or HTTP header requirements for AWS Config API online. Has anyone been able to successfully authentication with AWS Config API if so, provide an example of Parameters or Request Header?
I was able to successfully fix the 403 forbidden error. The Parameter and HTTP header blow work properly and return the response 200:
curl --location --request POST 'https://config.us-west-2.amazonaws.com/?Action=ListDiscoveredResources&AUTHPARAMS&Version=2010-05-08' \
--header 'Content-Type: application/x-amz-json-1.1' \
--header 'X-Amz-Target: StarlingDoveService.ListDiscoveredResources' \
(omitted rest of header for simplicity)
Having said that, I am still not sure about 'X-Amz-Target: StarlingDoveService.ListDiscoveredResources'. There is no mention of it in in AWS documentation for AWS Config API. Stumbled upon it from the AWS discuss forum by luck.
I have tried to use Django basic Authentication feature to verify username(test) and password(test).
It works from my local:
curl -H 'Accept: application/json; indent=4' -u test:test 'http://127.0.0.1:8000/api/checkuser/'
{
"detail": "Account authorized."
}
But it failed from production site:
curl -H 'Accept: application/json; indent=4' -u test:test 'https://production.fake/api/checkuser/'
{
"detail": "Authentication credentials were not provided."
}
I have tried to enable WSGIPassAuthorization from production server, but it does not help.
It seems to me that somehow the username and password did not really pass through, but cannot figure out how.
It works if I use web browser to access https://production.fake/api/checkuser/
Any advice to troubleshoot will be really appreciated. Thanks!
I have followed the instructions from https://github.com/spring-cloud-services-samples/cook and managed to install and run Config Server in PCF environment (SERVICE: Config Server, PLAN: standard).
I'm now trying to hit /encrypt endpoint of the p-config-server service, in order to encrypt new value. I'm following the instructions at http://docs.run.pivotal.io/spring-cloud-services/config-server/configuring-with-git.html#encryption-and-encrypted-values:
TOKEN=$(curl -k ACCESS_TOKEN_URI -u CLIENT_ID:CLIENT_SECRET -d
grant_type=client_credentials | jq -r .access_token); curl -k -H
"Authorization: bearer $TOKEN" -H "Accept: application/json"
URI/encrypt -d 'VALUE'
...but I always get:
{
"error": "access_denied",
"error_description": "Access is denied"
}
On the other side, if I try to get standard endpoint, to get config for an app, I'm able to retrieve JSON containing app properties. E.g.
TOKEN=$(curl -k ACCESS_TOKEN_URI -u CLIENT_ID:CLIENT_SECRET -d
grant_type=client_credentials | jq -r .access_token); curl -k -H
"Authorization: bearer $TOKEN" -H "Accept: application/json"
URI/my-app/default
... gives result like:
{"name":"my-app","profiles":["default"],"label":null,"version":"bb6e64592ced731ebba272430291a595e0f14a77","state":null,"propertySources":[{"name":"https://github.com/some-user/config/my-app.yml","source":{"my-property.name":"Test123"}}]}
Any idea why I can not access /encrypt endpoint?
Thank you.
Btw, I'm executing the command in CentOS Linux release 7.4.1708, with installed jq (command-line JSON processor).
I've got the answer from CloundFoundry IT support. In my CF environment, "encrypt" endpoint should have a trailing slash (/). So it should be ...URI/encrypt/ -d 'VALUE'. Maybe it helps someone.
One more hint I've got: There is a CF CLI plugin for the Spring-Cloud-Services which you could use for convenience.
https://github.com/pivotal-cf/spring-cloud-services-cli-plugin
cf install-plugin -r CF-Community "Spring Cloud Services"
cf help config-server-encrypt-value
Hi Actually you need to hit cf env command first and take note of configuration values from that which for sample looks like below:
{
"VCAP_SERVICES": {
"p-config-server": [
{
"credentials": {
"access_token_uri": "https://p-spring-cloud-services.uaa.cf.wise.com/oauth/token",
"client_id": "p-config-server-876cd13b-1564-4a9a-9d44-c7c8a6257b73",
"client_secret": "rU7dMUw6bQjR",
"uri": "https://config-86b38ce0-eed8-4c01-adb4-1a651a6178e2.apps.wise.com"
},
[...]
and then use those values in your curl bash script. for example
TOKEN=$(curl -k https://config-86b38ce0-eed8-4c01-adb4-1a651a6178e2.apps.wise.com -u p-config-server-876cd13b-1564-4a9a-9d44-c7c8a6257b73:rU7dMUw6bQjR -d
grant_type=client_credentials | jq -r .access_token); curl -k -H
"Authorization: bearer $TOKEN" -H "Accept: application/json"
URI/ENDPOINT | jq
Basically following values are required:
ACCESS_TOKEN_URI with the value of credentials.access_token_uri
CLIENT_ID with the value of credentials.client_id
CLIENT_SECRET with the value of credentials.client_secret
URI with the value of credentials.uri
Replace ENDPOINT with the relevant endpoint:
application/profile to retrieve configuration from a Config Server service instance
eureka/apps to retrieve the registry from a Service Registry service instance
Then I think you will no more get access denied response.
I'm trying to POST the simple data to the Parse server using REST, but not able to do so, here is the code
#include<curl/curl.h>
curl -X POST \
-H "X-Parse-Application-Id: xxxxxxxxxx" \
-H "X-Parse-REST-API-Key: xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/GameScore
what is X here? do we need to define x? what connection settings need to be used to post the data successfully? and where is the return object is Json, where is is stored?
thanks.
You are trying to use a terminal command in C++, this won't work. X is a command line option for curl.
Below is a basic example of an HTTP POST request submitted with Curl using C. You should be able to adapt this to your needs.
http://curl.haxx.se/libcurl/c/http-post.html
I am building a web service for a web application, and I would like a simple tool to test this as I am developing. I have tried some firefox plug-ins (Poster, 'REST Client'), and even though these work fine I have been unable to upload files with them.
Also, I would rather have a command-line tool that I can use to easily write a set of integration tests for this web service and that I can send to consumers of this web service as an example.
I know that curl can work for this but would like a few examples, especially around authentication (using HTTP Basic) and file uploads.
Answering my own question.
curl -X GET --basic --user username:password \
https://www.example.com/mobile/resource
curl -X DELETE --basic --user username:password \
https://www.example.com/mobile/resource
curl -X PUT --basic --user username:password -d 'param1_name=param1_value' \
-d 'param2_name=param2_value' https://www.example.com/mobile/resource
POSTing a file and additional parameter
curl -X POST -F 'param_name=#/filepath/filename' \
-F 'extra_param_name=extra_param_value' --basic --user username:password \
https://www.example.com/mobile/resource
In addition to existing answers it is often desired to format the REST output (typically JSON and XML lacks indentation). Try this:
$ curl https://api.twitter.com/1/help/configuration.xml | xmllint --format -
$ curl https://api.twitter.com/1/help/configuration.json | python -mjson.tool
Tested on Ubuntu 11.0.4/11.10.
Another issue is the desired content type. Twitter uses .xml/.json extension, but more idiomatic REST would require Accept header:
$ curl -H "Accept: application/json"
From the documentation on http://curl.haxx.se/docs/httpscripting.html :
HTTP Authentication
curl --user name:password http://www.example.com
Put a file to a HTTP server with curl:
curl --upload-file uploadfile http://www.example.com/receive.cgi
Send post data with curl:
curl --data "birthyear=1905&press=%20OK%20" http://www.example.com/when.cgi