From 691bdd511d208d130402186a9d6079d005884f3a Mon Sep 17 00:00:00 2001 From: yhua123 Date: Tue, 6 Sep 2016 12:44:17 +0800 Subject: [PATCH] add version support (#765) add version support in env --- Deploy/prepare | 21 ++++++++++++++------- Deploy/templates/ui/env | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Deploy/prepare b/Deploy/prepare index 003457736..abb7e832a 100755 --- a/Deploy/prepare +++ b/Deploy/prepare @@ -7,7 +7,7 @@ import string import os import sys import argparse -import commands +import subprocess from io import open if sys.version_info[:3][0] == 2: @@ -18,6 +18,10 @@ if sys.version_info[:3][0] == 3: import configparser as ConfigParser import io as StringIO +def validate(conf): + if len(conf.get("configuration", "secret_key")) != 16: + raise Exception("Error: The length of secret key has to be 16 characters!") + parser = argparse.ArgumentParser() parser.add_argument('-conf', dest='cfgfile', default = 'harbor.cfg',type=str,help="the path of Harbor configuration file") args = parser.parse_args() @@ -30,6 +34,8 @@ conf.seek(0, os.SEEK_SET) rcp = ConfigParser.RawConfigParser() rcp.readfp(conf) +validate(rcp) + hostname = rcp.get("configuration", "hostname") ui_url = rcp.get("configuration", "ui_url_protocol") + "://" + hostname email_server = rcp.get("configuration", "email_server") @@ -56,14 +62,14 @@ crt_email = rcp.get("configuration", "crt_email") max_job_workers = rcp.get("configuration", "max_job_workers") token_expiration = rcp.get("configuration", "token_expiration") verify_remote_cert = rcp.get("configuration", "verify_remote_cert") +secret_key = rcp.get("configuration", "secret_key") ######## #Read version form .git -status, output = commands.getstatusoutput('git describe --tags') -if status == 0: - version = output -else: - version = 'unkonwn' +try: + version = subprocess.check_output(["git", "describe","--tags"]).strip('\n') +except : + version = "UNKNOWN" ####### ui_secret = ''.join(random.choice(string.ascii_letters+string.digits) for i in range(16)) @@ -116,6 +122,7 @@ render(os.path.join(templates_dir, "ui", "env"), self_registration=self_registration, use_compressed_js=use_compressed_js, ui_secret=ui_secret, + secret_key=secret_key, verify_remote_cert=verify_remote_cert, token_expiration=token_expiration, version=version) @@ -143,6 +150,7 @@ render(os.path.join(templates_dir, "jobservice", "env"), db_password=db_password, ui_secret=ui_secret, max_job_workers=max_job_workers, + secret_key=secret_key, ui_url=ui_url, verify_remote_cert=verify_remote_cert) @@ -188,7 +196,6 @@ def openssl_is_installed(stat): return False if customize_crt == 'on': - import subprocess shell_stat = subprocess.check_call(["which", "openssl"], stdout=FNULL, stderr=subprocess.STDOUT) if openssl_is_installed(shell_stat): private_key_pem = os.path.join(config_dir, "ui", "private_key.pem") diff --git a/Deploy/templates/ui/env b/Deploy/templates/ui/env index 7f69284c6..c4afba44b 100644 --- a/Deploy/templates/ui/env +++ b/Deploy/templates/ui/env @@ -21,4 +21,3 @@ TOKEN_URL=http://ui VERIFY_REMOTE_CERT=$verify_remote_cert TOKEN_EXPIRATION=$token_expiration VERSION=$version -