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
3a16acf3
Commit
3a16acf3
authored
Oct 28, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #177 from feedhenry/keys_list
Added list-keys command, with associated spec
parents
8f9c11af
89d8af46
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
0 deletions
+34
-0
README.md
README.md
+5
-0
bin/gitlab-keys
bin/gitlab-keys
+2
-0
lib/gitlab_keys.rb
lib/gitlab_keys.rb
+14
-0
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+13
-0
No files found.
README.md
View file @
3a16acf3
...
...
@@ -78,6 +78,11 @@ Remove key:
./bin/gitlab-keys rm-key key-23 "ssh-rsa AAAAx321..."
List all keys:
./bin/gitlab-keys list-keys
Remove all keys from authorized_keys file:
./bin/gitlab-keys clear
bin/gitlab-keys
View file @
3a16acf3
...
...
@@ -12,6 +12,8 @@ require_relative '../lib/gitlab_init'
#
# /bin/gitlab-keys rm-key key-23 "ssh-rsa AAAAx321..."
#
# /bin/gitlab-keys list-keys
#
# /bin/gitlab-keys clear
#
...
...
lib/gitlab_keys.rb
View file @
3a16acf3
...
...
@@ -19,6 +19,7 @@ class GitlabKeys
when
'add-key'
;
add_key
when
'batch-add-keys'
;
batch_add_keys
when
'rm-key'
;
rm_key
when
'list-keys'
;
puts
list_keys
when
'clear'
;
clear
else
$logger
.
warn
"Attempt to execute invalid gitlab-keys command
#{
@command
.
inspect
}
."
...
...
@@ -38,6 +39,19 @@ class GitlabKeys
true
end
def
list_keys
$logger
.
info
'Listing all keys'
keys
=
''
File
.
readlines
(
auth_file
).
each
do
|
line
|
# key_id & public_key
# command=".../bin/gitlab-shell key-741" ... ssh-rsa AAAAB3NzaDAxx2E\n
# ^^^^^^^ ^^^^^^^^^^^^^^^
matches
=
/^command=\".+?\s+(.+?)\".+?ssh-rsa\s(.+)\s*.*\n*$/
.
match
(
line
)
keys
<<
"
#{
matches
[
1
]
}
#{
matches
[
2
]
}
\n
"
unless
matches
.
nil?
end
keys
end
def
batch_add_keys
lock
do
open
(
auth_file
,
'a'
)
do
|
file
|
...
...
spec/gitlab_keys_spec.rb
View file @
3a16acf3
...
...
@@ -41,6 +41,19 @@ describe GitlabKeys do
end
end
describe
:list_keys
do
let
(
:gitlab_keys
)
do
build_gitlab_keys
(
'add-key'
,
'key-741'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
end
it
'adds a key and lists it'
do
create_authorized_keys_fixture
gitlab_keys
.
send
:add_key
auth_line1
=
'key-741 AAAAB3NzaDAxx2E'
gitlab_keys
.
send
(
:list_keys
).
should
==
"
#{
auth_line1
}
\n
"
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'
)
}
...
...
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