Merge ~kirkland/ssh-import-id:master into ssh-import-id:master

Proposed by Dustin Kirkland 
Status: Needs review
Proposed branch: ~kirkland/ssh-import-id:master
Merge into: ssh-import-id:master
Diff against target: 246 lines (+71/-21)
11 files modified
README.md (+3/-2)
debian/changelog (+9/-0)
debian/control (+3/-3)
debian/copyright (+1/-1)
debian/links (+1/-0)
debian/rules (+3/-7)
dev/null (+0/-5)
setup.py (+2/-1)
ssh_import_id/__init__.py (+21/-1)
usr/bin/ssh-import-id-gl (+24/-0)
usr/share/man/man1/ssh-import-id.1 (+4/-1)
Reviewer Review Type Date Requested Status
Robie Basak Pending
Review via email: mp+445392@code.launchpad.net

Commit message

Added support for Gitlab

Description of the change

Added support for Gitlab

To post a comment you must log in.

Unmerged commits

17a4c7d... by Dustin Kirkland 

added Gitlab support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2index e839b64..5bea7d5 100644
3--- a/README.md
4+++ b/README.md
5@@ -8,7 +8,7 @@ Oh. You have to ask them to cat their public SSH key, paste it into IRC (wait, n
6
7 That's where ssh-import-id comes in. With ssh-import-id, you can add the public SSH keys from a known, trusted online identity to grant SSH access.
8
9-Currently supported identities include Github and Launchpad.
10+Currently supported identities include Github, Gitlab, and Launchpad.
11
12 Usage
13 -----
14@@ -16,6 +16,7 @@ Usage
15 ssh-import-id uses short prefix to indicate the location of the online identity. For now, these are:
16
17 'gh:' for Github
18+ 'gl:' for Gitlab
19 'lp:' for Launchpad
20
21 Command line help:
22@@ -41,7 +42,7 @@ If you wanted me to be able to ssh into your server, as the desired user on that
23
24 You can also import multiple users on the same line, even from different key services, like so:
25
26- $ ssh-import-id gh:cmars lp:kirkland
27+ $ ssh-import-id gh:cmars lp:kirkland gl:speeves
28
29 Used with care, it's a great collaboration tool!
30
31diff --git a/debian/changelog b/debian/changelog
32index 32ed111..13e6200 100644
33--- a/debian/changelog
34+++ b/debian/changelog
35@@ -1,3 +1,12 @@
36+ssh-import-id (5.12) unreleased; urgency=medium
37+
38+ [ Dustin Kirkland, Shannon Eric Peevey, Gabriel Mazetto ]
39+ * debian/control, debian/copyright, debian/links, README.md, setup.py,
40+ ssh_import_id/__init__.py, usr/share/man/man1/ssh-import-id.1:
41+ - adding support for Gitlab.com
42+
43+ -- Dustin Kirkland <kirkland@ubuntu.com> Mon, 26 Jun 2023 19:50:29 -0500
44+
45 ssh-import-id (5.11-0ubuntu1) hirsute; urgency=medium
46
47 * Upstream Release 5.11
48diff --git a/debian/changelog.trunk b/debian/changelog.trunk
49deleted file mode 100644
50index 39d90e2..0000000
51--- a/debian/changelog.trunk
52+++ /dev/null
53@@ -1,5 +0,0 @@
54-ssh-import-id (UPSTREAM_VER-0~upstream0) UNRELEASED; urgency=medium
55-
56- * UNRELEASED
57-
58- -- Dustin Kirkland <kirkland@ubuntu.com> Tue, 11 Jul 2017 15:51:44 -0500
59diff --git a/debian/control b/debian/control
60index 99c5b75..e24998e 100644
61--- a/debian/control
62+++ b/debian/control
63@@ -24,6 +24,6 @@ Depends: ca-certificates,
64 Recommends: openssh-server
65 Description: securely retrieve an SSH public key and install it locally
66 This utility will securely contact a public keyserver (Launchpad.net by
67- default, but Github.com is also supported), retrieve one or more user's
68- public keys, and append these to the current user's ~/.ssh/authorized_keys
69- file.
70+ default, but Github.com and Gitlab.com are also supported), retrieve one
71+ or more user's public keys, and append these to the current user's
72+ ~/.ssh/authorized_keys file.
73diff --git a/debian/copyright b/debian/copyright
74index bb8e48a..ffedd84 100644
75--- a/debian/copyright
76+++ b/debian/copyright
77@@ -6,7 +6,7 @@ Upstream-Contact: Dustin Kirkland <kirkland@ubuntu.com>
78 Files: *
79 Copyright: 2010, Canonical Ltd.
80 2013, Casey Marshall <casey.marshall@gmail.com>
81- 2013, Dustin Kirkland <dustin.kirkland@gmail.com>
82+ 2013-2023, Dustin Kirkland <dustin.kirkland@gmail.com>
83 License: GPL-3
84 This program is free software: you can redistribute it and/or modify
85 it under the terms of the GNU General Public License as published by
86diff --git a/debian/links b/debian/links
87index 1ad132a..39d8ac8 100644
88--- a/debian/links
89+++ b/debian/links
90@@ -1,2 +1,3 @@
91 usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-lp.1
92 usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-gh.1
93+usr/share/man/man1/ssh-import-id.1 usr/share/man/man1/ssh-import-id-gl.1
94diff --git a/debian/rules b/debian/rules
95index 75bb1da..f66f72d 100755
96--- a/debian/rules
97+++ b/debian/rules
98@@ -3,13 +3,9 @@
99 # Uncomment this to turn on verbose mode.
100 #export DH_VERBOSE=1
101
102-DEB_VERSION := $(shell dpkg-parsechangelog --show-field=Version)
103-
104 %:
105 dh $@ --with python3 --buildsystem=pybuild
106
107-override_dh_auto_install:
108- dh_auto_install
109- # upstream provides a way to patch in the distro
110- # version by replacing @@PACKAGED_VERSION@@ in version.py
111- for f in $$(find $(CURDIR)/debian/ -type f -name version.py); do [ -f "$$f" ] || continue; sed -i 's,@@PACKAGED_VERSION@@,$(DEB_VERSION),' "$$f"; done
112+override_dh_clean:
113+ rm -rf *.egg-info/
114+ dh_clean
115diff --git a/setup.py b/setup.py
116index f00afa6..45b5629 100755
117--- a/setup.py
118+++ b/setup.py
119@@ -2,6 +2,7 @@
120 #
121 # ssh-import-id - Authorize SSH public keys from trusted online identities.
122 # Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>
123+# Copyright (c) 2023 Dustin Kirkland <dustin.kirkland@gmail.com>
124 #
125 # ssh-import-id is free software: you can redistribute it and/or modify
126 # it under the terms of the GNU General Public License as published by
127@@ -50,7 +51,7 @@ setup(
128 url='https://launchpad.net/ssh-import-id',
129 platforms=['any'],
130 packages=['ssh_import_id'],
131- scripts=['usr/bin/ssh-import-id-gh', 'usr/bin/ssh-import-id-lp'],
132+ scripts=['usr/bin/ssh-import-id-gh', 'usr/bin/ssh-import-id-lp', 'usr/bin/ssh-import-id-gl'],
133 install_requires=["distro"],
134 entry_points={
135 'console_scripts': [
136diff --git a/ssh_import_id/__init__.py b/ssh_import_id/__init__.py
137index 034adda..b8a05a9 100644
138--- a/ssh_import_id/__init__.py
139+++ b/ssh_import_id/__init__.py
140@@ -3,7 +3,7 @@
141 # ssh-import-id - Authorize SSH public keys from trusted online identities
142 #
143 # Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>
144-# Copyright (c) 2013 Dustin Kirkland <dustin.kirkland@gmail.com>
145+# Copyright (c) 2013-2023 Dustin Kirkland <dustin.kirkland@gmail.com>
146 #
147 # ssh-import-id is free software: you can redistribute it and/or modify
148 # it under the terms of the GNU General Public License as published by
149@@ -26,6 +26,7 @@ except ImportError:
150 JSONDecodeError = ValueError
151 import logging
152 import os
153+import requests
154 import subprocess
155 import sys
156 import tempfile
157@@ -224,6 +225,8 @@ def fetch_keys(proto, username, useragent):
158 return fetch_keys_lp(username, useragent)
159 if proto == "gh":
160 return fetch_keys_gh(username, useragent)
161+ if proto == "gl":
162+ return fetch_keys_gl(username, useragent)
163
164 die("ssh-import-id protocol handler %s: not found or cannot execute" %
165 (proto))
166@@ -355,6 +358,23 @@ def fetch_keys_gh(ghid, useragent):
167 die(str(e))
168 return keys
169
170+def fetch_keys_gl(glid, useragent):
171+ try:
172+ url = os.getenv("URL", None)
173+ if url is not None:
174+ url = url % (quote_plus(glid))
175+ # Finally, fall back to gitlab.com
176+ if url is None:
177+ url = "https://gitlab.com/%s.keys" % (quote_plus(glid))
178+ headers = {'User-Agent': user_agent(useragent)}
179+ text = requests.get(url, verify=True, headers=headers).text
180+ keys = str(text)
181+ except (Exception,):
182+ e = sys.exc_info()[1]
183+ sys.stderr.write("ERROR: %s\n" % (str(e)))
184+ os._exit(1)
185+ return keys
186+
187
188 def main():
189 errors = []
190diff --git a/usr/bin/ssh-import-id-gl b/usr/bin/ssh-import-id-gl
191new file mode 100644
192index 0000000..5aa5fa7
193--- /dev/null
194+++ b/usr/bin/ssh-import-id-gl
195@@ -0,0 +1,24 @@
196+#!/bin/sh
197+#
198+# ssh-import-id-gl - Authorize SSH public keys from trusted online identities.
199+#
200+# Copyright (c) 2016-2023 Dustin Kirkland <dustin.kirkland@gmail.com>
201+# Copyright (c) 2022 Shannon Eric Peevey <shannonpeevey@gmail.com>
202+#
203+# ssh-import-id is free software: you can redistribute it and/or modify
204+# it under the terms of the GNU General Public License as published by
205+# the Free Software Foundation, version 3.
206+#
207+# ssh-import-id is distributed in the hope that it will be useful,
208+# but WITHOUT ANY WARRANTY; without even the implied warranty of
209+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
210+# GNU General Public License for more details.
211+#
212+# You should have received a copy of the GNU General Public License
213+# along with ssh-import-id. If not, see <http://www.gnu.org/licenses/>.
214+
215+set -e
216+
217+for i in $@; do
218+ ssh-import-id gl:$i
219+done
220diff --git a/usr/share/man/man1/ssh-import-id.1 b/usr/share/man/man1/ssh-import-id.1
221index 6d26fa7..fa52bb5 100644
222--- a/usr/share/man/man1/ssh-import-id.1
223+++ b/usr/share/man/man1/ssh-import-id.1
224@@ -9,12 +9,14 @@
225
226 .BI "ssh\-import\-id\-gh USER_ID_1 [USER_ID_2] ... [USER_ID_n]
227
228+.BI "ssh\-import\-id\-gl USER_ID_1 [USER_ID_2] ... [USER_ID_n]
229+
230 .SH OPTIONS
231 \-h | \-\-help usage
232 \-o | \-\-output F write output to file 'F' (default ~/.ssh/authorized_keys, use "\-" for standard out)
233 \-r | \-\-remove remove keys from authorized keys file 'F'
234 \-u | \-\-useragent U append U to the user agent string
235- PROTO:USER_ID Protocol can be 'lp' for Launchpad.net, or 'gh' for Github.com
236+ PROTO:USER_ID Protocol can be 'lp' for Launchpad.net, 'gh' for Github.com, or 'gl' for Gitlab.com
237
238 .SH DESCRIPTION
239 This utility will securely contact a public keyserver and retrieve one or more user's public keys, and append these to the current user's \fI~/.ssh/authorized_keys\fP file, standard output or any other specified output file.
240@@ -23,6 +25,7 @@ User IDs can be prepended by a protocol:
241
242 - \fBlp:\fP to use \fIhttps://launchpad.net/~%s/+sshkeys\fP
243 - \fBgh:\fP to use \fIhttps://api.github.com/users/%s/keys\fP
244+ - \fBgl:\fP to use \fIhttps://gitlab.com/%s.keys\fP
245
246 If the protocol is not explicitly specified, then \fBssh-import-id\fP will read a URL variable string from \fI/etc/ssh/ssh_import_id\fP as installed by your package manager and configured by your system administrator. You can override this locally by exporting the string you want in a URL environment variable. If all of these are empty, then the protocol is assumed to be "lp:", which was the original target implementation of this tool.
247

Subscribers

People subscribed via source and target branches