Skip to content
Snippets Groups Projects
Select Git revision
  • move-gl-dropdown
  • improve-table-pagination-spec
  • move-markdown-preview
  • winh-fix-merge-request-spec
  • master default
  • index-namespaces-lower-name
  • winh-single-karma-test
  • 10-3-stable
  • 36782-replace-team-user-role-with-add_role-user-in-specs
  • winh-modal-internal-state
  • tz-ide-file-icons
  • 38869-milestone-select
  • update-autodevops-template
  • jivl-activate-repo-cookie-preferences
  • qa-add-deploy-key
  • docs-move-article-ldap
  • 40780-choose-file
  • 22643-manual-job-page
  • refactor-cluster-show-page-conservative
  • dm-sidekiq-versioning
  • v10.4.0.pre
  • v10.3.0
  • v10.3.0-rc5
  • v10.3.0-rc4
  • v10.3.0-rc3
  • v10.3.0-rc2
  • v10.2.5
  • v10.3.0-rc1
  • v10.0.7
  • v10.1.5
  • v10.2.4
  • v10.2.3
  • v10.2.2
  • v10.2.1
  • v10.3.0.pre
  • v10.2.0
  • v10.2.0-rc4
  • v10.2.0-rc3
  • v10.1.4
  • v10.2.0-rc2
40 results

variables.rb

Blame
  • Forked from GitLab.org / GitLab FOSS
    20498 commits behind the upstream repository.
    • Kamil Trzcinski's avatar
      055afab5
      Make the CI permission model simpler · 055afab5
      Kamil Trzcinski authored
      This MR simplifies CI permission model:
      - read_build: allows to read a list of builds, artifacts and trace
      - update_build: allows to cancel and retry builds
      - create_build: allows to create builds from gitlab-ci.yml (not yet implemented)
      - admin_build: allows to manage triggers, runners and variables
      - read_commit_status: allows to read a list of commit statuses (including the overall of builds)
      - create_commit_status: allows to create a new commit status using API
      
      Remove all extra methods to manage permission.
      Made all controllers to use explicitly the new permissions.
      055afab5
      History
      Make the CI permission model simpler
      Kamil Trzcinski authored
      This MR simplifies CI permission model:
      - read_build: allows to read a list of builds, artifacts and trace
      - update_build: allows to cancel and retry builds
      - create_build: allows to create builds from gitlab-ci.yml (not yet implemented)
      - admin_build: allows to manage triggers, runners and variables
      - read_commit_status: allows to read a list of commit statuses (including the overall of builds)
      - create_commit_status: allows to create a new commit status using API
      
      Remove all extra methods to manage permission.
      Made all controllers to use explicitly the new permissions.
    variables.rb 2.83 KiB
    module API
      # Projects variables API
      class Variables < Grape::API
        before { authenticate! }
        before { authorize! :admin_build, user_project }
    
        resource :projects do
          # Get project variables
          #
          # Parameters:
          #   id (required) - The ID of a project
          #   page (optional) - The page number for pagination
          #   per_page (optional) - The value of items per page to show
          # Example Request:
          #   GET /projects/:id/variables
          get ':id/variables' do
            variables = user_project.variables
            present paginate(variables), with: Entities::Variable
          end
    
          # Get specific variable of a project
          #
          # Parameters:
          #   id (required) - The ID of a project
          #   key (required) - The `key` of variable
          # Example Request:
          #   GET /projects/:id/variables/:key
          get ':id/variables/:key' do
            key = params[:key]
            variable = user_project.variables.find_by(key: key.to_s)
    
            return not_found!('Variable') unless variable
    
            present variable, with: Entities::Variable
          end
    
          # Create a new variable in project
          #
          # Parameters:
          #   id (required) - The ID of a project
          #   key (required) - The key of variable
          #   value (required) - The value of variable
          # Example Request:
          #   POST /projects/:id/variables
          post ':id/variables' do
            required_attributes! [:key, :value]
    
            variable = user_project.variables.create(key: params[:key], value: params[:value])
    
            if variable.valid?
              present variable, with: Entities::Variable
            else
              render_validation_error!(variable)
            end
          end
    
          # Update existing variable of a project
          #
          # Parameters:
          #   id (required) - The ID of a project
          #   key (optional) - The `key` of variable
          #   value (optional) - New value for `value` field of variable
          # Example Request:
          #   PUT /projects/:id/variables/:key
          put ':id/variables/:key' do
            variable = user_project.variables.find_by(key: params[:key].to_s)
    
            return not_found!('Variable') unless variable
    
            attrs = attributes_for_keys [:value]
            if variable.update(attrs)
              present variable, with: Entities::Variable
            else
              render_validation_error!(variable)
            end
          end
    
          # Delete existing variable of a project
          #
          # Parameters:
          #   id (required) - The ID of a project
          #   key (required) - The ID of a variable
          # Example Request:
          #   DELETE /projects/:id/variables/:key
          delete ':id/variables/:key' do
            variable = user_project.variables.find_by(key: params[:key].to_s)
    
            return not_found!('Variable') unless variable
            variable.destroy
    
            present variable, with: Entities::Variable
          end
        end
      end
    end