Commit b9d58c4cecd06be74c3cc32ccfb522b31544ab2e

Authored by devaroop
1 parent e219cf72

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
CHANGELOG
1 1 v 6.2.0
  2 + - Retrieving user ssh keys publically(github style): http://__HOST__/__USERNAME__.keys
2 3 - Public projects are visible from the outside
3 4 - Add group access to permissions page
4 5 - Require current password to change one
... ...
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 &lt; 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
... ... @@ -391,4 +391,8 @@ class User &lt; ActiveRecord::Base
391 391  
392 392 self
393 393 end
  394 +
  395 + def all_ssh_keys
  396 + keys.collect{|x| x.key}.join("\n")
  397 + end
394 398 end
... ...
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
... ...