Skip to content

Custom Signatures Export Import

mkumykov edited this page Mar 8, 2021 · 3 revisions

Custom Signatures Export/Import

Preface

This document describes a process of migrating custom signatures from one instance of a Blackduck to another using Blackduck Pythin REST API library.

There are two scripts provided:

This document will imply that the execution environment is Linux or other UNIX-like system.

Requirements

  • Access to source Blackduck instance
  • Access to destination Blackduck instance
  • Client machine with Python 3 environment
  • Blackduck Python REST API

Setup

Setup API Library

Clone blackducksoftware/hub-rest-api-python

       git clone https://github.com/blackducksoftware/hub-rest-api-python.git

Alternatively use "Download ZIP" feature of GitHub project

For the purpose of this document let's consider that the library is cloned into $HOME/hub-rest-api-python folder. Further instructions will use that location.

Setup python execution environment

export PYTHONPATH=$PYTHONPATH:$HOME/hub-rest-api-python
pip3 install -r $PYTHONPATH:$HOME/hub-rest-api-python/requirements.txt

Setup working directory and configuration files for Export/Import process

Create a working directory to be used for Export/Import process and change your working directory to it.

mkdir $HOME/custom_signatures
cd $HOME/custom_signatures

Create configuration files for source and destination servers respectively.

src.restconfig.json

{
   "baseurl": "https://source-blackduck-server-hostname",
   "api_token": "source-blackduck-server-token",
   "insecure": true,
   "debug": false
}

dst.restconfig.json

{
   "baseurl": "https://destination-blackduck-server-hostname",
   "api_token": "destination-blackduck-server-token",
   "insecure": true,
   "debug": false
}

Test configuration

Test access to the source instance

cp src.restconfig.json .restconfig.json
python3 /Users/kumykov/git/hub-rest-api-python/examples/get_current_user.py 

This should produce JSON output that looks similar to this:

$ python3 $HOME/hub-rest-api-python/examples/get_current_user.py 
{"userName": "sysadmin", "firstName": "System", "lastName": "Administrator", "email": "[email protected]", "type": "INTERNAL"
...

Test access to the destination instance using same process, use dst.restconfig.json.

Export Custom Signatures

Export custom signatures by executing the following.

cp src.restconfig.json .restconfig.json
python3 /Users/kumykov/git/hub-rest-api-python/examples/custom_signatures_export.py output_folder

Once completed, output folder should contain collection of .bdio files and metadata.json file.

Import Custom Signatures

Import custom signatures to the destination server as following.

cp dst.restconfig.json .restconfig.json
python3 /Users/kumykov/git/hub-rest-api-python/examples/custom_signatures_export.py output_folder

Note that this command uses output of the previous command as input. This command will create a project structure as necessary and mark projects listed in the metadata.json as custom signatures.

Then it will upload .bdio files to the destination server.

Once processing is complete, custom signatures will be ready to use.