Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated version of gms module (includes #40 and #47) #50

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
cache:
paths:
- vendor/ruby
- spec/fixtures

variables:

.puppet400: &puppet400
PUPPET_LOCATION: 4.0.0
BUNDLER: '1.7.3'

.puppet41012: &puppet41012
PUPPET_LOCATION: 4.10.12
BUNDLER: '1.7.3'

.puppet550: &puppet550
PUPPET_LOCATION: 5.5.0
BUNDLER: '>= 0'

.syntax: &syntax
script:
- bundle exec rake syntax

.validate: &validate
script:
- bundle exec rake validate

.lint: &lint
script:
- bundle exec rake lint

.spec: &spec
script:
- bundle exec rake spec SPEC_OPTS='--format documentation'
coverage: '/Resource coverage: \d+\.\d+/'

before_script:
- gem install bundler --no-document --version "$BUNDLER"
- bundle install -j $(nproc) --path vendor --without development acceptance

puppet41012_test:
stage: test
image: "ruby:2.1.9"
<<: [*syntax, *validate, *lint, *spec]
variables:
<<: [*puppet41012]

puppet550_test:
image: "ruby:2.4.5"
stage: test
<<: [*syntax, *validate, *lint, *spec]
variables:
<<: [*puppet550]

puppet400_test:
stage: test
image: "ruby:2.1.9"
<<: [*syntax, *validate, *lint, *spec]
variables:
<<: [*puppet400]
20 changes: 12 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ script:
- "bundle exec rake syntax"
- "bundle exec rake spec SPEC_OPTS='--format documentation'"
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2
- 2.4.5
env:
- PUPPET_VERSION="~> 3.2.0"
- PUPPET_VERSION="~> 3.3.0"
- PUPPET_VERSION="~> 3.4.0"
- PUPPET_VERSION="~> 3.5.1"
- PUPPET_VERSION="~> 3.6.0"
- PUPPET_VERSION="~> 3.7.0"
- PUPPET_VERSION="~> 4.0.0"
- PUPPET_LOCATION="~> 3.4.0"
- PUPPET_LOCATION="~> 3.5.1"
- PUPPET_LOCATION="~> 3.6.0"
- PUPPET_LOCATION="~> 3.7.0"
- PUPPET_LOCATION="~> 4.0.0"
matrix:
include:
- rvm: 2.0.0
env: PUPPET_LOCATION="~> 3.3.0"
- rvm: 2.4.5
env: PUPPET_LOCATION="~> 5.5.0"

global:
- PUBLISHER_LOGIN=abrader
Expand Down
28 changes: 20 additions & 8 deletions lib/puppet/provider/git_deploy_key/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ def gms_server
return 'https://gitlab.com'
end

def api_version
return resource[:gitlab_api_version]
end

def keys_endpoint
if api_version.to_s.eql? "v3"
return 'keys'
else
return 'deploy_keys'
end
end

def calling_method
# Get calling method and clean it up for good reporting
cm = String.new
Expand Down Expand Up @@ -69,7 +81,8 @@ def exists?
project_id = get_project_id

sshkey_hash = Hash.new
url = "#{gms_server}/api/v3/projects/#{project_id}/keys"

url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/#{keys_endpoint}"

response = api_call('GET', url)

Expand All @@ -96,9 +109,9 @@ def get_project_id
raise(Puppet::Error, "gitlab_deploy_key::#{calling_method}: Must provide at least one of the following attributes: project_id or project_name")
end

project_name = resource[:project_name].strip.sub('/','%2F')
project_name = resource[:project_name].strip.gsub('/','%2F')

url = "#{gms_server}/api/v3/projects/#{project_name}"
url = "#{gms_server}/api/#{api_version}/projects/#{project_name}"

begin
response = api_call('GET', url)
Expand All @@ -115,7 +128,7 @@ def get_key_id

keys_hash = Hash.new

url = "#{gms_server}/api/v3/projects/#{project_id}/keys"
url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/#{keys_endpoint}"

response = api_call('GET', url)

Expand All @@ -138,7 +151,7 @@ def get_key_id
def create
project_id = get_project_id

url = "#{gms_server}/api/v3/projects/#{project_id}/keys"
url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/#{keys_endpoint}"

begin
response = api_call('POST', url, {'title' => resource[:name].strip, 'key' => File.read(resource[:path].strip)})
Expand All @@ -159,7 +172,8 @@ def destroy
key_id = get_key_id

unless key_id.nil?
url = "#{gms_server}/api/v3/projects/#{project_id}/keys/#{key_id}"

url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/#{keys_endpoint}/#{key_id}"

begin
response = api_call('DELETE', url)
Expand All @@ -177,5 +191,3 @@ def destroy
end

end


14 changes: 8 additions & 6 deletions lib/puppet/provider/git_groupteam/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def gms_server
return 'https://gitlab.com'
end

def api_version
return resource[:gitlab_api_version]
end

def calling_method
# Get calling method and clean it up for good reporting
cm = String.new
Expand Down Expand Up @@ -67,7 +71,7 @@ def api_call(action,url,data = nil)

def exists?
groupteam_hash = Hash.new
url = "#{gms_server}/api/v3/groups"
url = "#{gms_server}/api/#{api_version}/groups"

response = api_call('GET', url)

Expand Down Expand Up @@ -96,7 +100,7 @@ def exists?
def get_group_id
group_hash = Hash.new

url = "#{gms_server}/api/v3/groups"
url = "#{gms_server}/api/#{api_version}/groups"

response = api_call('GET', url)

Expand All @@ -117,7 +121,7 @@ def get_group_id
end

def create
url = "#{gms_server}/api/v3/groups"
url = "#{gms_server}/api/#{api_version}/groups"

begin
opts = { 'name' => resource[:groupteam_name].strip, 'path' => resource[:groupteam_name].strip }
Expand All @@ -144,7 +148,7 @@ def destroy
group_id = get_group_id

unless group_id.nil?
url = "#{gms_server}/api/v3/groups/#{group_id}"
url = "#{gms_server}/api/#{api_version}/groups/#{group_id}"

begin
response = api_call('DELETE', url)
Expand All @@ -162,5 +166,3 @@ def destroy
end

end


16 changes: 9 additions & 7 deletions lib/puppet/provider/git_groupteam_member/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def gms_server
return 'https://gitlab.com'
end

def api_version
return resource[:gitlab_api_version]
end

def calling_method
# Get calling method and clean it up for good reporting
cm = String.new
Expand Down Expand Up @@ -76,7 +80,7 @@ def exists?
group_id = get_group_id

groupteam_hash = Hash.new
url = "#{gms_server}/api/v3//groups/#{group_id}/members"
url = "#{gms_server}/api/#{api_version}/groups/#{group_id}/members"

response = api_call('GET', url)

Expand Down Expand Up @@ -130,7 +134,7 @@ def get_access_level
def get_group_id
group_hash = Hash.new

url = "#{gms_server}/api/v3/groups?search=#{resource[:groupteam_name].strip}"
url = "#{gms_server}/api/#{api_version}/groups?search=#{resource[:groupteam_name].strip}"

response = api_call('GET', url)

Expand All @@ -153,7 +157,7 @@ def get_group_id
def get_user_id
group_hash = Hash.new

url = "#{gms_server}/api/v3/users?search=#{resource[:member_name].strip}"
url = "#{gms_server}/api/#{api_version}/users?search=#{resource[:member_name].strip}"

response = api_call('GET', url)

Expand All @@ -178,7 +182,7 @@ def create
group_id = get_group_id
user_id = get_user_id

url = "#{gms_server}/api/v3//groups/#{group_id}/members"
url = "#{gms_server}/api/#{api_version}/groups/#{group_id}/members"

begin
if access_level.nil? || group_id.nil? || user_id.nil?
Expand Down Expand Up @@ -206,7 +210,7 @@ def destroy
user_id = get_user_id

unless group_id.nil?
url = "#{gms_server}/api/v3//groups/#{group_id}/members/#{user_id}"
url = "#{gms_server}/api/#{api_version}//groups/#{group_id}/members/#{user_id}"

begin
response = api_call('DELETE', url)
Expand All @@ -224,5 +228,3 @@ def destroy
end

end


18 changes: 10 additions & 8 deletions lib/puppet/provider/git_webhook/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def gms_server
return 'https://gitlab.com'
end

def api_version
return resource[:gitlab_api_version]
end

def calling_method
# Get calling method and clean it up for good reporting
cm = String.new
Expand Down Expand Up @@ -69,7 +73,7 @@ def exists?
project_id = get_project_id

webhook_hash = Hash.new
url = "#{gms_server}/api/v3/projects/#{project_id}/hooks"
url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/hooks"

response = api_call('GET', url)

Expand Down Expand Up @@ -97,9 +101,9 @@ def get_project_id
raise(Puppet::Error, "gitlab_webhook::#{calling_method}: Must provide at least one of the following attributes: project_id or project_name")
end

project_name = resource[:project_name].strip.sub('/','%2F')
project_name = resource[:project_name].strip.gsub('/','%2F')

url = "#{gms_server}/api/v3/projects/#{project_name}"
url = "#{gms_server}/api/#{api_version}/projects/#{project_name}"

begin
response = api_call('GET', url)
Expand All @@ -116,7 +120,7 @@ def get_webhook_id

webhook_hash = Hash.new

url = "#{gms_server}/api/v3/projects/#{project_id}/hooks"
url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/hooks"

response = api_call('GET', url)

Expand All @@ -138,7 +142,7 @@ def get_webhook_id
def create
project_id = get_project_id

url = "#{gms_server}/api/v3/projects/#{project_id}/hooks"
url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/hooks"

begin
opts = { 'url' => resource[:webhook_url].strip }
Expand Down Expand Up @@ -181,7 +185,7 @@ def destroy
webhook_id = get_webhook_id

unless webhook_id.nil?
url = "#{gms_server}/api/v3/projects/#{project_id}/hooks/#{webhook_id}"
url = "#{gms_server}/api/#{api_version}/projects/#{project_id}/hooks/#{webhook_id}"

begin
response = api_call('DELETE', url)
Expand All @@ -199,5 +203,3 @@ def destroy
end

end


Loading