mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 12:15:20 +01:00
add a jenkins job for migrate harbor from 1.6 to the latest, make some modification in prepare.py to adapt harbor 1.6 (#7025)
Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
parent
4dc983d419
commit
340577076c
@ -8,6 +8,7 @@ requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
|
||||
parser = argparse.ArgumentParser(description='The script to generate data for harbor v1.4.0')
|
||||
parser.add_argument('--endpoint', '-e', dest='endpoint', required=True, help='The endpoint to harbor')
|
||||
parser.add_argument('--version', '-v', dest='version', required=False, help='The version to harbor')
|
||||
args = parser.parse_args()
|
||||
|
||||
url = "https://"+args.endpoint+"/api/"
|
||||
@ -19,20 +20,27 @@ class HarborAPI:
|
||||
request(url+"projects", 'post', **body)
|
||||
|
||||
def create_user(self, username):
|
||||
payload = {"username":username, "email":username+"@vmware.com", "password":"Harbor12345", "realname":username, "commment":"string"}
|
||||
payload = {"username":username, "email":username+"@vmware.com", "password":"Harbor12345", "realname":username, "comment":"string"}
|
||||
body=dict(body=payload)
|
||||
request(url+"users", 'post', **body)
|
||||
|
||||
def set_user_admin(self, user):
|
||||
r = request(url+"users?username="+user+"", 'get')
|
||||
userid = str(r.json()[0]['user_id'])
|
||||
if args.version == "1.6":
|
||||
body=dict(body={"has_admin_role": True})
|
||||
else:
|
||||
body=dict(body={"has_admin_role": 1})
|
||||
request(url+"users/"+userid+"/sysadmin", 'put', **body)
|
||||
|
||||
def add_member(self, project, user, role):
|
||||
r = request(url+"projects?name="+project+"", 'get')
|
||||
projectid = str(r.json()[0]['project_id'])
|
||||
if args.version == "1.6":
|
||||
payload = {"member_user":{ "username": ""+user+""},"role_id": role}
|
||||
else:
|
||||
payload = {"roles": [role], "username":""+user+""}
|
||||
|
||||
body=dict(body=payload)
|
||||
request(url+"projects/"+projectid+"/members", 'post', **body)
|
||||
|
||||
@ -163,22 +171,18 @@ def do_data_creation():
|
||||
push_image("busybox", data["projects"][0]["name"])
|
||||
push_signed_image("alpine", data["projects"][0]["name"], "latest")
|
||||
|
||||
|
||||
for endpoint in data["endpoint"]:
|
||||
harborAPI.add_endpoint(endpoint["url"], endpoint["name"], endpoint["user"], endpoint["pass"], False)
|
||||
|
||||
for replicationrule in data["replicationrule"]:
|
||||
harborAPI.add_replication_rule(replicationrule["project"],
|
||||
replicationrule["endpoint"], replicationrule["trigger"],
|
||||
replicationrule["rulename"])
|
||||
|
||||
for project in data["projects"]:
|
||||
harborAPI.update_project_setting(project["name"],
|
||||
project["configuration"]["enable_content_trust"],
|
||||
project["configuration"]["prevent_vulnerable_images_from_running"],
|
||||
project["configuration"]["prevent_vlunerable_images_from_running_severity"],
|
||||
project["configuration"]["automatically_scan_images_on_push"])
|
||||
|
||||
harborAPI.update_systemsetting(data["configuration"]["emailsetting"]["emailfrom"],
|
||||
data["configuration"]["emailsetting"]["emailserver"],
|
||||
float(data["configuration"]["emailsetting"]["emailport"]),
|
||||
@ -186,5 +190,4 @@ def do_data_creation():
|
||||
data["configuration"]["projectcreation"],
|
||||
data["configuration"]["selfreg"],
|
||||
float(data["configuration"]["token"]))
|
||||
|
||||
do_data_creation()
|
Loading…
Reference in New Issue
Block a user