Compare commits

...

2 Commits

2 changed files with 17 additions and 18 deletions

View File

@ -6,19 +6,19 @@ Bootstrap an OS instance with bare essentials.
To bootstrap a macOS instance: To bootstrap a macOS instance:
``` ```console
$ curl -s https://code.infektor.net/config/bootstrap/raw/master/bootstrap-macOS.sh | sh $ curl -O https://code.infektor.net/config/bootstrap/raw/master/bootstrap-macOS.sh && chmod +x bootstrap-macOS.sh && ./bootstrap-macOS.sh
``` ```
To bootstrap a Debain based Linux instance: To bootstrap a Debian based Linux instance:
``` ```console
$ wget https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Debian.sh -O - | sh $ wget https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Debian.sh && chmod +x bootstrap-Debian.sh && ./bootstrap-Debian.sh
``` ```
To bootstrap a Windows instance: To bootstrap a Windows instance:
``` ```console
$ bitsadmin /transfer bootstrap-Windows.cmd https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Windows.cmd %cd%\bootstrap-Windows.cmd & %cd%\bootstrap-Windows.cmd $ bitsadmin /transfer bootstrap-Windows.cmd https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Windows.cmd %cd%\bootstrap-Windows.cmd & %cd%\bootstrap-Windows.cmd
``` ```
@ -27,7 +27,7 @@ $ bitsadmin /transfer bootstrap-Windows.cmd https://code.infektor.net/config/boo
Install as a pip package to set SSH keys on any of GitHub, GitLab, BitBucket Install as a pip package to set SSH keys on any of GitHub, GitLab, BitBucket
Cloud, or Gogs servers: Cloud, or Gogs servers:
``` ```console
pip install git+https://code.infektor.net/config/bootstrap.git $ pip install git+https://code.infektor.net/config/bootstrap.git
python -c 'import bootstrap; bootstrap.set_ssh_keys()' $ python -c 'import bootstrap; bootstrap.set_ssh_keys()'
``` ```

View File

@ -105,22 +105,21 @@ def set_github_ssh_key():
def set_gitlab_ssh_key(): def set_gitlab_ssh_key():
"""Set GitLab SSH key.""" """Set GitLab SSH key."""
api_url = '%s/api/v4' % get_url('GitLab', 'https://gitlab.com') api_url = '%s/api/v4' % get_url('GitLab', 'https://gitlab.com')
session_url = '%s/session' % api_url
keys_url = '%s/user/keys' % api_url keys_url = '%s/user/keys' % api_url
username, password = get_username_password('GitLab') username, password = get_username_password('GitLab')
response = post(session_url, {'login': username, 'password': password}) credentials = {'login': username, 'password': password}
if response.status_code != 201: response = get(keys_url, credentials)
raise bootstrap_error(response)
auth = {'Private-Token': response.json()['private_token']}
response = get(keys_url, headers=auth)
if response.status_code != 200: if response.status_code != 200:
raise bootstrap_error(response) raise bootstrap_error(response)
keys = response.json() keys = response.json()
local_key = get_local_key() local_key = get_local_key()
if not key_exists(keys, local_key): if not key_exists(keys, local_key):
response = post( response = post(keys_url,
keys_url, headers=auth, json={'title': node(), credentials,
'key': local_key}) json={
'title': node(),
'key': local_key
})
if response.status_code != 201: if response.status_code != 201:
raise bootstrap_error(response) raise bootstrap_error(response)