diff --git a/CHANGELOG b/CHANGELOG index c1107717fc8dd4cae1906103c8b27234f3b29b2d..1459ef84ae924e170fb22d9e81c0ebb05c6020bc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ v 6.2.0 + - Retrieving user ssh keys publically(github style): http://__HOST__/__USERNAME__.keys - Public projects are visible from the outside - Add group access to permissions page - Require current password to change one diff --git a/app/controllers/profiles/keys_controller.rb b/app/controllers/profiles/keys_controller.rb index c36dae2abd31539ee42b5e15d9994f910e16f68f..2b991957b701af02e9741adeeb49b07d88c5d594 100644 --- a/app/controllers/profiles/keys_controller.rb +++ b/app/controllers/profiles/keys_controller.rb @@ -1,5 +1,6 @@ class Profiles::KeysController < ApplicationController layout "profile" + skip_before_filter :authenticate_user!, only: [:get_keys] def index @keys = current_user.keys.order('id DESC').all @@ -32,4 +33,21 @@ class Profiles::KeysController < ApplicationController format.js { render nothing: true } end end + + #get all keys of a user(params[:username]) in a text format + #helpful for sysadmins to put in respective servers + def get_keys + if params[:username].present? + begin + user = User.find_by_username(params[:username]) + user.present? ? (render :text => user.all_ssh_keys) : + (render_404 and return) + rescue => e + render text: e.message + end + else + render_404 and return + end + end + end diff --git a/app/models/user.rb b/app/models/user.rb index f1f93eadc1ae435cec0a6c040d8b911496d5ec11..225c97d35ffa341d569679d6c0e5be7983867f30 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -391,4 +391,8 @@ class User < ActiveRecord::Base self end + + def all_ssh_keys + keys.collect{|x| x.key}.join("\n") + end end diff --git a/config/routes.rb b/config/routes.rb index 612a7327ec565c1cc45ae687caaa3a67c128ee1c..1d2b4d737363a7aea853764ca3c6f320dab30f09 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,9 @@ Gitlab::Application.routes.draw do API::API.logger Rails.logger mount API::API => '/api' + #get all keys of user + get ':username.keys' => 'profiles/keys#get_keys' , constraints: { username: /.*/ } + constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } constraints constraint do mount Sidekiq::Web, at: "/admin/sidekiq", as: :sidekiq