Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
4539a066
Commit
4539a066
authored
Jun 28, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'add-list-key-ids' into 'master'
Add list-key-ids command See merge request !140
parents
7e41e378
fb4260ce
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
3 deletions
+62
-3
CHANGELOG
CHANGELOG
+3
-0
VERSION
VERSION
+1
-1
lib/gitlab_keys.rb
lib/gitlab_keys.rb
+13
-0
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+45
-2
No files found.
CHANGELOG
View file @
4539a066
v5.1.0
- Add `gitlab-keys list-key-ids` subcommand for iterating over key IDs to find keys that should be deleted
v5.0.6
- Remove old `project` parameter, use `gl_repository` instead
- Use v4 of the GitLab REST API
...
...
VERSION
View file @
4539a066
5.
0.6
5.
1.0
lib/gitlab_keys.rb
View file @
4539a066
...
...
@@ -39,6 +39,8 @@ class GitlabKeys
rm_key
when
'list-keys'
;
list_keys
when
'list-key-ids'
;
list_key_ids
when
'clear'
;
clear
when
'check-permissions'
;
...
...
@@ -75,6 +77,17 @@ class GitlabKeys
keys
end
def
list_key_ids
$logger
.
info
'Listing all key IDs'
open_auth_file
(
'r'
)
do
|
f
|
f
.
each_line
do
|
line
|
matchd
=
line
.
match
(
/key-(\d+)/
)
next
unless
matchd
puts
matchd
[
1
]
end
end
end
def
batch_add_keys
lock
(
300
)
do
# Allow 300 seconds (5 minutes) for batch_add_keys
open_auth_file
(
'a'
)
do
|
file
|
...
...
spec/gitlab_keys_spec.rb
View file @
4539a066
...
...
@@ -80,6 +80,23 @@ describe GitlabKeys do
end
end
describe
:list_key_ids
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'list-key-ids'
)
}
before
do
create_authorized_keys_fixture
(
existing_content:
"key-1
\t
ssh-dsa AAA
\n
key-2
\t
ssh-rsa BBB
\n
key-3
\t
ssh-rsa CCC
\n
key-9000
\t
ssh-rsa DDD
\n
"
)
end
it
'outputs the key IDs, separated by newlines'
do
output
=
capture_stdout
do
gitlab_keys
.
send
(
:list_key_ids
)
end
output
.
should
match
"1
\n
2
\n
3
\n
9000"
end
end
describe
:batch_add_keys
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'batch-add-keys'
)
}
let
(
:fake_stdin
)
{
StringIO
.
new
(
"key-12
\t
ssh-dsa ASDFASGADG
\n
key-123
\t
ssh-rsa GFDGDFSGSDFG
\n
"
,
'r'
)
}
...
...
@@ -160,6 +177,23 @@ describe GitlabKeys do
gitlab_keys
.
send
(
:rm_key
).
should
be_true
end
end
context
'without key content'
do
let
(
:gitlab_keys
)
{
build_gitlab_keys
(
'rm-key'
,
'key-741'
)
}
it
"removes the right line by key ID"
do
create_authorized_keys_fixture
other_line
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-742
\"
,options ssh-rsa AAAAB3NzaDAxx2E"
delete_line
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell key-741
\"
,options ssh-rsa AAAAB3NzaDAxx2E"
open
(
tmp_authorized_keys_path
,
'a'
)
do
|
auth_file
|
auth_file
.
puts
delete_line
auth_file
.
puts
other_line
end
gitlab_keys
.
send
:rm_key
erased_line
=
delete_line
.
gsub
(
/./
,
'#'
)
File
.
read
(
tmp_authorized_keys_path
).
should
==
"existing content
\n
#{
erased_line
}
\n
#{
other_line
}
\n
"
end
end
end
describe
:clear
do
...
...
@@ -288,9 +322,9 @@ describe GitlabKeys do
end
end
def
create_authorized_keys_fixture
def
create_authorized_keys_fixture
(
existing_content:
'existing content'
)
FileUtils
.
mkdir_p
(
File
.
dirname
(
tmp_authorized_keys_path
))
open
(
tmp_authorized_keys_path
,
'w'
)
{
|
file
|
file
.
puts
(
'existing content'
)
}
open
(
tmp_authorized_keys_path
,
'w'
)
{
|
file
|
file
.
puts
(
existing_content
)
}
gitlab_keys
.
stub
(
auth_file:
tmp_authorized_keys_path
)
end
...
...
@@ -301,4 +335,13 @@ describe GitlabKeys do
def
tmp_lock_file_path
tmp_authorized_keys_path
+
'.lock'
end
def
capture_stdout
(
&
blk
)
old
=
$stdout
$stdout
=
fake
=
StringIO
.
new
blk
.
call
fake
.
string
ensure
$stdout
=
old
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment