How to pass a parameter to a Spring Cloud Function? - spring-cloud

I'm following the Spring Cloud Function tutorial.
In the example, they are calling the revert bean with this command:
curl localhost:8080/reverseString -H "Content-Type: text/plain" -d "abc"
I like to call the endpoint from a browser/postman as a GET request.
So I was looking to orchestrate a URL with a query parameter, that may look like localhost:8080/reverseString?input=abc
But:
It is not clear to me what should be the name of the parameter?
Seems like no matter what method name we put, they all get HTTP 200 response, with no response body. reverseStringggg, reve ...

You can pass it as localhost:8080/reverseString/abc
That said, I've raise the issue to explicitly support http parameters - https://github.com/spring-cloud/spring-cloud-function/issues/864

Related

How to pass API parameters to GCP cloud build triggers

I have a large set of GCP Cloud Build Triggers that I invoke via a Cloud scheduler, all running fine.
Now I want to invoke these triggers by an external API call and pass them dynamic parameters that vary in values and number of parameters.
I was able to start a trigger by running an API request but any JSON parameters in the API request that I sent were ignored.
Google talks about substitution parameters at https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values. I define these variables in the cloudbuild.yaml file, however they were not propagated into my shell script from the API request.
I don't any errors with authentication or authorization, so security may not be an issue.
Is my idea supported at all or do I need to resort to another solution such as running a GKE cluster with containers that would expose its API (a very heavy-boxing solution).
We do something similar -- we migrated from Jenkins to GCB but for some people we still need a nicer "UI" to start builds / pass variables.
I got scripts from here and modified them to our own needs: https://medium.com/#nieldw/put-your-build-triggers-into-source-control-with-the-cloud-build-api-ed0c18d6fcac
Here is their REST API: https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.triggers/run
For the script below, keep in mind you need the trigger-id of what you want to run. (you can also get this by parsing the output of another REST API.)
TRIGGER_ID=1
# we need to specify ATLEAST the branch name or commit id (check after)
BRANCH_OR_SHA=$2
# check if branch_name or commit_sha
if [[ $BRANCH_OR_SHA =~ [0-9a-f]{5,40} ]]; then
# is COMMIT_HASH
COMMIT_SHA=$BRANCH_OR_SHA
BRANCH_OR_SHA="\"commitSha\": \"$COMMIT_SHA\""
else
# is BRANCH_NAME
BRANCH_OR_SHA="\"branchName\": \"$BRANCH_OR_SHA\""
fi
# This is the request we send to google so it knows what to build
# Here we're overriding some variables that we have already set in the default 'cloudbuild.yaml' file of the repo
cat <<EOF > request.json
{
"projectId": "$PROJECT_ID",
$BRANCH_OR_SHA,
"substitutions": {
"_MY_VAR_1": "my_value",
"_MY_VAR_2": "my_value_2"
}
}
EOF
# our curl post, we send 'request.json' with info, add our Token, and set the trigger_id
curl -X POST -T request.json -H "Authorization: Bearer $(gcloud config config-helper \
--format='value(credential.access_token)')" \
https://cloudbuild.googleapis.com/v1/projects/"$PROJECT_ID"/triggers/"$TRIGGER_ID":run

Unable to import test results to jira via rest api

i'm using the following curl command to import the output.xml file into jira test execution key and receiving error as below. I'm sure the test execution key is existing in jira and the project id is also correct. Any pointers?
curl -H "Content-Type: multipart/form-data" -u userid:pass -F "file=#output.xml" "https://server/rest/raven/latest/import/execution/robot?projectKey=PROJKEY+and+testExecKey=TESTEXNKEY" -o error.txt
The error i receive is as below
The User "userid" does not have permission to create issues
Why does it try to create new issue while the issue already exists? And why does it say the user doesn't have access when the access is there?
You probably mean Xray add-on and you probably use the same request per their documentation. The problem seems to be with your parameter syntax. It should be .../robot/?projectKey=PROJKEY&testExecKey=TESTEXNKEY (i.e. & instead of +and+).
Plus I would explicitly specify it's a POST request: curl -X POST ....
But their error message is not clear, anyway. I don't have Xray available right now, but if you keep having troubles, I would recommend checking with their support.

Spring MVC - respecting double slash in REST request

Lets say I have the following two REST endpoints built with Spring MVC (v.4):
1. [GET] /cars/make/{make}
2. [GET] /cars/make/{make}/model
And the following requests:
1. curl -X GET -H "Accept: application/json" "http://localhost/cars/make//model"
2. curl -X GET -H "Accept: application/json" "http://localhost/cars/make/%20/model"
The two requests will match the first endpoint (with path variable make having a value of model. Is it possible to change the matcher to match on the second endpoint with make being an empty string or whitespace?
I've been able to override the default Spring AntPathMatcher to not trim tokens, thus fixing the issue with the second request. However I'm not sure how to modify it so that it strictly respects the 2 backslashes with no whitespace in between. Is this possible?

How to use JSON in OrientDB HTTP command request

I'm using orientdb-community-2.2-alpha and I'm trying to use JSON payloads with the HTTP command API (as in calling http://<host>:<port>/command/<database>/sql) and I simply can't figure out how to do it. All I get is an OCommandExecutorNotFoundException saying Cannot find a command executor for the command request: sql.<whatever JSON I tried here> no matter what I try.
I'm not providing an example of what I've tried as I'm not trying to do any one specific thing; I would just like to see a working curl example of how to post a generic command request using a JSON payload.
I can use JSON with batch requests just fine, it's just the command API that I can't get to work.
You can try with Postman plugin

Cannot set more than one Meta data with OpenStack Swift Object

I am trying to set metadata with a Object stored in Swift Container. I am using following command (note that my container is 'container1' and object is 'employee.json':
curl -X POST -H "X-Auth-Token:$TOKEN" -H 'X-Object-Meta-metadata1: value' $STORAGE_URL/container1/employee.json
It works fine with one metadata. But whenever, I am trying to set more than one metadata issuing several curl commands, only the last metadata value is actually set.
I think, there should not be a limit that you can set only one metadata for a swift object. Am I doing anything wrong?
FYI: I am using Havana release of Openstack Swift.
Thank you.
I think, I have figured it out... Its my bad that I did not read documentation sincerely.
It [1] says, "A POST request will delete all existing metadata added with a previous PUT/POST."
So, I tried this and it worked...
curl -X POST -H "X-Auth-Token:$TOKEN" -H 'X-Object-Meta-p1:[P1]' -H 'X-Object-Meta-p2:[P1]' $STORAGE_URL/container1/employee.json
Here, instead of two POST requests, now I have set multiple metadata in a single POST request.
Again, thanks.
Ref:
http://docs.openstack.org/api/openstack-object-storage/1.0/content/update-object-metadata.html