Retrieve latest artifact from JFROG artifactory - versioning

I have a few versions of my code in JFROG, which are provided to the clients. How do I specify a generic way to pull latest version(Artifact)? It is not Maven code. I looked up on the Jfrog page:
'''
GET http://localhost:8081/artifactory/ivy-local/org/acme/[RELEASE]/acme-[RELEASE].jar
'''
How do I get [RELEASE] ?
Please help ?

the [RELEASE] in this case is the version number you want to download the latest artifact for. To get that number you can use the REST API call for Artifact Latest Version Search Based on Layout. For example
GET /api/search/latestVersion?g=org.acme&a=artifact&repos=libs-snapshot-local
This would return a string of the latest release version you have.

You can follow the documentation at jfrog
#!/bin/bash
# Note that we don't enable the 'e' option, which would cause the script to
# immediately exit
set -uo pipefail
HOST=myartcloud.jfrog.io
USER=thisIsMyUser
PASS=thisismypass
SNAPSHOT_LAST_VERSION=$(curl --silent --show-error --fail \
-u$USER:"$PASS" \
-X POST https://$HOST/artifactory/api/search/aql \
-H "content-type: text/plain" \
-d 'items.find({ "repo": {"$eq":"my-repo-snapshot"}, "name": {"$match" : "my-project-package-name*"}})'\
| grep -E -o -e 'my-project-package-name-[[:digit:]].[[:digit:]].[[:digit:]]+'| uniq | sort | tail -1 \
| grep -E -o -e '[[:digit:]].[[:digit:]].[[:digit:]]+')
Explanation. Making usage of curl with option
--fail (HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts.
--silent Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
--show-error When used with -s it makes curl show an error message if it fails.
Then a post request -X POST is made using basic authentication to the api path. The content type of the request is -H "content-type: text/plain".
-d, --data (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML.
The data sent, is using a filter query to find an repository and also the content.
After the api results, using grep command line utility where it searches for PATTERNS and return only the version number.
Example: 0.1.1

Related

Using curl with AngularJS and bash

I’m trying to fill out web forms using curl via a bash script to a website that uses AngularJS. Can’t find any documentation on how to do this. Is it even possible to use curl to POST data to webforms that use AngularJS? I’m not even sure I’m asking the right question or if there’s a better method?
In most cases AngularJS uses ajax calls with JSON payload instead of old-school multipart POSTs.
You can use browser to send test post and save request information "as cURL".
Most likely you will have ready-to-use command to add to your bash file.
But quite often such posts are associated with authenticated person so you will need to fill in up-to-date session cookie into your request.
First things to check will be whether your command works with cleaned cookies.
If it works then your task is done.
Just call such API with something like this:
curl -X POST -H "Content-Type:application/json" \
http://some-server/handle-form \
-d '{"parameter1":["41","34"],"another_parameter":"val1"}'
But if your curl request is rejected by server with cookies absent then you need to setup proper cookie before invocation of API request.
This call will authenticate you against server and will store session cookie in a jar file:
curl -b ./jar -c ./jar -i -X POST -H "Content-Type:application/json" \
http://some-server/login \
-d '{"login":"my-user-name", "password":"my-password"}'
And such save session cookies would be reused for subsequent API calls:
curl -b ./jar -c ./jar -i -X POST -H "Content-Type:application/json" \
http://some-server/handle-form \
-d '{"parameter1":["41","34"],"another_parameter":"val1"}'

How to automatically create a Sentry release and upload source-maps to Sentry in a react project?

I have a create-react-app project, and I'd like the deploy process to generate a Sentry release and upload the source maps to Sentry as well.
This script will create a Sentry release for version specified in the package.json file, and upload the source maps to Sentry.
It will work for any JS project, not just React.
create a file in your project root and name it deploy.sh:
SENTRY_TOKEN="YOUR_TOKEN"
PACKAGE_VERSION=`cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]'`
printf "\nBuilding version $PACKAGE_VERSION...\n\n"
#2) Build for dev and cd to build directory
npm run build # or whatever your build command is
cd build/static/js # or whatever your build folder is
#3) create Sentry release
SOURCE_MAP=`find . -maxdepth 1 -mindepth 1 -name '*.map' | awk '{ gsub("./", "") ; print $0 }'`
printf "\nCreating a Sentry release for version $PACKAGE_VERSION...\n"
curl https://sentry.io/api/0/projects/:sentry_organization_slug/:sentry_project_slug/releases/ \
-X POST \
-H "Authorization: Bearer ${SENTRY_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{\"version\": \"${PACKAGE_VERSION}\"}" \
#4) Upload a file for the given release
printf "\n\nUploading sourcemap file to Sentry: ${SOURCE_MAP}...\n"
curl "https://sentry.io/api/0/projects/:sentry_organization_slug/:sentry_project_slug/releases/$PACKAGE_VERSION/files/" \
-X POST \
-H "Authorization: Bearer ${SENTRY_TOKEN}" \
-F file=#${SOURCE_MAP} \
-F name="https://THE_URL_OF_THE_MAIN_JS_FILE/$SOURCE_MAP"
#5) IMPORTANT: Delete the sourcemaps before deploying
rm $SOURCE_MAP
#6) upload to your cloud provider
...
replace:
:sentry_organization_slug and :sentry_project_slug with the correct values from sentry (from the URL of any page inside your sentry account website)
SENTRY_TOKEN with your token from Sentry
THE_URL_OF_THE_MAIN_JS_FILE with the URL where your react build file is publicly accessible.
run.
Make sure you don't forget to update the package.json version on every release
I had the same problem recently and despite that there is no official solution for Create React App from Sentry their tooling is great and it's quite easy to automate the process of creating releases by yourself. You would need to generate release name, build the app and use this name to initialize Sentry library, create Sentry Release and upload sourcemaps.
I wrote the article which explains in details how to do it: https://medium.com/#vshab/create-react-app-and-sentry-cde1f15cbaa
Or you can go straight forward and look at example of configured project: https://github.com/vshab/create-react-app-and-sentry-example

PUT with cURL couchDB

I am trying to create a database with curl from the command line on Windows using this command:
curl -X PUT http://127.0.0.1:5984/test_database.
I receive this response:
curl: (52) Empty reply from server
I am able to see all the created databases (curl -X GET http://127.0.0.1:5984/_all_dbs) and i can also use GET to see information for a specific database created from Futon interface, but PUT doesn't seem to work.
I have also tried to enter the curl command from win-bash command line. I got the same response.
What else should i try?

SOLR: Curl update all files

Is there anyway to use the curl command to update the solr with all the files under a directory? For example like update all the XML files:
curl "http://localhost:8983/solr/xml/update?commit=true&tr=add.xsl" -H "Content-Type: text/xml" --data-binary #*.xml
Using the post.jar, I was able to run these updates, but I am not looking the same function on using CURL ?
Thanks in advance.
I don't think CURL supports making wildcard posts through --data-binary. It does support some globbing in its -T parameter, but that issues a PUT (as it uses the baseurl + filename). You'll also have to expand the list yourself, as I couldn't get * to work as globbing pattern.
The easiest way is probably to wrap it in a for-loop instead, which will depend on how you're running curl (and what OS or shell you're using).
#!/usr/bin/env bash
for FILE in *.xml
do
curl "http://localhost:8983/solr/xml/update?commit=true&tr=add.xsl" -H "Content-Type: text/xml" --data-binary #$FILE
done

Versioning JCR nodes via DAV - howto?

Background: I've been thinking about adopting a service mix including Apache Sling, Jackrabbit, and Jetty, for purposes of content management within web site designs. At this point, I'd like to imagine that it would be possible to create a mobile content creation platform using DAV to access a JCR content repository. The matter of Versioning in JCR 2.0 (JSR-283) it leaves me wondering, how would one conduct JCR versioning operations via HTTP?
In more detail: I'm looking at what I presume would be section 15 of JSR-283, served up in HTML format from Adobe. In that section, JSR-283 presents a concept of versioning for JCR nodes.
I understand, then, that there's a VersionManager API in JSR-283 compatible releases of Jackrabbit. That serves to explain how one would conduct JCR (JSR-283) versioning operations via the API. So, but how can a user agent conduct a versioning operation via DAV?
I'd like to answer that one for myself, but I don't even know where to start.
Is there another part of JSR-283 explaining how the version checkin/checkout operations translate into HTTP requests? Is it a matter of simple DAV properties? Am I even close to the mark, at that?
/Peer review needed, lol
There is a document (JCR_Webdav_Protocol.doc - Apache Jackrabbit) describing the mapping between WebDAV method calls and Jackrabbit JCR API calls on the Jackrabbit website:
http://jackrabbit.apache.org/JCR_Webdav_Protocol.doc
Though this document is last updated 29.March 2006 I found it quite helpful to make my first steps.
I have traced a session with Microsoft Office 2010 against my Jackrabbit default repository using Word and Wireshark. The following shell script kind of executes the same actions using curl and libreoffice on *nix.
As you can see the DELETE, UPLOAD, VERSION-CONTROL Document WebDAV calls are executed upfront to the actions in Word.
The Browse Directory opens the URL in your Internet Explorer instance.
Microsoft Word retrieves Document Properties (PROPFIND) and then opens (GET) and LOCKs the Document.
It also requests the Properties on %EE%B3%B0 for unknown reasons (UTF-8 (hex) 0xEE 0xB3 0xB0 (eeb3b0) or UTF-16 "\uECF0" a.k.a. "" from the Private Use Range of Unicode Character Set).
Once you Save the Document in Microsoft Word it will upload (PUT) and update the properties (PROPPATCH) of your Document node to include Win32CreationTime, Win32LastModifiedTime and Win32LastAccessTime stamps.
Closing the Document in Word will release the aquired lock using UNLOCK.
CHECKIN Document is again executed manually to make the Version lifecycle complete.
The Version-Tree REPORT can be gained from WebDAV too.
#!/bin/sh
# Delete document
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X DELETE -v http://localhost:7001/repository/default/test.docx
# Upload document
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X PUT -v http://localhost:7001/repository/default/test.docx --data-binary "#test.docx"
# Version-Control document
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X VERSION-CONTROL -v http://localhost:7001/repository/default/test.docx
# Checkout document
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X CHECKOUT -v http://localhost:7001/repository/default/test.docx
# Browse directory
curl -A "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" -X GET -v http://localhost:7001/repository/default/
# Open document in Word
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X PROPFIND -v http://localhost:7001/repository/default/test.docx | xmllint --format -
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X GET -v http://localhost:7001/repository/default/test.docx -O
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X PROPFIND -v http://localhost:7001/repository/default/test.docx%EE%B3%B0
cat > LOCK_document.xml <<EOF
<?xml version="1.0" encoding="utf-8" ?>
<D:lockinfo xmlns:D="DAV:">
<D:lockscope>
<D:exclusive/>
</D:lockscope>
<D:locktype>
<D:write/>
</D:locktype>
<D:owner>
<D:href>WINDOWSDOMAIN\USER</D:href>
</D:owner>
</D:lockinfo>
EOF
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X LOCK -v http://localhost:7001/repository/default/test.docx --data "#LOCK_document.xml" | xmllint --format - | tee LOCK_document.txt
export LOCK_token=$(grep opaquelocktoken LOCK_document.txt | sed 's/^.*opaquelocktoken:/<opaquelocktoken:/' | sed 's/<\/D:href>.*$/>/')
curl -A "Microsoft Office Existence Discovery" -X HEAD -v http://localhost:7001/repository/default/test.docx
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X OPTIONS -v http://localhost:7001/ -H "translate: f"
# Edit document in Word
libreoffice test.docx
# Save document in Word
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X HEAD -v http://localhost:7001/repository/default/test.docx
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X PUT -v http://localhost:7001/repository/default/test.docx -H "If: (${LOCK_token})" --data-binary "#test.docx"
cat > PROPPATCH_document.xml <<EOF
<?xml version="1.0" encoding="utf-8" ?>
<D:propertyupdate xmlns:D="DAV:" xmlns:Z="urn:schemas-microsoft-com:">
<D:set>
<D:prop>
<Z:Win32CreationTime>Mon, 09 Mar 2015 15:24:36 GMT</Z:Win32CreationTime>
<Z:Win32LastAccessTime>Mon, 16 Mar 2015 13:22:40 GMT</Z:Win32LastAccessTime>
<Z:Win32LastModifiedTime>Mon, 16 Mar 2015 13:22:40 GMT</Z:Win32LastModifiedTime>
</D:prop>
</D:set>
</D:propertyupdate>
EOF
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X PROPPATCH -v http://localhost:7001/repository/default/test.docx -H "If: (${LOCK_token})" --data "#PROPPATCH_document.xml" | xmllint --format -
# Close document in Word
curl -A "Microsoft Office Existence Discovery" -X HEAD -v http://localhost:7001/repository/default/test.docx
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X UNLOCK -v http://localhost:7001/repository/default/test.docx -H "Lock-Token: ${LOCK_token}"
# Checkin document
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X CHECKIN -v http://localhost:7001/repository/default/test.docx
# Version tree report on document
cat > REPORT_version-tree.xml <<EOF
<?xml version="1.0" encoding="utf-8" ?>
<D:version-tree xmlns:D="DAV:">
<D:prop>
<D:version-name/>
</D:prop>
</D:version-tree>
EOF
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X REPORT -v http://localhost:7001/repository/default/test.docx --data "#REPORT_version-tree.xml" | xmllint --format -
I only had problems with the auto-version capabilities of Jackrabbit, which are obviously not implemented yet.
https://issues.apache.org/jira/browse/JCR-1348
#<!--
# see http://www.webdav.org/specs/rfc3253.html#PROPERTY_auto-version
# <D:auto-version>checkout-checkin</D:auto-version>
# <D:auto-version>checkout-unlocked-checkin</D:auto-version>
# <D:auto-version>checkout</D:auto-version>
# <D:auto-version>locked-checkout</D:auto-version>
#-->
cat > PROPPATCH_auto-version.xml <<EOF
<?xml version="1.0" encoding="utf-8" ?>
<D:propertyupdate xmlns:D="DAV:">
<D:set>
<D:prop>
<D:auto-version>checkout-checkin</D:auto-version>
</D:prop>
</D:set>
</D:propertyupdate>
EOF
curl -A Microsoft-WebDAV-MiniRedir/6.1.7601 -X PROPPATCH -v http://localhost:7001/repository/default/test.docx -H "If: (${LOCK_token})" --data "#PROPPATCH_auto-version.xml" | xmllint --format -
I understand that the JCR versioning framework effectively pivots around the mix:versionable JCR mixin node type (Jackrabbit Wiki). So, if a node is created as being of type mix:versionable, then I presume that the conventional WebDAV checkin and checkout operations - as could be encapsulated with a WebDAV API - that those would probably be how one would conduct JCR checkin/checkout operations on versionable nodes. That, I presume, would answer that much of the question
I don't see any exact DAV compliment to the JCR checkpoint operation, but if that's just checkin followed with checkout, as the documentation explains, then it would be easy enough to emulate via DAV - thus making a compliment to that JCR operation.

Resources