How to add a package to the XQuery repository? - rest

I am using cURL to execute commands using the REST interface of BaseX like this:
curl http://localhost:8984/rest/?command=repo+list
There are also commands to manage the XQuery module repository. I am especially interested in REPO INSTALL to install a package. Is it somehow possible to execute this command using cURL and the REST interface but without having the package already on the target server? I want to provide the file in the body of the cURL request, similar to adding a resource to a database (source) which goes like this:
curl -i -X PUT -T "etc/xml/factbook.xml" "http://localhost:8984/rest/factbook"
Trying
curl -i -X PUT -T "/tmp/foo.xar" http://localhost:8984/rest/?command=repo+install
Gives me
HTTP/1.1 404 Not Found
Content-Type: text/plain;charset=UTF-8
Content-Length: 18
Connection: close
Server: Jetty(9.4.18.v20190429)
No path specified.
Adding -H "Content-Type: application/x-xar" does not help either.
And replacing PUT with POST gives me
HTTP/1.1 100 Continue
HTTP/1.1 400 Bad Request
Date: Tue, 03 Mar 2020 09:53:21 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 46
Server: Jetty(9.4.18.v20190429)
"" (Line 1): Content is not allowed in prolog.

The following works in case of standard modules (replace user/pass/server if needed):
$ curl http://admin:admin#localhost:8984/rest/?command=repo+install+http://www.xqueryfunctions.com/xq/functx-1.0.1-doc.xq

Related

curl gives 403 error while trying to run exec command on kubenetes pod

I m trying to execute the command inside the container using Kubernetes API. while the command work using kubectl
kubectl exec shell-demo -- bash -c env
but same gives 403 error when using Kubernetes web API(kubectl proxy) using curl.
$ curl -k -v POST http://192.168.1.44:5443/api/v1/namespaces/mynamespace/pods/shell-demo/exec?command=bash&command=-c&command=env&container=nginx&stderr=true&stdout=true
[1] 405247
[2] 405248
[3] 405249
[4] 405250
[5] 405251
[2] Done command=-c
[3] Done command=env
[4]- Done container=nginx
[farooq#farooq-pc ansible-vbox-vagrant-kubernetes]$ * Could not resolve host: POST
* Closing connection 0
curl: (6) Could not resolve host: POST
* Trying 192.168.1.44:5443...
* Connected to 192.168.1.44 (192.168.1.44) port 5443 (#1)
> GET /api/v1/namespaces/mynamespace/pods/shell-demo/exec?command=bash HTTP/1.1
> Host: 192.168.1.44:5443
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Thu, 18 Nov 2021 19:54:34 GMT
< Content-Length: 10
<
Forbidden
Your curl command looks wrong. Try it with -X in front of the POST like this: curl -k -v -X POST http://192.168.1.44:5443/api/v1/namespaces/mynamespace/pods/shell-demo/exec?command=bash&command=-c&command=env&container=nginx&stderr=true&stdout=true
also make sure if you need POST at all, since you don't add any data (-d mypostbody) it could be a simple GET request with urlencoded-data depending on your API endpoint aswell.

Downloading github actions workflow logs using github api

I am trying to download the logs of a particular workflow in github.
I have referenced the following link for the same.
However I am getting 302 as response code.
Not sure what the issue here is. Its not downloading logs as expected
curl -v -u username:$token -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/ORGANIZATION/REPOSITORY/actions/runs/319282523477/logs
.
.
< HTTP/1.1 302 Found
< Date: Wed, 21 Oct 2020 07:47:13 GMT
< Content-Type: text/html;charset=utf-8
.
As per the same documentation that you mentioned:
Gets a redirect URL to download a plain text file of logs for a workflow job. This link expires after 1 minute. Look for Location: in the response header to find the URL for the download
Response
Status: 302 Found
So you might have already got the url to download the logs as the response has a 302 http status. Please check for the Location: response header, which should give you the url that you need to download the logs.
As a side note to Madhu Bhat's answer, you can simply add -L to your curl command to make it follow redirects.
(from curl --help)
-L, --location Follow redirects

How to insert data on Grails 3 through REST API?

I've build a demo project on Grails 3.0.10
I can read the data with a REST request but I don't know how to insert data.
Here's how my project is built:
grails create-app bookstore
cd bookstore
grails create-domain-class bookstore.Book
edit file grails-app/domain/bookstore/Book.groovy :
package bookstore
class Book {
String title
String author
Date publicationDate
static constraints = {
}
}
Scaffold:
grails generate-all bookstore.Book
Run the app:
grails run-app
Browse:
http://localhost:8080
From here I can insert and list items from the browser ;o)
Now I want to use the REST API !
Reading data is OK:
curl -H "Accept: application/json" -i http://localhost:8080
/book.jsonHTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Application-Context: application:development
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 14 Dec 2015 12:14:01 GMT
[{"class":"bookstore.Book","id":1,"author":"James","publicationDate":"2015-12-13T23:00:00Z","title":"Hello"}]
But when I try to insert data:
curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"title":"Test", "author":"Franck"}'
http://localhost:8080/book/create.jsonHTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Application-Context: application:development
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 14 Dec 2015 12:16:03 GMT
{"class":"bookstore.Book","id":null,"author":null,"publicationDate":null,"title":null}
And nothing is inserted.
The default create action doesn't save anything. It is used to populate the initial form when creating an instance using a browser form. You probably want to be invoking the save action instead.
This isn't really related to your question but FYI... if you are building a REST interface, you should look at RestfulController and/or the #Resource annotation.

