mirror of
https://github.com/goharbor/harbor.git
synced 2026-10-24 21:59:32 +03:00
- Use stdlib crypto/pbkdf2 instead of golang.org/x/crypto/pbkdf2 for password/secret hashing (output unchanged; no migration needed). - Restrict JWT signing to RSA/RSA-PSS and reject other methods in pkg/token (default RS256 unchanged). - Remove unused common/utils/email package (no references in codebase). Signed-off-by: wang yan <yan-yw.wang@broadcom.com> Co-authored-by: wang yan <yan-yw.wang@broadcom.com>
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import base
|
|
from datetime import datetime
|
|
|
|
oras_cmd = "oras"
|
|
file_artifact = "artifact.txt"
|
|
file_readme = "readme.md"
|
|
file_config = "config.json"
|
|
|
|
def oras_push(harbor_server, user, password, project, repo, tag):
|
|
oras_login(harbor_server, user, password)
|
|
fo = open(file_artifact, "w")
|
|
fo.write( "hello artifact" )
|
|
fo.close()
|
|
sha256_artifact = base.run_command( ["sha256sum", file_artifact] )
|
|
fo = open(file_readme, "w")
|
|
fo.write( r"Docs on this artifact" )
|
|
fo.close()
|
|
sha256_readme = base.run_command( [ "sha256sum", file_readme] )
|
|
fo = open(file_config, "w")
|
|
fo.write( "{\"doc\":\"readme.md\"}" )
|
|
fo.close()
|
|
|
|
exception = None
|
|
for _ in range(5):
|
|
exception = oras_push_cmd(harbor_server, project, repo, tag)
|
|
if exception == None:
|
|
break
|
|
if exception != None:
|
|
raise exception
|
|
return sha256_artifact.split()[0], sha256_readme.split()[0]
|
|
|
|
def oras_push_cmd(harbor_server, project, repo, tag):
|
|
try:
|
|
ret = base.run_command( [oras_cmd, "push", harbor_server + "/" + project + "/" + repo+":"+ tag,
|
|
"--config", "config.json:application/vnd.acme.rocket.config.v1+json", \
|
|
file_artifact+":application/vnd.acme.rocket.layer.v1+txt", \
|
|
file_readme +":application/vnd.acme.rocket.docs.layer.v1+json"] )
|
|
return None
|
|
except Exception as e:
|
|
print("Run command error:", str(e))
|
|
return e
|
|
|
|
def oras_login(harbor_server, user, password):
|
|
ret = base.run_command([oras_cmd, "login", "-u", user, "-p", password, harbor_server])
|
|
|
|
def oras_pull(harbor_server, user, password, project, repo, tag):
|
|
try:
|
|
cwd = os.getcwd()
|
|
cwd= cwd + r"/tmp" + datetime.now().strftime(r'%m%s')
|
|
if os.path.exists(cwd):
|
|
os.rmdir(cwd)
|
|
os.makedirs(cwd)
|
|
os.chdir(cwd)
|
|
except Exception as e:
|
|
raise Exception('Error: Exited with error {}',format(e))
|
|
ret = base.run_command([oras_cmd, "pull", harbor_server + "/" + project + "/" + repo+":"+ tag])
|
|
assert os.path.exists(file_artifact)
|
|
assert os.path.exists(file_readme)
|
|
return base.run_command( ["sha256sum", file_artifact] ).split()[0], base.run_command( [ "sha256sum", file_readme] ).split()[0]
|