Skip to content

Commit 8b402e4

Browse files
committed
Document authentication behavior in README
Signed-off-by: Kyle Fazzari <[email protected]>
1 parent 157967f commit 8b402e4

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

README.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,48 @@ The set of repositories to operate on can optionally be restricted by the type:
138138
If the command should work on multiple repositories make sure to pass only generic arguments which work for all of these repository types.
139139

140140

141+
Access repositories that require authentication
142+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143+
144+
Vcstool supports authenticated access to repositories by parsing files with a netrc-like format.
145+
It will first look for login information in the ~/.netrc file, used by ftp, git, and similar programs if it exists.
146+
If it doesn't exist (or doesn't contain login infomation for the URL in question), it moves to vcstool-specific locations.
147+
In these locations vcstool will look for credentials in either an `auth.conf` file, or .conf files inside an `auth.conf.d` directory.
148+
These locations are (in order of precedence):
149+
150+
1. User config directory.
151+
- On Linux, abides by XDG spec: `~/.config/vcstool/`
152+
- On macOS: `~/Library/Application Support/vcstool/`
153+
- On Windows: `C:\Users\<username>\AppData\Local\vcstool\vcstool\`
154+
2. Site config directory.
155+
- On Linux: `vcstool/` subdirectory in any directory within `$XDG_CONFIG_DIRS`, or `/etc/xdg/vcstool/` if unset
156+
- On macOS: `/Library/Application Support/vcstool/`
157+
- On Windows: `C:\ProgramData\vcstool\vcstool\`
158+
159+
The netrc-like format consists of a few different tokens separated by whitespace (spaces, tabs, or newlines):
160+
161+
- `machine <name>`: Credentials are retrieved by matching the repository URL to this token
162+
- `login <name>`: Login username
163+
- `password <string>`: Login password
164+
165+
For example, to access private github repositories:
166+
167+
```
168+
machine github.com
169+
login mylogin
170+
password myaccesstoken
171+
```
172+
173+
Accessing private gitlab repositories looks similar, although no `login` is required:
174+
175+
```
176+
machine gitlab.com
177+
password myaccesstoken
178+
```
179+
180+
A word of caution: these files are not encrypted.
181+
Ensure that their permissions do not exeed that which is required.
182+
141183
How to install vcstool?
142184
=======================
143185

vcstool/clients/vcs_base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,15 @@ def _credentials_for_machine(machine):
222222
if credentials:
223223
return credentials
224224

225-
# Finally, check the system-wide auth directory for vcstool
226-
return _credentials_for_machine_in_dir(
227-
appdirs.site_config_dir(_APPDIRS_PROJECT_NAME), machine)
225+
# Finally, check the system-wide auth directories for vcstool, in order
226+
auth_path = appdirs.site_config_dir(_APPDIRS_PROJECT_NAME, multipath=True)
227+
for site_config_dir in auth_path.split(':'):
228+
credentials = _credentials_for_machine_in_dir(
229+
site_config_dir, machine)
230+
if credentials:
231+
return credentials
232+
233+
return None
228234

229235

230236
def _credentials_for_machine_in_dir(directory, machine):

0 commit comments

Comments
 (0)