mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-18 04:53:57 +01:00
build.cmds.CmdListRepos: Support username/password authentication
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
50744fc41e
commit
27e9b23849
2 changed files with 67 additions and 32 deletions
|
|
@ -23,10 +23,13 @@ class CmdListRepos(Cmd): # export
|
|||
|
||||
from urllib.parse import urlparse
|
||||
url = urlparse(args.base_url)
|
||||
username = get_username(args=args, url=args.base_url)
|
||||
askpass_env=['GIT_ASKPASS', 'SSH_ASKPASS']
|
||||
username = get_username(args=args, url=args.base_url, askpass_env=askpass_env)
|
||||
password = None
|
||||
if username is not None:
|
||||
password = get_password(args=args, url=args.base_url, askpass_env=askpass_env)
|
||||
match url.scheme:
|
||||
case 'ssh':
|
||||
password = get_password(args=args, url=args.base_url, askpass_env=['GIT_ASKPASS', 'SSH_ASKPASS'])
|
||||
if re.match(r'ssh://.*git\.janware\.com/', args.base_url):
|
||||
from jw.build.lib.SSHClient import SSHClientCmd as SSHClient
|
||||
ssh = SSHClient(hostname=url.hostname)
|
||||
|
|
@ -39,16 +42,19 @@ class CmdListRepos(Cmd): # export
|
|||
print(out)
|
||||
return
|
||||
case 'https':
|
||||
cmd_input = None
|
||||
if re.match(r'https://github.com', args.base_url):
|
||||
curl_args = [
|
||||
'-f',
|
||||
'-H',
|
||||
'Accept: application/vnd.github+json',
|
||||
'-H',
|
||||
'X-GitHub-Api-Version: 2022-11-28',
|
||||
f'https://api.github.com/users/{args.from_user}/repos'
|
||||
'-H', 'Accept: application/vnd.github+json',
|
||||
'-H', 'X-GitHub-Api-Version: 2022-11-28',
|
||||
]
|
||||
repos = run_curl(curl_args)
|
||||
if password is not None:
|
||||
assert username is not None
|
||||
cmd_input = (f'-u {username}:{password}').encode('utf-8')
|
||||
curl_args.extend(['-K-'])
|
||||
curl_args.append(f'https://api.github.com/users/{args.from_user}/repos')
|
||||
repos = run_curl(curl_args, cmd_input=cmd_input)
|
||||
for repo in repos:
|
||||
print(repo['name'])
|
||||
return
|
||||
|
|
@ -57,10 +63,14 @@ class CmdListRepos(Cmd): # export
|
|||
curl_args = ['-f']
|
||||
if re.match(r'https://janware.test', args.base_url):
|
||||
curl_args.append('--insecure')
|
||||
if password is not None:
|
||||
assert username is not None
|
||||
cmd_input = (f'-u {username}:{password}').encode('utf-8')
|
||||
curl_args.extend(['-K-'])
|
||||
curl_args.extend([
|
||||
f'https://{url.hostname}/code/api/v1/orgs/{args.from_user}/repos'
|
||||
])
|
||||
repos = run_curl(curl_args)
|
||||
repos = run_curl(curl_args, cmd_input=cmd_input)
|
||||
for repo in repos:
|
||||
print(repo['name'])
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue