From 65125178576c2bde8803d5fc4ab29d1cbdfaee83 Mon Sep 17 00:00:00 2001 From: Kyle Allan Date: Tue, 30 Jul 2013 13:39:17 -0700 Subject: [PATCH 1/4] add a new config entry for a default staging repo --- lib/nexus_cli/configuration.rb | 3 +++ spec/unit/nexus_cli/configuration_spec.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/nexus_cli/configuration.rb b/lib/nexus_cli/configuration.rb index c04ede7..675b430 100644 --- a/lib/nexus_cli/configuration.rb +++ b/lib/nexus_cli/configuration.rb @@ -62,6 +62,9 @@ def validate!(config) m = m.is_a?(String) ? m.gsub(' ', '_').downcase : m } + attribute :default_profile_id, + type: String + attribute :username, type: String, required: true diff --git a/spec/unit/nexus_cli/configuration_spec.rb b/spec/unit/nexus_cli/configuration_spec.rb index 34075e4..e82d559 100755 --- a/spec/unit/nexus_cli/configuration_spec.rb +++ b/spec/unit/nexus_cli/configuration_spec.rb @@ -73,7 +73,7 @@ described_class.new(url: nil, repository: "something", username: "someone", password: "somepass") end - context "when the object is invalide" do + context "when the object is invalid" do it "raises an error" do expect { validate! }.to raise_error(NexusCli::InvalidSettingsException) end From 44e225b5d1e97f32329bf2a0db0a96d4494660cf Mon Sep 17 00:00:00 2001 From: Kyle Allan Date: Tue, 30 Jul 2013 13:40:32 -0700 Subject: [PATCH 2/4] add support for a staging repositories lifecycle --- features/pro/nexus_staging.feature | 11 ++++ lib/nexus_cli.rb | 1 + lib/nexus_cli/mixins/pro/staging_actions.rb | 68 +++++++++++++++++++++ lib/nexus_cli/remote/pro_remote.rb | 1 + lib/nexus_cli/tasks.rb | 12 ++++ 5 files changed, 93 insertions(+) create mode 100644 features/pro/nexus_staging.feature create mode 100644 lib/nexus_cli/mixins/pro/staging_actions.rb diff --git a/features/pro/nexus_staging.feature b/features/pro/nexus_staging.feature new file mode 100644 index 0000000..e86ab44 --- /dev/null +++ b/features/pro/nexus_staging.feature @@ -0,0 +1,11 @@ +Feature: Use the Nexus CLI to execute commands that interact with the Nexus Pro Staging Suite + As a Pro CLI user + I need commands to start, close, and release Nexus Staging Repositories + + Scenario: Start a Staging Repository + When I call the nexus "start_staging" command + Then the output should contain: + """ + rcs-005 + """ + And the exit status should be 0 \ No newline at end of file diff --git a/lib/nexus_cli.rb b/lib/nexus_cli.rb index fa9c374..f7149f2 100755 --- a/lib/nexus_cli.rb +++ b/lib/nexus_cli.rb @@ -31,6 +31,7 @@ module NexusCli autoload :LoggingActions, 'nexus_cli/mixins/logging_actions' autoload :CustomMetadataActions, 'nexus_cli/mixins/pro/custom_metadata_actions' autoload :SmartProxyActions, 'nexus_cli/mixins/pro/smart_proxy_actions' + autoload :StagingActions, 'nexus_cli/mixins/pro/staging_actions' class << self def root diff --git a/lib/nexus_cli/mixins/pro/staging_actions.rb b/lib/nexus_cli/mixins/pro/staging_actions.rb new file mode 100644 index 0000000..2e9d1f8 --- /dev/null +++ b/lib/nexus_cli/mixins/pro/staging_actions.rb @@ -0,0 +1,68 @@ +module NexusCli + module StagingActions + + # Starts a new staging repository with the ruleset defined + # by the given staging_profile_id + # + # @param staging_profile_id [String] + # + # @return [String] the repository id of the new staging repository + def start(staging_profile_id = configuration['default_profile_id'], description = "Starting Repository") + response = nexus.post(nexus_url("service/local/staging/profiles/#{staging_profile_id}/start"), :body => create_promote_request(description), :header => DEFAULT_CONTENT_TYPE_HEADER) + case response.status + when 201 + JSON.parse(response.body)["data"]["stagedRepositoryId"] + else + raise UnexpectedStatusCodeException.new(response.status) + end + end + + # Closes the given staging repository + # + # @param repository_id [String] + # @param description = "Closing Repository" [String] + # + # @return [Boolean] + def close(repository_id, description = "Closing Repository") + response = nexus.post(nexus_url("service/local/staging/bulk/close"), :body => staging_lifecycle_payload(repository_id, description), :header => DEFAULT_CONTENT_TYPE_HEADER) + case response.status + when 201 + true + else + raise UnexpectedStatusCodeException.new(response.status) + end + end + + # Releases the given staging repository + # + # + # @return [Bolean] + def release + response = nexus.post(nexus_url("service/local/staging/bulk/promote"), :body => staging_lifecycle_payload(repository_id, description), :header => DEFAULT_CONTENT_TYPE_HEADER) + case response.status + when 201 + true + else + raise UnexpectedStatusCodeException.new(response.status) + end + end + + def profiles + response = nexus.get(nexus_url("service/local/staging/profiles")) + response.body + end + + private + + def create_promote_request(description) + json_payload = { "data" => { "description" => description } } + JSON.dump(json_payload) + end + + def staging_lifecycle_payload(repository_id, promotion_id = nil, description) + json_payload = { "data" => { "stagedRepositoryIds" => Array(repository_id), "description" => description}} + json_payload["stagingProfileGroup"] = promotion_id unless promotion_id.nil? + JSON.dump(json_payload) + end + end +end diff --git a/lib/nexus_cli/remote/pro_remote.rb b/lib/nexus_cli/remote/pro_remote.rb index 07787ba..fe1076b 100644 --- a/lib/nexus_cli/remote/pro_remote.rb +++ b/lib/nexus_cli/remote/pro_remote.rb @@ -8,6 +8,7 @@ class ProRemote < BaseRemote include RepositoryActions include SmartProxyActions include UserActions + include StagingActions def get_license_info response = nexus.get(nexus_url("service/local/licensing"), :header => DEFAULT_ACCEPT_HEADER) diff --git a/lib/nexus_cli/tasks.rb b/lib/nexus_cli/tasks.rb index 916f3f2..cfc3c00 100755 --- a/lib/nexus_cli/tasks.rb +++ b/lib/nexus_cli/tasks.rb @@ -27,6 +27,18 @@ def self.included(base) :default => true, :desc => "Set to false to disable SSL Verification." + desc "start_staging", "Starts a new staging repository" + def start_staging + say nexus_remote.start + end + + desc "close_staging repository_id", "Closes the provided staging repository" + def close_staging(repository_id) + if nexus_remote.close(repository_id) + say "Staging repository #{repository_id} has been closed." + end + end + method_option :destination, :type => :string, :default => nil, From 2c84165f5ad91118027c4db5a1571234d036b805 Mon Sep 17 00:00:00 2001 From: Kyle Allan Date: Fri, 2 Aug 2013 11:02:58 -0700 Subject: [PATCH 3/4] remove 1.9.2 from travis --- .travis.yml | 1 - features/pro/nexus_staging.feature | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0b8343e..a9d16a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ script: "bundle exec thor spec:unit" language: ruby rvm: - - 1.9.2 - 1.9.3 diff --git a/features/pro/nexus_staging.feature b/features/pro/nexus_staging.feature index e86ab44..afaa627 100644 --- a/features/pro/nexus_staging.feature +++ b/features/pro/nexus_staging.feature @@ -8,4 +8,4 @@ Feature: Use the Nexus CLI to execute commands that interact with the Nexus Pro """ rcs-005 """ - And the exit status should be 0 \ No newline at end of file + And the exit status should be 0 From 0e6ff80f1b9badaffc402259f2f94e46308a5d4d Mon Sep 17 00:00:00 2001 From: Kyle Allan Date: Wed, 21 Aug 2013 10:33:29 -0700 Subject: [PATCH 4/4] foo --- features/nexus_oss.feature | 1 + features/step_definitions/cli_steps.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/features/nexus_oss.feature b/features/nexus_oss.feature index 37ef44b..c151978 100755 --- a/features/nexus_oss.feature +++ b/features/nexus_oss.feature @@ -10,6 +10,7 @@ Feature: Use the Nexus CLI """ And the exit status should be 0 + @wip @push Scenario: Push an Artifact When I push an artifact with the GAV of "com.test:mytest:tgz:1.0.0" diff --git a/features/step_definitions/cli_steps.rb b/features/step_definitions/cli_steps.rb index 13a0708..7cfaf53 100644 --- a/features/step_definitions/cli_steps.rb +++ b/features/step_definitions/cli_steps.rb @@ -19,10 +19,11 @@ end When /^I push an artifact with the GAV of "(.*)"$/ do |gav| - groupId, artifact_id, version, extension = gav.split(":") + groupId, artifact_id, extension, version = gav.split(":") file = File.new(File.join(temp_dir, "#{artifact_id}-#{version}.#{extension}"), 'w') file.puts "some data" file.close + puts "nexus-cli push #{gav} #{file.path} --overrides=#{get_overrides_string}" step "I run `nexus-cli push #{gav} #{file.path} --overrides=#{get_overrides_string}`" end