helm hosted repo via CLI - nexus

I installed the helm repo plugin for nexus3
Now I want to create the helm hosted repo via RestAPI command, in the same way as I do for raw repository
# RAW Repository
curl -X POST "${NEXUS_URL}/service/rest/v1/script" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"name\": \"create_raw_repo\", \"content\": \"repository.createRawHosted(args, 'default')\", \"type\": \"groovy\"}"
curl -X POST "${NEXUS_URL}/service/rest/v1/script/create_raw_repo/run" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: text/plain" \
-d "raw-release"
# HELM Repo
curl -X POST "${NEXUS_URL}/service/rest/v1/script" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"name\": \"create_helm_repo\", \"content\": \"repository.createHelmHosted(args, 'default')\", \"type\": \"groovy\"}"
curl -X POST "${NEXUS_URL}/service/rest/v1/script/create_helm_repo/run" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: text/plain" \
-d "helm-demo-release"
The problem is that the repository.createHelmHosted method doesn't exists.
What is the correct way to do it?

From version 3.21 nexus support OOB the helm repo and has REST API to create the repo
http://you-nexus:8081/service/rest/beta/repositories/helm/hosted
curl -X POST "http://you-nexus:8081/service/rest/beta/repositories/helm/hosted" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"name\": \"internal\", \"online\": true, \"storage\": { \"blobStoreName\": \"default\", \"strictContentTypeValidation\": true, \"writePolicy\": \"allow_once\" }, \"cleanup\": { \"policyNames\": \"weekly-cleanup\" }}"

Related

Post request with form data to login to a website return 400 - Bad request