How to request only for a web page header using netcat?

I am not sure whether netcat has some command for requesting http header or should I use sed to filter the result? If sed is used in this case, is it so that I only have to extract everything before the first "<" occurs ?
The command line tool curl has the -I option which only gets the headers:
-I/--head
(HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on a FTP or FILE file, curl displays the file size and last modification time only.
Demo:
$ curl -I stackoverflow.co.uk
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 503
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 26 Sep 2013 21:06:15 GMT

using wget against protected site with NTLM

Trying to mirror a local intranet site and have found previous questions using 'wget'. It works great with sites that are anonymous, but I have not been able to use it against a site that is expecting username\password (IIS with Integrated Windows Authentication).
Here is what I pass in:
wget -c --http-user='domain\user' --http-password=pwd http://local/site -dv
Here is the debug output (note I replaced some with dummy values obviously):
Setting --verbose (verbose) to 1
DEBUG output created by Wget 1.11.4 on Windows-MSVC.
--2009-07-14 09:39:04-- http://local/site
Host `local' has not issued a general basic challenge.
Resolving local... seconds 0.00, x.x.x.x
Caching local => x.x.x.x
Connecting to local|x.x.x.x|:80... seconds 0.00, connected.
Created socket 1896.
Releasing 0x003e32b0 (new refcount 1).
---request begin---
GET /site/ HTTP/1.0
User-Agent: Wget/1.11.4
Accept: */*
Host: local
Connection: Keep-Alive
---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 401 Access Denied
Server: Microsoft-IIS/5.1
Date: Tue, 14 Jul 2009 13:39:04 GMT
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
Content-Length: 4431
Content-Type: text/html
---response end---
401 Access Denied
Closed fd 1896
Unknown authentication scheme.
Authorization failed.
NTLM authentication is broken in wget 1.11, use 1.10 instead.
Curl is actually probably a better tool for fetching content from NTLM-authenticated web servers. You can get an equivalent function to your proposed wget command line by using:
curl --anyauth --user username:password http://someserver/site
I've seen references to being able to use the NTLM Authorization Proxy Server to get around these types of problems.
use --auth-no-challenge option (wget 1.11+) (it's now considered unsafe)
I found solution.
It is work-around for Basic auth IIS7.
When auth is successeful it send next http header:
'Authorization: < type > < credentials >'.
So we able to do authorization in browser and
copy this header params from browser (firebug addon) or generate:
$ echo -en 'username:password' | base64
dXNlcm5hbWU6cGFzc3dvcmQK
$ echo 'dXNlcm5hbWU6cGFzc3dvcmQK' | base64 -d
username:password
example:
$ wget --header="Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQK" http://example.com/