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:
```
$ curl -s https://code.infektor.net/config/bootstrap/raw/master/bootstrap-macOS.sh | sh
```console
$ 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:
```
$ wget https://code.infektor.net/config/bootstrap/raw/master/bootstrap-Debian.sh -O - | sh
```console
$ 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:
```
```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
```
@ -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
Cloud, or Gogs servers:
```
pip install git+https://code.infektor.net/config/bootstrap.git
python -c 'import bootstrap; bootstrap.set_ssh_keys()'
```console
$ pip install git+https://code.infektor.net/config/bootstrap.git
$ python -c 'import bootstrap; bootstrap.set_ssh_keys()'
```

View File

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