I am trying to login into this website with below credentials (no worry, it's anonymous):
user = 'MattieBailey#mailinator.com'
password = 'thx9jD3SkrssPKY'
When I logged in manually, I saw in Chrome inspector view there are sequentially a POST request and a GET request.
However, when I tried to simulate these requests with python, I got 400 - Bad request for the POST request. The GET request returned 200 - OK and sent me the content of the login webpage. In the Chrome Inspector View, all these 2 requests returned 302 status code with some response headers contains authorized id_token to use for further requests.
The same result was obtained when I tried to import these two requests to Postman so the problem might not be my code.
My ultimate goal is to get the id_token parameter in the response header of the GET request.
I appreciate your help!
POST request
curl 'https://auth.fiintrade.vn/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DStoxPlus.FiinTrade.SPA%26redirect_uri%3Dhttps%253A%252F%252Ffiintrade.vn%252Fsignin-callback%26response_type%3Did_token%2520token%26scope%3Dopenid%2520FiinTrade.Market%2520FiinTrade.Core%2520FiinTrade.Realtime%2520FiinTrade.Fundamental%26state%3D19e5bb5a7df14a2bab8ded1f265a7bda%26nonce%3D1547e70f8a2940b89dac75565e032046%26clientType%3DWEBCLIENT%26fp%3D54404ac5041ff5b042c29fb397bef44d%26type%3Dredirect' \
-H 'Connection: keep-alive' \
-H 'Cache-Control: max-age=0' \
-H 'sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'Origin: null' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-User: ?1' \
-H 'Sec-Fetch-Dest: document' \
-H 'Accept-Language: en-US,en;q=0.9,vi;q=0.8' \
-H 'Cookie: _ga=GA1.2...' \
--data-raw 'ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DStoxPlus.FiinTrade.SPA%26redirect_uri%3Dhttps%253A%252F%252Ffiintrade.vn%252Fsignin-callback%26response_type%3Did_token%2520token%26scope%3Dopenid%2520FiinTrade.Market%2520FiinTrade.Core%2520FiinTrade.Realtime%2520FiinTrade.Fundamental%26state%3D19e5bb5a7df14a2bab8ded1f265a7bda%26nonce%3D1547e70f8a2940b89dac75565e032046%26clientType%3DWEBCLIENT%26fp%3D54404ac5041ff5b042c29fb397bef44d%26type%3Dredirect&Username=MattieBailey%40mailinator.com&Password=thx9jD3SkrssPKY&button=login&__RequestVerificationToken=CfDJ8KNrfTjG6sBLmncBE9MMk0dDAX-OFwPXUy1uT0AqrEyhngGIImEM99JGxVKsssw62kRxLY2tHfTqfH8M8Mphqxh80YdwwHM6vpZIb-yVMnma4nS0QCkOf51FMFFu8pPwMM6FY52WEPSWy_ZWuaiAeCU' \
--compressed
GET request
curl 'https://auth.fiintrade.vn/connect/authorize/callback?client_id=StoxPlus.FiinTrade.SPA&redirect_uri=https%3A%2F%2Ffiintrade.vn%2Fsignin-callback&response_type=id_token%20token&scope=openid%20FiinTrade.Market%20FiinTrade.Core%20FiinTrade.Realtime%20FiinTrade.Fundamental&state=19e5bb5a7df14a2bab8ded1f265a7bda&nonce=1547e70f8a2940b89dac75565e032046&clientType=WEBCLIENT&fp=54404ac5041ff5b042c29fb397bef44d&type=redirect' \
-H 'Connection: keep-alive' \
-H 'Cache-Control: max-age=0' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-User: ?1' \
-H 'Sec-Fetch-Dest: document' \
-H 'sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'Accept-Language: en-US,en;q=0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c3RfYXR0ZW1wdCI6IjgvMTIvMjAyMSAxMTo1ODoxNyBQTSIsImxhc3RfYXR0ZW1wdF9zdGF0dXMiOiJTVUNDRVNTIiwiZmluZ2VycHJpbnQiOiI1NDQwNGFjNTA0MWZmNWIwNDJjMjlmYjM5N2JlZjQ0ZCIsImNsaWVudHR5cGUiOiJXRUJDTElFTlQiLCJzY29wZSI6WyJvcGVuaWQiLCJGaWluVHJhZGUuTWFya2V0IiwiRmlpblRyYWRlLkNvcmUiLCJGaWluVHJhZGUuUmVhbHRpbWUiLCJGaWluVHJhZGUuRnVuZGFtZW50YWwiXSwiYW1yIjpbInB3ZCJdfQ.RSMsirz2etpYNVx9Pq1W1qExw1ETwCt5XUxglHwreyQX0WDZV3nUDOf5mxgNKjQx_sPCBQuF6SBH8IdNGcuv9ajvd2XbKWdcsNljXidiRHNGogo-JKIZIqadzLAEAmdXoYP_w2ToqOYkWmtEzm2SMpgbVzklRftciQg4h-K_jYW4YpteX23Az78yT3_RIirfBfszaTp5v3BEOR_StHG16bHPauOlIGmch6o6cWUSX1RPnqyAUVaNGELPygNQcmoYVgyQhwoloXyuDY7LGjhK3EgMm9iCuDx5JasFi5A0PQrAfgs1g7UftC-B_7XvJG4pw4qbevj3PehvZ9Kp1RshXw&token_type=Bearer&expires_in=28600&scope=openid%20FiinTrade.Market%20FiinTrade.Core%20FiinTrade.Realtime%20FiinTrade.Fundamental&state=19e5bb5a7df14a2bab8ded1f265a7bda&session_state=dV3zKwxom21hMpGaoJweGLKUlj2rO2gGSFWbw6bIw4U.ab1d0e2f49d55710dba656b0c958891d
I finally figured it out using Selenium. Here is the code:
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
LOGIN_URL = 'https://auth.fiintrade.vn/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DStoxPlus.FiinTrade.SPA%26redirect_uri%3Dhttps%253A%252F%252Ffiintrade.vn%252Fsignin-callback%26response_type%3Did_token%2520token%26scope%3Dopenid%2520FiinTrade.Market%2520FiinTrade.Core%2520FiinTrade.Realtime%2520FiinTrade.Fundamental%26state%3Dd454e517f7ff44709a797670cd357be7%26nonce%3D890d02d7b58f42e88197818b035ad6d9%26clientType%3DWEBCLIENT%26fp%3De292f9093f0b9abc9904b5fba1d948c6%26type%3Dredirect'
def generate_token() -> bool:
service = Service(cfg.CHROME_DRIVER_PATH)
options = Options()
options.headless = True # do not show new window
driver = webdriver.Chrome(service=service, options=options)
driver.get(LOGIN_URL)
username_textbox = driver.find_element(By.ID, "exampleInputEmail1")
username_textbox.send_keys(cfg.USERNAME)
password_textbox = driver.find_element(By.ID, "exampleInputPassword1")
password_textbox.send_keys(cfg.PASSWORD)
login_button = driver.find_element(By.NAME, "button")
login_button.click()
assert 'access_token=' in driver.current_url, 'Failed to get access token'
resp = driver.current_url
# get token from resp
resp = resp.split('access_token=')[1].split('&token_type=')
id_token = resp[0]
token_type = resp[1].split('&expires_in=')[0]
auth_token = token_type + ' ' + id_token
with open(cfg.AUTH_TOKEN_SAVE_PATH, 'w') as f:
f.write(auth_token)
return 0

Send MSGPack body generates HTTP 500

I actualy try to replicate a http request with a msgpack body request. I have the original request that works (several times testet, generates a http 200 statuscode)
If i replicate the request for example in insomnia or in PowerShell or with curl i get an http error 500. I tried it with a binary file also as Body.
Any ideas?
Following curl command can be use:
curl --request POST \
--url https://4af7c20b-7646-4fb7-b64f-ae0a8c51c1f1.register.collector.scopely.io/register \
--header 'Accept: application/x-msgpack' \
--header 'Accept-Encoding: gzip' \
--header 'Cache-Control: no-cache' \
--header 'Connection: Keep-Alive' \
--header 'Content-Type: application/x-msgpack' \
--header 'Host: 4af7c20b-7646-4fb7-b64f-ae0a8c51c1f1.register.collector.scopely.io' \
--header 'User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-N950N Build/NMF26X)' \
--header 'X-Unity-Version: 5.6.4p3' \
--header 'cache-control: no-cache' \
--header 'content-length: 672' \
--header 'x-scopely-titan-auth: 4af7c20b-7646-4fb7-b64f-ae0a8c51c1f1' \
--body 3gAQrHN5cy5wbGF0Zm9ybadhbmRyb2lkqXN5cy5zdG9yZaZHb29nbGW3c3lzLmNsaWVudF9nZW5lcmF0ZWRfaWTZIGQ3NDYyNDJhMzk3NjQ0N2E5ZTg3NmRlNmUxNDViZTgzr3N5cy5zZGtfdmVyc2lvbqUzLjAuN6pzeXMuYnVuZGxltGNvbS5zY29wZWx5LnN0YXJ0cmVrr3N5cy5hcHBfdmVyc2lvbqswLjU0My4xMDQ0Na5zeXMub3NfdmVyc2lvbr41LjEuMS9hcGktMjIobm1mMjZ4LzUwMDE5MDMzMSmpc3lzLm1vZGVssHNhbXN1bmcgU00tTjk1ME6qc3lzLmxvY2FsZaVkZV9ERalzeXMuYnVpbGSqUHJvZHVjdGlvbqtzeXMuY2FycmllcrB2b2RhZm9uZSBkMiBnbWJoqHN5cy5pbWVprzM1MTU2NDA4MDIwMjIyOapzeXMuc2VyaWFssDQ5NWE2ZGQzODk4YmM1Zmauc3lzLmFuZHJvaWRfaWSwYmM1ZmY0OTVhNmRkMzg5OK9zeXMubWFjX2FkZHJlc3OxQkM6NUY6RjQ6OTU6QTY6RES5c3lzLmdvb2dsZV9hZHZlcnRpc2luZ19pZNkkZTRiMThhN2EtOGQ2Yi00ZTFiLTgwYWItOWM5MzY4NGVkNTBm

Configuring a bitbucket repository to "activate" pipelines

I have multiple repositories in a BitBucket project.
I wish to automatically create a bitbucket repository, and enable pipelines (setting the pipeline configuration should be easy, with pushing a bitbucket-pipelines.yml file).
How can I do it using the REST API?
The other answer's "enable pipelines" request did not work for me.
This is what worked:
curl -X PUT -is -u '<username>:<password>' -H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<username>/<slug>/pipelines_config \
-d '{
"enabled": true
}'
You can create a repository with the BitBucket REST API.
$ curl -X POST -H "Content-Type: application/json" -d '{
"scm": "git",
"project": {
"key": "Foo"
}
}' https://api.bitbucket.org/2.0/repositories/<username>/<repo_slug>
Push your bitbucket-pipelines.yml to your created repo.
curl https://api.bitbucket.org/2.0/repositories/<username>/<slug>/src \
-F /bitbucket-pipelines.yml=#bitbucket-pipelines.yml
Then enable pipeline for your project
curl -X PUT -is -u '<username>:<password>' -H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<username>/<repo_slug> \
-d '{
"enabled": true,
"type": "repository_pipelines_configuration"
}'
Finally, you can trigger a pipeline for the branch like so.
$ curl -X POST -is -u <username>:<password> \
-H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<username>/<slug>/pipelines/ \
-d '
{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "<branch_name>"
}
}'
References:
Repository API
Pipelines API

