Commit b9d58c4cecd06be74c3cc32ccfb522b31544ab2e
1 parent
e219cf72
Exists in
spb-stable
and in
3 other branches
getting user keys publically through http without any authentication, the github…
… way. E.g: http://github.com/devaroop.keys changelog updated to include ssh key retrieval feature update
Showing
4 changed files
with
26 additions
and
0 deletions
Show diff stats
CHANGELOG
app/controllers/profiles/keys_controller.rb
1 | 1 | class Profiles::KeysController < ApplicationController |
2 | 2 | layout "profile" |
3 | + skip_before_filter :authenticate_user!, only: [:get_keys] | |
3 | 4 | |
4 | 5 | def index |
5 | 6 | @keys = current_user.keys.order('id DESC').all |
... | ... | @@ -32,4 +33,21 @@ class Profiles::KeysController < ApplicationController |
32 | 33 | format.js { render nothing: true } |
33 | 34 | end |
34 | 35 | end |
36 | + | |
37 | + #get all keys of a user(params[:username]) in a text format | |
38 | + #helpful for sysadmins to put in respective servers | |
39 | + def get_keys | |
40 | + if params[:username].present? | |
41 | + begin | |
42 | + user = User.find_by_username(params[:username]) | |
43 | + user.present? ? (render :text => user.all_ssh_keys) : | |
44 | + (render_404 and return) | |
45 | + rescue => e | |
46 | + render text: e.message | |
47 | + end | |
48 | + else | |
49 | + render_404 and return | |
50 | + end | |
51 | + end | |
52 | + | |
35 | 53 | end | ... | ... |
app/models/user.rb
config/routes.rb
... | ... | @@ -11,6 +11,9 @@ Gitlab::Application.routes.draw do |
11 | 11 | API::API.logger Rails.logger |
12 | 12 | mount API::API => '/api' |
13 | 13 | |
14 | + #get all keys of user | |
15 | + get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ } | |
16 | + | |
14 | 17 | constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } |
15 | 18 | constraints constraint do |
16 | 19 | mount Sidekiq::Web, at: "/admin/sidekiq", as: :sidekiq | ... | ... |