How to specify putting zip into jfrog artifactory? - artifactory

I have directory like /tmp/some-js/(a lot of folders)
I added it into zip /tmp/some-js.zip
I have structure in artifactory like /npm-dev/some-js/*
I put into artifactory this zip with command
curl -u user:api-key -k -X PUT https://xxx.xx.xx.xx:8081/artifactory/npm_dev/some-js/ -T /tmp/some-js.zip
And I have got directory in artifactory /npm-dev/some-js/some-js.zip/*
There is a way to specify unpacking some-js.zip contents into /npm-dev/some-js ?

Uploading an archive file (such as a zip file) to Artifactory and extracting its content to a specific directory is done by:
PUT https://<jfrog-platform>/artifactory/the-repo/path/to/dir/file.zip
X-Explode-Archive: true
<file-content>
The content of file.zip will be extracted and deployed under the-repo/path/to/dir/, preserving the relative directory structure in the zip file. So if file.zip has the following structure:
foo/
|- bar.txt
|- baz.txt
The following files will be created in Artifactory:
the-repo/path/to/dir/foo/bar.txt
the-repo/path/to/dir/foo/baz.txt
Using curl and the details in the question:
curl -u user:api-key \
-k \
-X PUT \
https://xxx.xx.xx.xx:8081/artifactory/npm_dev/some-js/some-js.zip \
-T /tmp/some-js.zip
-H "X-Explode-Archive: true"
For more information, see the documentation on Deploy Artifacts from Archive

Related

How to download google sheets file to specific folder in cpanel using wget cron

I have a working cron job but I can't get it to download my file into my target destination. At the moment, the file is downloaded into the root folder in cpanel.
Here is what I have:
wget --no-check-certificate 'https://docs.google.com/spreadsheets/d/[...]/edit?usp=sharing' -O file.xlsx
Now defining the destination folder doesn't work. Here's how I'm doing it:
wget --no-check-certificate 'https://docs.google.com/spreadsheets/d/[...]/edit?usp=sharing' -O 'public_html/wp-content/uploads/import/files' file.xlsx
This doesn't download any file. Not sure what I could be missing.
Managed with this:
wget --no-check-certificate 'https://docs.google.com/spreadsheets/d/[...]/edit?usp=sharing' -O public_html/wp-content/uploads/import/files/file.xlsx

How to delete all contents of local Artifactory repository via REST API?

I'm using a local repository as a staging repo and would like to be able to clear the whole staging repo via REST. How can I delete the contents of the repo without deleting the repo itself?
Since I have a similar requirement in one of my environments I like to provide a possible solution approach.
It is assumed the JFrog Artifactory instance has a local repository called JFROG-ARTIFACTORY which holds the latest JFrog Artifactory Pro installation RPM(s). For listing and deleting I've created the following script:
#!/bin/bash
# The logged in user will be also the admin account for Artifactory REST API
A_ACCOUNT=$(who am i | cut -d " " -f 1)
LOCAL_REPO=$1
PASSWORD=$2
STAGE=$3
URL="example.com"
# Check if a stage were provided, if not set it to PROD
if [ -z "$STAGE" ]; then
STAGE="repository-prod"
fi
# Going to list all files within the local repository
# Doc: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-FileList
curl --silent \
-u"${A_ACCOUNT}:${PASSWORD}" \
-i \
-X GET "https://${STAGE}.${URL}/artifactory/api/storage/${LOCAL_REPO}/?list&deep=1" \
-w "\n\n%{http_code}\n"
echo
# Going to delete all files in the local repository
# Doc: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-DeleteItem
curl --silent \
-u"${A_ACCOUNT}:${PASSWORD}" \
-i \
-X DELETE "https://${STAGE}.${URL}/artifactory/${LOCAL_REPO}/" \
-w "\n\n%{http_code}\n"
echo
So after calling
./Scripts/deleteRepository.sh JFROG-ARTIFACTORY Pa\$\$w0rd! repository-dev
for the development instance, it listed me all files in the local repository called JFROG-ARTIFACTORY, the JFrog Artifactory Pro installation RPM(s), deleted them, but left the local repository itself.
You may change and enhance the script for your needs and have also a look into How can I completely remove artifacts from Artifactory?

Create multiple artifactory repositories from json

I want to automate the process of importing existing repositories structure from another Artifactory through .json file.
So far, I have managed to make single repo from json with the following command.
curl -X PUT --insecure -u admin -H "Content-type: application/json" -T repository-config.json "https://artifactory.test.net/artifactory/api/repositories/acqbo-docker-release-local"
Is there a way to import multiple/array of repositories from a single json file and a single curl?
Ended up writing my own bash script for this purpose.
you will have to make a file with the repositories you want to copy:
#!/bin/bash
#############
# This script copies the repository structure from one Artifactory server to another
# repos.list file is required to have repositories that we want to copy, each in new line.
# user with the admin rights is necessary
#############
#Where to copy repos from and to
ARTIFACTORY_SOURCE="https://source.group.net/artifactory/api/repositories/"
ARTIFACTORY_DESTINATION="https://destination.group.net/artifactory/api/repositories/"
NOLINES=$(wc -l < repos.list) #get total nuber of lines in repos.line
COUNTER=1 #Set the counter to 1
while [ $COUNTER -le $NOLINES ] #loops times number of lines in the repos.line
do
REPONAME=$(awk "NR==$COUNTER" repos.list) #get only repo name, line by line
curl -GET --insecure -u admin:adminpass "$ARTIFACTORY_SOURCE$REPONAME" > xrep.json #Obtain data from Artifactory source, repo by repo, and writes it to the xrep.json
curl -X PUT --insecure -u admin:adminpass -H "Content-type: application/json" -T xrep.json "$ARTIFACTORY_DESTINATION$REPONAME" #Sends data from json to the destination Artifactory server
#print in blue color
printf "\e[1;34m$COUNTER repo done\n\e[0m"
((COUNTER++))
done
printf "\e[1;34mAll repos exported!\n\e[0m"

OpenStack Swift cannot use bulk operation to auto extract tar file

I want to upload many files with a single operation in OpenStack Swift. I find the middleware -- Bulk Operations which can auto extract files from tar compressed file. However, I failed to extract the files from the tar.
I PUT the tar file use the bulk operation like this:
curl -X PUT http://127.0.0.1:8080/v1/AUTH_test/ContainerName/$?extract-archive=tar \
-T theTarName.tar \
-H "Content-Type: text/plain" \
-H "X-Auth-Token: token"
I am sure that the storageURL, tar file path, and token is accurate. But, I didn't get any responses(successes or errors). When I show the objects in the container, I find just one object named 0extract-archive=tar was uploaded, but the files in the tar were not extracted.
I want to know how to extract the tar automatically in OpenStack Swift and all of the files in the tar can be displayed in the container.
Thanks in advance.
The issue is the $? part. $? refers to the exit code of the last command in bash (http://tldp.org/LDP/abs/html/exit-status.html), which I suspect you're using.
If you'd like to use $ as the archive prefix, consider escaping it with \:
$ curl -X PUT \
"http://127.0.0.1:8080/v1/AUTH_test/container/\$?extract-archive=tar" \
-T test.tar \
-H "X-Auth-Token: <token>"
You should get the following output:
Number Files Created: 3
Response Body:
Response Status: 201 Created
Errors:

How to ssh to a certain directory and then be able to use the FIND command to find certain files and gunzip them

Hi everyone I'm not to ksh. What i'm trying to do is I'm writing a script to scp a(or many) zip file from a local directory to a remote host. Then get the script to ssh into the remote host to gunzip the files I just scp over. Is there any simple way to do this. I keep trying but once I ssh over to the remote host the rest of my commands no longer run like the cd /file/directory and then gzip -d /files etc.....
NB: don't confuse "zip" and "gzip", two different animals
This should work:
cd <local_directory>
# collect files names as $1 $2 ... $N
set -- *.gz # or use your own filter like "dumps*.gz"
# put source file a tar archive and send it as input to ssh
# then, on the other side, untar the file then decompress
tar cf - $* | ssh <user>#<remote_host> "cd <remote dir> && tar xf - && gunzip $*
Note: using "&&" instead of ";" to prevent "tar" command to be executed if "cd" fails for any reason

Resources