Uploading a file to Confluence using powershell - powershell

I am trying to add a document to confluence page.
I am using this code :
E:\APP\"curl-7.53.1"\src\curl.exe -v -S -u user:password -X POST -H "X-Atlassian-Token: no-check" -F "file=#C:\Users\srvc_mdw_dev\Desktop\conf.txt" -F "comment=this is my file" "http://example.net/rest/api/content/36375143/child/attachment"
But i get the following error :
PS E:\PowerShell\script> ./conf
Note: Unnecessary use of -X or --request, POST is already inferred.
* timeout on name lookup is not supported
* Trying IPaddress...
* TCP_NODELAY set
* Connected to example.net (ip address) port 80 (#0)
* Server auth using Basic with user 'user'
> POST /rest/api/content/36375143/child/attachment HTTP/1.1
> Host: example.com
> Authorization: Basic c291aGFpbC5vdWFiaUBtZXRyb2V4dGVybmFsLmZyOm1ldHJvNDU2Kg==
> User-Agent: curl/7.53.1
> Accept: */*
> X-Atlassian-Token: no-check
> Content-Length: 333
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------646f724e33da0066
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: https://example.net/rest/api/content/36375143/child/attachment
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
* HTTP error before end of send, stop sending
<
* Closing connection 0
Do Someone knows why I have this error ? thank you

Please review the following curl command the confluence rest api documentation.
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page",
"space":{"key":"TST"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":
"storage"}}}' http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/

Related

Powershell alternative to curl when calling Jenkins API

I would like to find a PowerShell alternative to curl most specific when calling jenkins api and getting a return output.
curl --silent -k https://jenkins:8443/job/myjob/buildwithParameters -i
The curl parameter -i will return the queue number in the output.
With the queue item I can easily query again the API and get the results of the specific job.
Location: https://jenkinsserver:8443/queue/item/317/
I can successfully wrap curl into a PowerShell script/function however I would like to eliminate this dependency.
PS C:\> curl.exe --silent -k https://jenkinsserver:8443/job/MyJOB/buildWithParameters --user myuser:****myapitoken****** --data ComputerName=XYZ003 --data State=start --data --data ve
rbosity=high -i
HTTP/1.1 201 Created
Date: Wed, 02 Dec 2020 02:52:01 GMT
X-Content-Type-Options: nosniff
Location: https://jenkinsserver:8443/queue/item/317/
Content-Length: 0
Server: Jetty(9.4.30.v20200611)
PS C:\>

Is it possible to compare two variables in an HAProxy ACL statement?

Is it possible to compare compare two variables in an HAProxy ACL statement? For example, assuming that both the host header and X-CORRECT-HOST header are equal to "example.com".
acl correct_host hdr(host) -i example.com # THIS RETURNS TRUE
acl correct_host hdr(X-CORRECT-HOST) -i example.com # THIS RETURNS TRUE
I've tried a few things and read through the documentation, but can't seem to get anything to work. Here's a couple examples I tried that all return false:
acl correct_host hdr(host) -i hdr(X-CORRECT-HOST)
acl correct_host hdr(host) -m str hdr(X-CORRECT-HOST)
acl correct_host hdr(host) -i %[hdr(X-CORRECT-HOST)]
acl correct_host hdr(host) -m str %[hdr(X-CORRECT-HOST)]
You can use lua(need to build haproxy with lua support)
you can check with:
haproxy -vv|grep -i lua
somethig like this:
OPTIONS = USE_ZLIB=1 USE_OPENSSL=1 USE_LUA=1
Built with Lua version : Lua 5.3.1
or build with lua, something like:
make TARGET=linux2628 USE_LUA=1 LUA_LIB=/opt/lua-5.3.1/lib LUA_INC=/opt/lua-5.3.1/include
then
$ ./haproxy -v
Nuster version 2.0.0.18
Copyright (C) 2017-2018, Jiang Wenyuan, <koubunen AT gmail DOT com >
HA-Proxy version 1.8.12 2018/06/27
Copyright 2000-2018 Willy Tarreau <willy#haproxy.org>
conf:
global
debug
lua-load compare_header_value.lua
frontend web1
bind *:8080
mode http
default_backend app1
backend app1
mode http
http-request set-var(req.two_header_value_equal) lua.compare_header_value(hdr1,hdr2)
http-request deny unless { var(req.two_header_value_equal) -m bool }
server s1 127.0.0.1:8000
compare_header_value.lua
function compare_header_value(txn, h1, h2)
local hdr = txn.http:req_get_headers()
if hdr[h1] == nil or hdr[h2] == nil then
return false
end
if hdr[h1][0] == hdr[h2][0] then
return true
end
return false
end
core.register_fetches("compare_header_value", compare_header_value)
then you can use ACL like this:
http-request deny unless { var(req.two_header_value_equal) -m bool }
Test:
1 same header
curl -v http://127.0.0.1:8080/ -H "hdr1: 1" -H "hdr2: 1"
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.60.0
> Accept: */*
> hdr1: 1
> hdr2: 1
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
2 different header
curl -v http://127.0.0.1:8080/ -H "hdr1: 1" -H "hdr2: 2"
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.60.0
> Accept: */*
> hdr1: 1
> hdr2: 2
>
* HTTP 1.0, assume close after body
< HTTP/1.0 403 Forbidden
It can be done with strcmp
https://cbonte.github.io/haproxy-dconv/2.6/configuration.html#7.3.1-strcmp
e.g.
http-request set-var(txn.host) hdr(host)
# Check whether the client is attempting domain fronting.
acl ssl_sni_http_host_match ssl_fc_sni,strcmp(txn.host) eq 0

alchemy API doesnt accept my local file

Here is my request:
> curl -i -H "Accept: application/json" -H "Content-Type:
> application/json" -X GET
> http://access.alchemyapi.com/calls/image/ImageGetRankedImageKeywords?apikey=<key>&image=file%3A%2F%2Ftmp%2Fimage.jpg&imagePostMode=not-raw&outputMode=json
Following http://www.alchemyapi.com/api/image-tagging/image.html
Response:
HTTP/1.1 200 OK Server: nginx Date: Wed, 13 May 2015 04:27:56 GMT
Content-Type: application/xml; charset=utf-8 Content-Length: 440
Connection: keep-alive Cache-Control: no-cache
X-AlchemyAPI-CurrentVersion: 12.15 X-AlchemyAPI-Error-Msg:
content-is-empty X-AlchemyAPI-Key: X-AlchemyAPI-Params:
sentiment=0&knowledgeGraph=0&detectedLanguage=unknown&submitLanguage=detect
X-AlchemyAPI-Status: ERROR X-AlchemyAPI-Total-Transactions: 4
Access-Control-Allow-Origin: *
ERROR
content-is-empty
By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of
Use: http://www.alchemyapi.com/company/terms.html
4
Why?
The image exists:
$ ls -l /tmp/trash1.jpg
-rw-r-----# 1 xx staff 47846 May 12 15:49 /tmp/image.jpg
$
Their support helped me.
Essentially i need to POST the image directly.
Can't use the "image" parameter and filling it with the name of the local file. That parameter actually needs to contain the contents of the image file instead. So instead need to use imagePostMode=raw, and just add the file as the post body, which I would recommend. Something like this:
wget -qO- --post-file YOUR_IMAGE.png "http://access.alchemyapi.com/calls/image/ImageGetRankedImageKeywords?apikey=API_KEY&imagePostMode=raw"

How can I suppress the headers from CLI CURL's output of request

There's plenty of info on how to prevent curl from showing header information when doing a request for the PHP version, but seemingly nothing for the CLI version.
my request is in the form
curl -i -X POST -H 'Content-Type: application/json; charset=UTF-8' -H 'X-Accept: application/json' -H '-d '{"somedata":"12ihiuhihihed994f63dbef6b012b"}' https://myurl.com/v3/oauth/request
Which works, but returns this:
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json
Date: Wed, 27 Mar 2013 20:42:11 GMT
P3P: policyref="/w3c/p3p.xml", CP="ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE"
Server: Apache/2.2.23 (Amazon)
Status: 200 OK
X-Powered-By: PHP/5.3.20
Content-Length: 54
Connection: keep-alive
{"code":"jkhjhhjhaa","state":null}
when all I really want is this:
{"code":"jkhjhhjhaa","state":null}
Simply remove the -i switch from your curl command.
man curl
said :
-i, --include
(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...
In order to suppress output from CURL CLI --silent option can be used. It perfectly works when curl output is piped as well.
-s, --silent Silent mode (don't output anything)
In case this isn't obvious, also don't use the -v (verbose) switch with -s (silent)

Can't PUT to a Bucket

First I'm pretty sure the riak is setting ok by using the command: riak-admin status
But I can't PUT in into a bucket test:
curl -v -X PUT -d 'This is really cool' -H "Content-Type: text/plain" http://markson.hk:8098/buckets/test/1234
< HTTP/1.1 404 Object Not Found
< Server: MochiWeb/1.1 WebMachine/1.9.0 (participate in the frantic)
< Date: Fri, 18 Nov 2011 12:13:03 GMT
< Content-Type: text/html
< Content-Length: 193
Does the error due to the new bucket test? Should I create it first?
Take a look at Basic Riak API Operations, the basic PUT request looks like this:
PUT /riak/bucket/key
Hence your curl example should be similar to:
curl -v -X PUT -d 'The is so cool' -H "Content-Type: text/plain" http://markson.hk:8098/riak/test/1234
But then again, seems like somebody already deposited a test key for you: