BigW Consortium Gitlab

internal.rb 1.89 KB
Newer Older
1
module API
2
  # Internal access API
Dmitriy Zaporozhets committed
3
  class Internal < Grape::API
4
    before { authenticate_by_gitlab_shell_token! }
5

6
    namespace 'internal' do
7
      # Check if git command is allowed to project
8
      #
9
      # Params:
10 11
      #   key_id - ssh key id for Git over SSH
      #   user_id - user id for Git over HTTP
12 13 14
      #   project - project path with namespace
      #   action - git action (git-upload-pack or git-receive-pack)
      #   ref - branch name
15
      #   forced_push - forced_push
16
      #
17
      post "/allowed" do
18
        status 200
19

20 21 22 23 24 25
        actor = 
          if params[:key_id]
            Key.find_by(id: params[:key_id])
          elsif params[:user_id]
            User.find_by(id: params[:user_id])
          end
26

27
        project_path = params[:project]
28
        
29 30 31 32
        # Check for *.wiki repositories.
        # Strip out the .wiki from the pathname before finding the
        # project. This applies the correct project permissions to
        # the wiki repository as well.
33 34
        wiki = project_path.end_with?('.wiki')
        project_path.chomp!('.wiki') if wiki
35

36
        project = Project.find_with_namespace(project_path)
37

38 39 40 41 42 43
        access =
          if wiki
            Gitlab::GitAccessWiki.new(actor, project)
          else
            Gitlab::GitAccess.new(actor, project)
          end
44

45
        access.check(params[:action], params[:changes])
46 47 48 49 50 51 52
      end

      #
      # Discover user by ssh key
      #
      get "/discover" do
        key = Key.find(params[:key_id])
53
        present key.user, with: Entities::UserSafe
54
      end
Dmitriy Zaporozhets committed
55 56 57

      get "/check" do
        {
58
          api_version: API.version,
59 60
          gitlab_version: Gitlab::VERSION,
          gitlab_rev: Gitlab::REVISION,
Dmitriy Zaporozhets committed
61 62
        }
      end
63 64 65 66

      get "/broadcast_message" do
        if message = BroadcastMessage.current
          present message, with: Entities::BroadcastMessage
67 68
        else
          {}
69 70
        end
      end
Dmitriy Zaporozhets committed
71 72 73
    end
  end
end