From 0fe8209ae123a3c7f18d1f7a66726779e6e935c5 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Mon, 5 Sep 2016 11:22:12 +0800 Subject: [PATCH 1/3] the name can be same with others when creating and updating policies --- api/replication_policy.go | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/api/replication_policy.go b/api/replication_policy.go index bcfa18791..3777f6209 100644 --- a/api/replication_policy.go +++ b/api/replication_policy.go @@ -91,15 +91,17 @@ func (pa *RepPolicyAPI) Post() { policy := &models.RepPolicy{} pa.DecodeJSONReqAndValidate(policy) - po, err := dao.GetRepPolicyByName(policy.Name) - if err != nil { - log.Errorf("failed to get policy %s: %v", policy.Name, err) - pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) - } + /* + po, err := dao.GetRepPolicyByName(policy.Name) + if err != nil { + log.Errorf("failed to get policy %s: %v", policy.Name, err) + pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) + } - if po != nil { - pa.CustomAbort(http.StatusConflict, "name is already used") - } + if po != nil { + pa.CustomAbort(http.StatusConflict, "name is already used") + } + */ project, err := dao.GetProjectByID(policy.ProjectID) if err != nil { @@ -169,18 +171,20 @@ func (pa *RepPolicyAPI) Put() { policy.ProjectID = originalPolicy.ProjectID pa.Validate(policy) - // check duplicate name - if policy.Name != originalPolicy.Name { - po, err := dao.GetRepPolicyByName(policy.Name) - if err != nil { - log.Errorf("failed to get policy %s: %v", policy.Name, err) - pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) - } + /* + // check duplicate name + if policy.Name != originalPolicy.Name { + po, err := dao.GetRepPolicyByName(policy.Name) + if err != nil { + log.Errorf("failed to get policy %s: %v", policy.Name, err) + pa.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) + } - if po != nil { - pa.CustomAbort(http.StatusConflict, "name is already used") + if po != nil { + pa.CustomAbort(http.StatusConflict, "name is already used") + } } - } + */ if policy.TargetID != originalPolicy.TargetID { //target of policy can not be modified when the policy is enabled From 3ae4b71c9a2905bda7aa6c9b41988043567a4812 Mon Sep 17 00:00:00 2001 From: yhua Date: Mon, 5 Sep 2016 15:45:36 +0800 Subject: [PATCH 2/3] add version support in env --- Deploy/prepare | 21 +++++++++++---------- Deploy/templates/ui/env | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Deploy/prepare b/Deploy/prepare index 82c647d15..f1db506e1 100755 --- a/Deploy/prepare +++ b/Deploy/prepare @@ -7,6 +7,7 @@ import string import os import sys import argparse +import commands from io import open if sys.version_info[:3][0] == 2: @@ -17,10 +18,6 @@ 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() @@ -33,8 +30,6 @@ 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") @@ -61,9 +56,16 @@ 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 = 'UNKNOWN' +####### + ui_secret = ''.join(random.choice(string.ascii_letters+string.digits) for i in range(16)) base_dir = os.path.dirname(__file__) @@ -114,9 +116,9 @@ 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) + token_expiration=token_expiration, + version=version) render(os.path.join(templates_dir, "ui", "app.conf"), ui_conf, @@ -141,7 +143,6 @@ 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) diff --git a/Deploy/templates/ui/env b/Deploy/templates/ui/env index 2d6badcb6..c4afba44b 100644 --- a/Deploy/templates/ui/env +++ b/Deploy/templates/ui/env @@ -12,7 +12,6 @@ AUTH_MODE=$auth_mode LDAP_URL=$ldap_url LDAP_BASE_DN=$ldap_basedn UI_SECRET=$ui_secret -SECRET_KEY=$secret_key SELF_REGISTRATION=$self_registration USE_COMPRESSED_JS=$use_compressed_js LOG_LEVEL=debug @@ -21,3 +20,4 @@ EXT_ENDPOINT=$ui_url TOKEN_URL=http://ui VERIFY_REMOTE_CERT=$verify_remote_cert TOKEN_EXPIRATION=$token_expiration +VERSION=$version From 5076897ea9b1f25b07c4f9a2eff605aaa7b2677d Mon Sep 17 00:00:00 2001 From: yhua Date: Mon, 5 Sep 2016 15:53:49 +0800 Subject: [PATCH 3/3] add version support in env --- Deploy/prepare | 2 +- Deploy/templates/ui/env | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Deploy/prepare b/Deploy/prepare index f1db506e1..003457736 100755 --- a/Deploy/prepare +++ b/Deploy/prepare @@ -63,7 +63,7 @@ status, output = commands.getstatusoutput('git describe --tags') if status == 0: version = output else: - version = 'UNKNOWN' + version = 'unkonwn' ####### ui_secret = ''.join(random.choice(string.ascii_letters+string.digits) for i in range(16)) diff --git a/Deploy/templates/ui/env b/Deploy/templates/ui/env index c4afba44b..7f69284c6 100644 --- a/Deploy/templates/ui/env +++ b/Deploy/templates/ui/env @@ -21,3 +21,4 @@ TOKEN_URL=http://ui VERIFY_REMOTE_CERT=$verify_remote_cert TOKEN_EXPIRATION=$token_expiration VERSION=$version +