how to curl with query string parameter in format of "filter[name]=foo"

Here is an api on my server:
https://server/api/v1/products?filter[name]=foo
this works well when I access it via browser, and it works well with the following two methods:
$ cat /tmp/x
{"filter": {"name": "foo"}}
$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : -H 'Content-Type: application/json' -d "#/tmp/x" https://server/api/v1/products
{"name": "foo", ...}
$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : -d "filter[name]=foo" https://server/api/v1/products
{"name": "foo", ...}
Now I'm trying to do it with:
$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : https://server/api/v1/products?filter[name]=foo
$ echo $?
3
it fails with error code 3, which stands for "URL malformed. The syntax was not correct."
How should I specify the query string parameters in the url?
The query string needs to be URL encoded so it has to look like this:
https://server/api/v1/products?filter%5Bname%5D=foo
asciitable.com.

How do I POST XML data with curl

I want to post XML data with cURL. I don't care about forms like said in How do I make a post request with curl.
I want to post XML content to some webservice using cURL command line interface. Something like:
curl -H "text/xml" -d "<XmlContainer xmlns='sads'..." http://myapiurl.com/service.svc/
The above sample however cannot be processed by the service.
Reference example in C#:
WebRequest req = HttpWebRequest.Create("http://myapiurl.com/service.svc/");
req.Method = "POST";
req.ContentType = "text/xml";
using(Stream s = req.GetRequestStream())
{
using (StreamWriter sw = new StreamWriter(s))
sw.Write(myXMLcontent);
}
using (Stream s = req.GetResponse().GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
MessageBox.Show(sr.ReadToEnd());
}
-H "text/xml" isn't a valid header. You need to provide the full header:
-H "Content-Type: text/xml"
I prefer the following command-line options:
cat req.xml | curl -X POST -H 'Content-type: text/xml' -d #- http://www.example.com
or
curl -X POST -H 'Content-type: text/xml' -d #req.xml http://www.example.com
or
curl -X POST -H 'Content-type: text/xml' -d '<XML>data</XML>' http://www.example.com
It is simpler to use a file (req.xml in my case) with content you want to send -- like this:
curl -H "Content-Type: text/xml" -d #req.xml -X POST http://localhost/asdf
You should consider using type 'application/xml', too (differences explained here)
Alternatively, without needing making curl actually read the file, you can use cat to spit the file into the stdout and make curl to read from stdout like this:
cat req.xml | curl -H "Content-Type: text/xml" -d #- -X POST http://localhost/asdf
Both examples should produce identical service output.
Have you tried url-encoding the data ? cURL can take care of that for you :
curl -H "Content-type: text/xml" --data-urlencode "<XmlContainer xmlns='sads'..." http://myapiurl.com/service.svc/
You can try the following solution:
curl -v -X POST -d #payload.xml https://<API Path> -k -H "Content-Type: application/xml;charset=utf-8"

Resources