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
c6fa7e5e
Commit
c6fa7e5e
authored
Feb 03, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add/remove keys to authorized_keys
parent
b83ab386
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
+59
-0
bin/gitlab-keys
bin/gitlab-keys
+14
-0
config.yml.example
config.yml.example
+1
-0
lib/gitlab_keys.rb
lib/gitlab_keys.rb
+44
-0
No files found.
bin/gitlab-keys
0 → 100755
View file @
c6fa7e5e
#!/usr/bin/env ruby
#
# GitLab Keys shell. Add/remove keys from ~/.ssh/authorized_keys
#
# Ex.
# /bin/gitlab-keys add-key dzaporozhets "ssh-rsa AAAAx321..."
#
#
ROOT_PATH
=
File
.
join
(
File
.
expand_path
(
File
.
dirname
(
__FILE__
)),
".."
)
require
File
.
join
(
ROOT_PATH
,
'lib'
,
'gitlab_keys'
)
GitlabKeys
.
new
.
exec
exit
config.yml.example
View file @
c6fa7e5e
user: git
user: git
repos_path: "/home/git/repositories"
repos_path: "/home/git/repositories"
auth_file: "/home/git/.ssh/authorized_keys"
lib/gitlab_keys.rb
0 → 100644
View file @
c6fa7e5e
require
'open3'
require
'yaml'
class
GitlabKeys
attr_accessor
:auth_file
,
:key
,
:username
def
initialize
@command
=
ARGV
.
shift
@username
=
ARGV
.
shift
@key
=
ARGV
.
shift
config
=
YAML
.
load_file
(
File
.
join
(
ROOT_PATH
,
'config.yml'
))
@auth_file
=
config
[
'auth_file'
]
end
def
exec
case
@command
when
'add-key'
;
add_key
when
'rm-key'
;
rm_key
when
'rm-user'
;
rm_user
else
puts
'not allowed'
end
end
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
=
"echo
\"
#{
cmd
}
\"
>>
#{
auth_file
}
"
system
(
cmd
)
end
def
rm_key
cmd
=
"sed '/
#{
@key
}
/d'
#{
auth_file
}
"
system
(
cmd
)
end
def
rm_user
cmd
=
"sed -i '/
#{
@username
}
/d'
#{
auth_file
}
"
puts
cmd
system
(
cmd
)
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