diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..88d2b1e --- /dev/null +++ b/.gitlab-ci.yml @@ -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] diff --git a/.travis.yml b/.travis.yml index a1e996f..08c06dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/puppet/provider/git_deploy_key/gitlab.rb b/lib/puppet/provider/git_deploy_key/gitlab.rb index 059974d..02a1a16 100644 --- a/lib/puppet/provider/git_deploy_key/gitlab.rb +++ b/lib/puppet/provider/git_deploy_key/gitlab.rb @@ -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 @@ -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) @@ -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) @@ -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) @@ -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)}) @@ -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) @@ -177,5 +191,3 @@ def destroy end end - - diff --git a/lib/puppet/provider/git_groupteam/gitlab.rb b/lib/puppet/provider/git_groupteam/gitlab.rb index c8f704e..11d1b09 100644 --- a/lib/puppet/provider/git_groupteam/gitlab.rb +++ b/lib/puppet/provider/git_groupteam/gitlab.rb @@ -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 @@ -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) @@ -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) @@ -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 } @@ -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) @@ -162,5 +166,3 @@ def destroy end end - - diff --git a/lib/puppet/provider/git_groupteam_member/gitlab.rb b/lib/puppet/provider/git_groupteam_member/gitlab.rb index b0afdbc..9d494b5 100644 --- a/lib/puppet/provider/git_groupteam_member/gitlab.rb +++ b/lib/puppet/provider/git_groupteam_member/gitlab.rb @@ -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 @@ -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) @@ -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) @@ -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) @@ -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? @@ -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) @@ -224,5 +228,3 @@ def destroy end end - - diff --git a/lib/puppet/provider/git_webhook/gitlab.rb b/lib/puppet/provider/git_webhook/gitlab.rb index 5679425..7c1a871 100644 --- a/lib/puppet/provider/git_webhook/gitlab.rb +++ b/lib/puppet/provider/git_webhook/gitlab.rb @@ -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 @@ -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) @@ -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) @@ -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) @@ -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 } @@ -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) @@ -199,5 +203,3 @@ def destroy end end - - diff --git a/lib/puppet/provider/gms_webhook/gitlab.rb b/lib/puppet/provider/gms_webhook/gitlab.rb index 51c2e9f..f06f1ec 100644 --- a/lib/puppet/provider/gms_webhook/gitlab.rb +++ b/lib/puppet/provider/gms_webhook/gitlab.rb @@ -28,7 +28,7 @@ def self.instances instances = [] - repos_url = "#{gms_server}/api/v3/projects" + repos_url = "#{gms_server}/api/#{api_version}/projects" repos = get(repos_url, @token) webhooks = Array.new @@ -37,7 +37,7 @@ def self.instances repos.each do |r| # hooks_url = "#{gms_server}/projects/#{r['id']}/hooks" - hooks_url = "#{gms_server}/api/v3/projects/#{r['id']}/hooks" + hooks_url = "#{gms_server}/api/#{api_version}/projects/#{r['id']}/hooks" hook_objs = get(hooks_url, @token) @@ -126,6 +126,10 @@ def gms_server PuppetX::Puppetlabs::Gms::gms_server 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 @@ -137,7 +141,7 @@ def calling_method def get_project_id(project_name) begin - repos_url = "#{self.gms_server}/api/v3/projects" + repos_url = "#{self.gms_server}/api/#{api_version}/projects" repos = PuppetX::Puppetlabs::Gms.get(repos_url, get_token) repos.each do |r| @@ -158,7 +162,7 @@ def exists? def flush Puppet.debug("def flush") - put_url = "#{gms_server}/api/v3/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}" + put_url = "#{gms_server}/api/#{api_version}/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}" if @property_hash != {} begin @@ -179,7 +183,7 @@ def create Puppet.debug('def create') begin - post_url = "#{self.gms_server}/api/v3/projects/#{get_project_id(resource[:project_name].strip)}/hooks" + post_url = "#{self.gms_server}/api/#{api_version}/projects/#{get_project_id(resource[:project_name].strip)}/hooks" response = PuppetX::Puppetlabs::Gms.post(post_url, get_token, message(resource)) @@ -202,7 +206,7 @@ def destroy Puppet.debug("def destroy") unless webhook_id.nil? - destroy_url = "#{gms_server}/api/v3/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}" + destroy_url = "#{gms_server}/api/#{api_version}/projects/#{get_project_id(resource[:project_name].strip)}/hooks/#{self.id}" begin response = PuppetX::Puppetlabs::Gms.delete(destroy_url, get_token) diff --git a/lib/puppet/type/git_deploy_key.rb b/lib/puppet/type/git_deploy_key.rb index 50f9142..1e6956e 100644 --- a/lib/puppet/type/git_deploy_key.rb +++ b/lib/puppet/type/git_deploy_key.rb @@ -61,6 +61,12 @@ module Puppet end end + newparam(:gitlab_api_version) do + desc 'The api version to use with gitlab.' + defaultto :v4 + newvalues(:v3, :v4) + end + autorequire(:file) do self[:path]if self[:path] and Pathname.new(self[:path]).absolute? end @@ -71,4 +77,3 @@ module Puppet end end - diff --git a/lib/puppet/type/git_groupteam.rb b/lib/puppet/type/git_groupteam.rb index a15a105..e3d7e1a 100644 --- a/lib/puppet/type/git_groupteam.rb +++ b/lib/puppet/type/git_groupteam.rb @@ -99,10 +99,15 @@ module Puppet end end + newparam(:gitlab_api_version) do + desc 'The api version to use with gitlab.' + defaultto :v4 + newvalues(:v3, :v4) + end + validate do validate_token_or_token_file end end end - diff --git a/lib/puppet/type/git_groupteam_member.rb b/lib/puppet/type/git_groupteam_member.rb index c32f09e..4341065 100644 --- a/lib/puppet/type/git_groupteam_member.rb +++ b/lib/puppet/type/git_groupteam_member.rb @@ -106,10 +106,15 @@ module Puppet end end + newparam(:gitlab_api_version) do + desc 'The api version to use with gitlab.' + defaultto :v4 + newvalues(:v3, :v4) + end + validate do validate_token_or_token_file end end end - diff --git a/lib/puppet/type/git_webhook.rb b/lib/puppet/type/git_webhook.rb index 0fcb981..05c1c19 100644 --- a/lib/puppet/type/git_webhook.rb +++ b/lib/puppet/type/git_webhook.rb @@ -100,10 +100,15 @@ module Puppet end end + newparam(:gitlab_api_version) do + desc 'The api version to use with gitlab.' + defaultto :v4 + newvalues(:v3, :v4) + end + validate do validate_token_or_token_file end end end - diff --git a/lib/puppet/type/gms_webhook.rb b/lib/puppet/type/gms_webhook.rb index 77aa90c..da51972 100644 --- a/lib/puppet/type/gms_webhook.rb +++ b/lib/puppet/type/gms_webhook.rb @@ -178,6 +178,12 @@ def insync?(is) end end + newparam(:gitlab_api_version) do + desc 'The api version to use with gitlab.' + defaultto :v4 + newvalues(:v3, :v4) + end + read_only_properties = { id: 'id', last_response_code: 'last_response_code', diff --git a/metadata.json b/metadata.json index 80d97ea..9923562 100644 --- a/metadata.json +++ b/metadata.json @@ -80,19 +80,15 @@ } ], "requirements": [ - { - "name": "pe", - "version_requirement": ">= 3.1.3 < 2015.4.0" - }, { "name": "puppet", - "version_requirement": ">= 3.4.3 < 5.0.0" + "version_requirement": ">= 3.4.3 < 7.0.0" } ], "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">=3.2.0 <5.0.0" + "version_requirement": ">=3.2.0 <7.0.0" } ] }