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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-shell
Commits
2241d767
Commit
2241d767
authored
Feb 05, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add/remove keys by id
parent
a8b9cb85
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
bin/gitlab-keys
bin/gitlab-keys
+2
-2
lib/gitlab_keys.rb
lib/gitlab_keys.rb
+4
-4
spec/gitlab_keys_spec.rb
spec/gitlab_keys_spec.rb
+6
-6
No files found.
bin/gitlab-keys
View file @
2241d767
...
...
@@ -6,9 +6,9 @@ require_relative '../lib/gitlab_init'
# GitLab Keys shell. Add/remove keys from ~/.ssh/authorized_keys
#
# Ex.
# /bin/gitlab-keys add-key
dzaporozhets
"ssh-rsa AAAAx321..."
# /bin/gitlab-keys add-key
key-782
"ssh-rsa AAAAx321..."
#
# /bin/gitlab-keys rm-key
dzaporozhets
"ssh-rsa AAAAx321..."
# /bin/gitlab-keys rm-key
key-23
"ssh-rsa AAAAx321..."
#
require
File
.
join
(
ROOT_PATH
,
'lib'
,
'gitlab_keys'
)
...
...
lib/gitlab_keys.rb
View file @
2241d767
...
...
@@ -2,11 +2,11 @@ require 'open3'
require_relative
'gitlab_config'
class
GitlabKeys
attr_accessor
:auth_file
,
:key
,
:username
attr_accessor
:auth_file
,
:key
def
initialize
@command
=
ARGV
.
shift
@
username
=
ARGV
.
shift
@
key_id
=
ARGV
.
shift
@key
=
ARGV
.
shift
@auth_file
=
GitlabConfig
.
new
.
auth_file
end
...
...
@@ -23,13 +23,13 @@ class GitlabKeys
protected
def
add_key
cmd
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell
#{
@
username
}
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty
#{
@key
}
"
cmd
=
"command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell
#{
@
key_id
}
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty
#{
@key
}
"
cmd
=
"echo
\'
#{
cmd
}
\'
>>
#{
auth_file
}
"
system
(
cmd
)
end
def
rm_key
cmd
=
"sed '/
#{
@key
}
/d'
#{
auth_file
}
"
cmd
=
"sed '/
#{
@key
_id
}
/d'
#{
auth_file
}
"
system
(
cmd
)
end
end
spec/gitlab_keys_spec.rb
View file @
2241d767
...
...
@@ -4,23 +4,23 @@ require_relative '../lib/gitlab_keys'
describe
GitlabKeys
do
describe
:initialize
do
before
do
argv
(
'add-key'
,
'
dzaporozhets
'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
argv
(
'add-key'
,
'
key-741
'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
@gl_keys
=
GitlabKeys
.
new
end
it
{
@gl_keys
.
username
.
should
==
'dzaporozhets'
}
it
{
@gl_keys
.
key
.
should
==
'ssh-rsa AAAAB3NzaDAxx2E'
}
it
{
@gl_keys
.
instance_variable_get
(
:@command
).
should
==
'add-key'
}
it
{
@gl_keys
.
instance_variable_get
(
:@key_id
).
should
==
'key-741'
}
end
describe
:add_key
do
before
do
argv
(
'add-key'
,
'
dzaporozhets
'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
argv
(
'add-key'
,
'
key-741
'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
@gl_keys
=
GitlabKeys
.
new
end
it
"should receive valid cmd"
do
valid_cmd
=
"echo 'command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell
dzaporozhets
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaDAxx2E' >> /home/git/.ssh/authorized_keys"
valid_cmd
=
"echo 'command=
\"
#{
ROOT_PATH
}
/bin/gitlab-shell
key-741
\"
,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB3NzaDAxx2E' >> /home/git/.ssh/authorized_keys"
@gl_keys
.
should_receive
(
:system
).
with
(
valid_cmd
)
@gl_keys
.
send
:add_key
end
...
...
@@ -28,12 +28,12 @@ describe GitlabKeys do
describe
:rm_key
do
before
do
argv
(
'rm-key'
,
'
dzaporozhets
'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
argv
(
'rm-key'
,
'
key-741
'
,
'ssh-rsa AAAAB3NzaDAxx2E'
)
@gl_keys
=
GitlabKeys
.
new
end
it
"should receive valid cmd"
do
valid_cmd
=
"sed '/
ssh-rsa AAAAB3NzaDAxx2E
/d' /home/git/.ssh/authorized_keys"
valid_cmd
=
"sed '/
key-741
/d' /home/git/.ssh/authorized_keys"
@gl_keys
.
should_receive
(
:system
).
with
(
valid_cmd
)
@gl_keys
.
send
:rm_key
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