Add permissions support
This commit is contained in:
parent
3db00dbf77
commit
6820f02658
|
@ -6,6 +6,8 @@ require: rubocop-performance
|
|||
AllCops:
|
||||
TargetRubyVersion: 2.5
|
||||
NewCops: enable
|
||||
Exclude:
|
||||
- 'test.rb'
|
||||
|
||||
Layout/LineLength:
|
||||
Max: 123
|
||||
|
@ -41,4 +43,4 @@ Style/OptionalBooleanParameter:
|
|||
Enabled: false
|
||||
|
||||
Lint/MissingSuper:
|
||||
Enabled: false
|
||||
Enabled: false
|
||||
|
|
7
Gemfile
7
Gemfile
|
@ -5,6 +5,13 @@ source 'https://rubygems.org'
|
|||
# Specify your gem's dependencies in sonarqube.gemspec
|
||||
gemspec
|
||||
|
||||
group :development do
|
||||
gem 'guard'
|
||||
gem 'guard-bundler', require: false
|
||||
gem 'guard-rspec', require: false
|
||||
gem 'guard-rubocop'
|
||||
end
|
||||
|
||||
gem 'pry'
|
||||
gem 'rubocop'
|
||||
gem 'rubocop-performance'
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
guard :rspec, cmd: 'rspec' do
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { 'spec' }
|
||||
end
|
||||
|
||||
guard :rubocop do
|
||||
ignore(/{^test.rb}/)
|
||||
watch(/{.+\.rb$}/)
|
||||
watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
|
||||
end
|
||||
|
||||
guard :bundler do
|
||||
require 'guard/bundler'
|
||||
require 'guard/bundler/verify'
|
||||
helper = Guard::Bundler::Verify.new
|
||||
|
||||
files = ['Gemfile']
|
||||
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
|
||||
|
||||
# Assume files are symlinked from somewhere
|
||||
files.each { |file| watch(helper.real_path(file)) }
|
||||
end
|
|
@ -0,0 +1,174 @@
|
|||
---
|
||||
layout: default
|
||||
title: Permissions
|
||||
nav_order: 5
|
||||
parent: Client
|
||||
---
|
||||
|
||||
<details close markdown="block">
|
||||
<summary>
|
||||
Table of contents
|
||||
</summary>
|
||||
{: .text-delta }
|
||||
1. TOC
|
||||
{:toc}
|
||||
</details>
|
||||
|
||||
# Permissions
|
||||
|
||||
## Add Permisssion to group
|
||||
```ruby
|
||||
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
|
||||
status = Sonarqube.permissions_add_group({groupName: 'New-Group', permission: permission, projectKey: 'test'})
|
||||
status.to_hash.nil?
|
||||
end
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
||||
|
||||
## Add group to template
|
||||
```ruby
|
||||
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
|
||||
status = Sonarqube.add_group_to_template({groupName: 'New-Group', permission: permission, templateName: 'test'})
|
||||
status.to_hash.nil?
|
||||
end
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
||||
|
||||
## Add project creator to template
|
||||
```ruby
|
||||
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
|
||||
status = Sonarqube.add_project_creator_to_template(permission, { templateName: 'test' })
|
||||
status.to_hash.nil?
|
||||
end
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
||||
|
||||
## Add permissions to user
|
||||
```ruby
|
||||
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
|
||||
status = permission_add_user('user', permission, { templateName: 'test' })
|
||||
status.to_hash.nil?
|
||||
end
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
||||
|
||||
## Add user to template
|
||||
```ruby
|
||||
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
|
||||
status = Sonarqube.add_user_to_template({ login: 'new_user', permission: 'user', templateName: 'test' })
|
||||
status.to_hash.nil?
|
||||
end
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
||||
|
||||
## Apply Template
|
||||
```ruby
|
||||
status = Sonarqube.apply_template({ projectName: 'New-Group', templateName: 'test' })
|
||||
status.to_hash.nil?
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
||||
|
||||
## Bulk apply template
|
||||
```ruby
|
||||
status = Sonarqube.bulk_apply_template({ templateName: 'test', projects: 'my_project,another_project' })
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
status.to_hash.nil?
|
||||
```
|
||||
|
||||
## Create Template
|
||||
```ruby
|
||||
status = Sonarqube.create_template('template_name', 'description', '.*\.finance\..*')
|
||||
# => #<Sonarqube::ObjectifiedHash:46120 {hash: {"permissionTemplate"=>{"id"=>"AXQt1hhmsmLGhox2KqqJ", "name"=>"template_name", "description"=>"description", "projectKeyPattern"=>".*\\.finance\\..*", "createdAt"=>"2020-08-27T02:53:59+0000", "updatedAt"=>"2020-08-27T02:53:59+0000", "permissions"=>[]}}}
|
||||
status.permissionTemplate.name
|
||||
# => template_name
|
||||
```
|
||||
|
||||
## Delete Template
|
||||
```ruby
|
||||
status = Sonarqube.delete_template({ templateName: 'template_name' })
|
||||
# => #<Sonarqube::ObjectifiedHash:46120 {hash: {"permissionTemplate"=>{"id"=>"AXQt1hhmsmLGhox2KqqJ", "name"=>"template_name", "description"=>"description", "projectKeyPattern"=>".*\\.finance\\..*", "createdAt"=>"2020-08-27T02:53:59+0000", "updatedAt"=>"2020-08-27T02:53:59+0000", "permissions"=>[]}}}
|
||||
status.to_hash.nil?
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
```
|
||||
|
||||
## Remove group from template
|
||||
```ruby
|
||||
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
|
||||
status = Sonarqube.remove_group_from_template({groupName: 'New-Group', permission: permission, templateName: 'test'})
|
||||
status.to_hash.nil?
|
||||
end
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
||||
|
||||
## Remove Permission from group
|
||||
```ruby
|
||||
['user', 'codeviewer', 'issueadmin', 'securityhotspotadmin', 'scan'].each do | permission |
|
||||
status = Sonarqube.permissions_remove_group({groupName: 'New-Group', permission: permission, projectKey: 'test'})
|
||||
status.to_hash.nil?
|
||||
end
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
# => <Sonarqube::ObjectifiedHash:46120 {hash: {}}
|
||||
# => true
|
||||
```
|
|
@ -7,6 +7,7 @@ module Sonarqube
|
|||
|
||||
# Please keep in alphabetical order
|
||||
include Groups
|
||||
include Permissions
|
||||
include Projects
|
||||
include Tokens
|
||||
include Users
|
||||
|
|
|
@ -0,0 +1,215 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Sonarqube::Client
|
||||
# Defines methods related to permissions.
|
||||
# @see https://SONAR_URL/web_api/api/permissions
|
||||
module Permissions
|
||||
# Add permission to a group.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.permissions_add_group({ groupName: 'New-Group', permission: 'user', projectKey: 'test' })
|
||||
#
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :groupId Id of group.
|
||||
# @option options [String] :groupName Name of group.
|
||||
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
||||
# @option options [String] :projectId Id of project, only apply for project permissions.
|
||||
# @option options [String] :projectKey Key of project, only apply for project permissions.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_group}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def permission_add_group(options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
|
||||
|
||||
post('/api/permissions/add_group', body: options)
|
||||
end
|
||||
alias add_group_permission permission_add_group
|
||||
|
||||
# Add group to template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.add_group_to_template({ groupName: 'New-Group', permission: 'user', templateName: 'test' })
|
||||
#
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :groupId Id of group.
|
||||
# @option options [String] :groupName Name of group.
|
||||
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
||||
# @option options [String] :templateId Id of template.
|
||||
# @option options [String] :templateName Name of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_group_to_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def add_group_to_template(options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
|
||||
|
||||
post('/api/permissions/add_group_to_template', body: options)
|
||||
end
|
||||
|
||||
# Add project creator to template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.add_project_creator_to_template('issueadmin', { templateName: 'test' })
|
||||
#
|
||||
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :templateId Id of template.
|
||||
# @option options [String] :templateName Name of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_project_creator_to_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def add_project_creator_to_template(permission, options = {})
|
||||
raise ArgumentError, 'Missing required parameters' if permission.nil?
|
||||
|
||||
post('/api/permissions/add_project_creator_to_template', body: { permission: permission }.merge!(options))
|
||||
end
|
||||
|
||||
# Add permissions to user.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.permission_add_user('new_user', 'issueadmin', { projectKey: 'test' })
|
||||
#
|
||||
# @param [String] :login Name of login user.
|
||||
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :projectId Id of project, only apply for project permissions.
|
||||
# @option options [String] :projectKey Key of project, only apply for project permissions.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_user}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def permission_add_user(login, permission, options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
raise ArgumentError, 'Missing required parameters' if login.nil? && permission.nil?
|
||||
|
||||
body = { login: login, permission: permission }.merge!(options)
|
||||
post('/api/permissions/add_user', body: body)
|
||||
end
|
||||
alias add_user_permission permission_add_user
|
||||
|
||||
# Add user to template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.add_user_to_template({ 'new_user', 'issueadmin', { templateName: 'test' })
|
||||
#
|
||||
# @param [String] :login Name of login user.
|
||||
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user.
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :templateId Id of template.
|
||||
# @option options [String] :templateName Name of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_user_to_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def add_user_to_template(login, permission, options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
raise ArgumentError, 'Missing required parameters' if login.nil? && permission.nil?
|
||||
|
||||
body = { login: login, permission: permission }.merge!(options)
|
||||
post('/api/permissions/add_user_to_template', body: body)
|
||||
end
|
||||
|
||||
# Apply template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.apply_template({ projectName: 'New-Group', templateName: 'test' })
|
||||
#
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :projectId Id of group.
|
||||
# @option options [String] :projectName Name of group.
|
||||
# @option options [String] :templateId Id of template.
|
||||
# @option options [String] :templateName Name of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/apply_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def apply_template(options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
|
||||
post('/api/permissions/apply_template', body: options)
|
||||
end
|
||||
|
||||
# Bulk apply template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.bulk_apply_template({ templateName: 'test', projects: 'my_project,another_project' })
|
||||
#
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :analyzedBefore Filter the projects for which last analysis is older than the given date .
|
||||
# @option options [String] :onProvisionedOnly Filter the projects that are provisioned.
|
||||
# @option options [String] :projects Comma-separated list of project keys maximum 1000
|
||||
# @option options [String] :q serach project names that contain the supplied string and project keys that are exactly the same as the supplied string
|
||||
# @option options [String] :qualifiers Comma-separated list of component qualifiers. Filter the results with the specified qualifiers.
|
||||
# @option options [String] :templateId Id of template.
|
||||
# @option options [String] :templateName Name of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/bulk_apply_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def bulk_apply_template(options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
|
||||
post('/api/permissions/bulk_apply_template', body: options)
|
||||
end
|
||||
|
||||
# Create template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.create_template('template_name', 'description', '.*\.finance\..*')
|
||||
#
|
||||
# @param [String] :name Name of template.
|
||||
# @param [String] :project_key_pattern Project key pattern. Must be a valid Java regular expression.
|
||||
# @param [String] :description Description of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/create_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def create_template(name, description, project_key_pattern)
|
||||
body = { name: name, description: description, projectKeyPattern: project_key_pattern }
|
||||
post('/api/permissions/create_template', body: body)
|
||||
end
|
||||
|
||||
# Delete template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.create_template({ templateName: 'template_name' })
|
||||
#
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :templateId Id of template.
|
||||
# @option options [String] :templateName Name of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/delete_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def delete_template(options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
raise ArgumentError, 'Missing required parameters' if options[:templateName].nil? && options[:templateId].nil?
|
||||
|
||||
post('/api/permissions/delete_template', body: options)
|
||||
end
|
||||
|
||||
# Remove permission to a group.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.permissions_add_group({ groupName: 'New-Group', permission: permission, projectKey: 'test' })
|
||||
#
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :groupId Id of group.
|
||||
# @option options [String] :groupName Name of group.
|
||||
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
||||
# @option options [String] :projectId Id of project, only apply for project permissions.
|
||||
# @option options [String] :projectKey Key of project, only apply for project permissions.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/remove_group}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def permission_remove_group(options = {})
|
||||
options.transform_keys(&:to_sym)
|
||||
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
|
||||
|
||||
post('/api/permissions/remove_group', body: options)
|
||||
end
|
||||
alias remove_group_permission permission_remove_group
|
||||
|
||||
# Remove group from template.
|
||||
#
|
||||
# @example
|
||||
# Sonarqube.remove_group_from_template({ groupName: 'New-Group', permission: 'permission', templateId: 'test' })
|
||||
#
|
||||
# @param [Hash] options A customizable set of options.
|
||||
# @option options [String] :groupId Id of group.
|
||||
# @option options [String] :groupName Name of group.
|
||||
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
||||
# @option options [String] :TemplateId Id of template.
|
||||
# @option options [String] :TemplateName Name of template.
|
||||
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/remove_group_from_template}
|
||||
# @return [<Sonarqube::ObjectifiedHash>]
|
||||
def remove_group_from_template(options = {})
|
||||
post('/api/permissions/remove_group_from_template', body: options)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{"permissionTemplate": {"name": "template_name","description": "description","projectKeyPattern": ".*\\.finance\\..*"}}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1,203 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Sonarqube::Client do
|
||||
describe '.permission_add_group' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/add_group', 'permission_add_group')
|
||||
@permission = Sonarqube.permission_add_group({ groupName: 'New-Group', permission: 'user', projectKey: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { groupName: 'New-Group', permission: 'user', projectKey: 'test' }
|
||||
expect(a_post('/api/permissions/add_group').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.add_group_to_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/add_group_to_template', 'template_add_group')
|
||||
@permission = Sonarqube.add_group_to_template({ groupName: 'New-Group', permission: 'user', templateName: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { groupName: 'New-Group', permission: 'user', templateName: 'test' }
|
||||
expect(a_post('/api/permissions/add_group_to_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.add_project_creator_to_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/add_project_creator_to_template', 'template_add_project_creator')
|
||||
@permission = Sonarqube.add_project_creator_to_template('user', { templateName: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { permission: 'user', templateName: 'test' }
|
||||
expect(a_post('/api/permissions/add_project_creator_to_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.permission_add_user' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/add_user', 'permission_add_user')
|
||||
@permission = Sonarqube.permission_add_user('user', 'user', { templateName: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { login: 'user', permission: 'user', templateName: 'test' }
|
||||
expect(a_post('/api/permissions/add_user').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.add_user_to_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/add_user_to_template', 'template_add_user')
|
||||
@permission = Sonarqube.add_user_to_template('new_user', 'user', { templateName: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { login: 'new_user', permission: 'user', templateName: 'test' }
|
||||
expect(a_post('/api/permissions/add_user_to_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.apply_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/apply_template', 'apply_template')
|
||||
@permission = Sonarqube.apply_template({ projectName: 'test', templateName: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { projectName: 'test', templateName: 'test' }
|
||||
expect(a_post('/api/permissions/apply_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.bulk_apply_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/bulk_apply_template', 'bulk_apply_template')
|
||||
@permission = Sonarqube.bulk_apply_template({ projectName: 'test', templateName: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { projectName: 'test', templateName: 'test' }
|
||||
expect(a_post('/api/permissions/bulk_apply_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.create_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/create_template', 'create_template')
|
||||
@permission = Sonarqube.create_template('template_name', 'description', '.*\.finance\..*')
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { name: 'template_name', description: 'description', projectKeyPattern: '.*\.finance\..*' }
|
||||
expect(a_post('/api/permissions/create_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.permissionTemplate.name).to eq('template_name')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.delete_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/delete_template', 'delete_template')
|
||||
@permission = Sonarqube.delete_template({ templateName: 'template_name' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { templateName: 'template_name' }
|
||||
expect(a_post('/api/permissions/delete_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.permission_remove_group' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/remove_group', 'permission_remove_group')
|
||||
@permission = Sonarqube.permission_remove_group({ groupName: 'New-Group', permission: 'user', projectKey: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { groupName: 'New-Group', permission: 'user', projectKey: 'test' }
|
||||
expect(a_post('/api/permissions/remove_group').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.remove_group_from_template' do
|
||||
context 'when successful request' do
|
||||
before do
|
||||
stub_post('/api/permissions/remove_group_from_template', 'remove_group_from_template')
|
||||
@permission = Sonarqube.remove_group_from_template({ groupName: 'New-Group', permission: 'permission', templateName: 'test' })
|
||||
end
|
||||
|
||||
it 'gets the correct resource' do
|
||||
body = { groupName: 'New-Group', permission: 'permission', templateName: 'test' }
|
||||
expect(a_post('/api/permissions/remove_group_from_template').with(body: body)).to have_been_made
|
||||
end
|
||||
|
||||
it 'returns returns empty hash' do
|
||||
expect(@permission.to_hash).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,7 +30,7 @@ describe Sonarqube do
|
|||
actions = described_class.actions
|
||||
expect(actions).to be_an Array
|
||||
expect(actions.first).to be_a Symbol
|
||||
expect(actions.min).to eq(:add_member)
|
||||
expect(actions.min).to eq(:add_group_permission)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue