Raw HTTP Repositories

Raw HTTP repositories are useful when you want to read and write to CloudRepo but don’t want to use a technology specific client.

Note

A CloudRepo Maven Repsitory works as a CloudRepo Raw Repository so all instructions here apply to Maven Repositories as well.

Pre-Requisites

Before you can use CloudRepo as a raw HTTP repository, you’ll need to ensure that you have created a Maven Repository as well as a Repository User in the CloudRepo Admin Portal.

If you haven’t done this yet, please see the following instructions for doing so:

Note

For security purposes (mostly because passwords tend to be stored in plaintext), we do not allow your admin user to access artifacts via the repositories. Please create a user in the CloudRepo Administrator Portal.

Command Line (CURL) Examples

There are times when you want to access your artifacts directly via a script or command line. In this case, you can upload and download files via the command line with CURL. We provide examples of how to upload and download files to/from CloudRepo here.

Note

The following examples have been tested on Ubuntu 16.04.1 using Curl 7.47.0 and Bash 4.3.48(1).

These scripts should on any system with compatible Bash and Curl executables.

Upload a file with CURL

The following bash script shows how to upload a file directly to CloudRepo using CURL.

#!/bin/bash

#
# Not a good idea to commit these credentials to source control, but you can remove them here and set them as environment variables
# outside this script prior to invoking.
#
USER_ID=chris@example.com
PASSPHRASE=changeme

#
# Change this to your organization id and repository id
#
ORGANIZATION_ID=example-org
REPOSITORY_ID=example-repo

# Do not begin with a slash
DESTINATION_PATH=uploads/test-123.jar

# We use the -n flag with the echo command so that we don't pass the null terminator.
ENCODED_PW=`echo -n ${USER_ID}:${PASSPHRASE} | base64 -`
FILE_TO_UPLOAD=/home/chris/photos/chris.jpeg

TARGET_URL=https://${ORGANIZATION_ID}.mycloudrepo.io/repositories/${REPOSITORY_ID}/${DESTINATION_PATH}

#
# CURL Command
#   -s -> Silence the output
#   -w -> Capture the HTTP Result Code
#   -d -> Specify the Data to upload
#
HTTP_STATUS=`curl -s -w "%{http_code}" -X PUT ${TARGET_URL} -H "Authorization: Basic ${ENCODED_PW}" -d @${FILE_TO_UPLOAD}`

#
# Output actual success (200) or other failures here, to give feedback to the user
#
if [[ ${HTTP_STATUS} -eq 200 ]]; then
    echo File Successfully uploaded to CloudRepo and can be retrieved from [${TARGET_URL}]!
else
    echo Failed to upload file to CloudRepo [${TARGET_URL}] Result: $HTTP_STATUS
fi

Download a file with CURL

Once you’ve uploaded a file to CloudRepo, you can use the following bash script download that file to your computer.

#!/bin/bash

#
# Replace these with your username and passphrase.
#
# Not a good idea to commit these credentials to source control, but you can remove them here and set them as environment variables
# outside this script prior to invoking.
#
USER_ID=chris@example.io
PASSPHRASE=changeme

#
# Change this to your organization id and repository id
#
ORGANIZATION_ID=example-org
REPOSITORY_ID=example-repo

#
# Location of artifact you wish to retrieve on the Remote CloudRepo Server - Do not begin with a slash.
#
ARTIFACT_PATH=uploads/test-123.jar

# We use the -n flag with the echo command so that we don't pass the null terminator.
ENCODED_PW=`echo -n ${USER_ID}:${PASSPHRASE} | base64 -`

#
# Specify where you want to store the downloaded file
#
OUTPUT_DIRECTORY=/tmp
OUTPUT_FILE=${OUTPUT_DIRECTORY}/$ARTIFACT_PATH

#
# CURL Command
#  -s -> silent output
#  --create-dirs -> create directories when writing the file if they don't already exist
#  -o -> Specify the output file path
#  -w Capture the Status Code, so we can differentiate between success and failed calls and the return.
HTTP_STATUS=`curl -s --create-dirs -o ${OUTPUT_FILE} -w "%{http_code}" -X GET https://${ORGANIZATION_ID}.mycloudrepo.io/repositories/${REPOSITORY_ID}/${ARTIFACT_PATH} -H "Authorization: Basic ${ENCODED_PW}"`

#
# Output actual success (200) or other failures here, to give feedback to the user
#
if [[ ${HTTP_STATUS} -eq 200 ]]; then
    echo File Successfully retrieved from CloudRepo and stored in ${OUTPUT_FILE}
else
    echo Failed to download file from CloudRepo - Result: $HTTP_STATUS