diff --git a/Berksfile b/Berksfile index 8fe19ce..44bc4fc 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,3 @@ -site :opscode -chef_api :config +source 'https://api.berkshelf.com' metadata diff --git a/README.md b/README.md index ada9a91..9f1be57 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,9 @@ Attribute | Description | Type | Default --------- |------------- |----- |-------- name | Name of the plugin to install | String | name -## nexus\_repository +## nexus\_hosted\_repository -Resource provider for creating and deleting Neuxs repositories. +Resource provider for creating and deleting hosted Neuxs repositories. ### Actions Action | Description | Default @@ -114,11 +114,49 @@ update | Updates a repository | ### Attributes Attribute | Description | Type | Default --------- |------------- |----- |-------- -name | Name of the repository to create/delete | String | name -type | The type of repository - either "hosted" or "proxy". | String | +name | Name of the repository to create/delete/update | String | name +publisher | The type of repository - either "hosted" or "proxy". | String | +policy | Either "HOSTED" or "SNAPSHOT" repository policy for artifacts | String | + + +## nexus\_group\_repository + +Resource provider for creating and deleting group Neuxs repositories. + +### Actions +Action | Description | Default +------- |------------- |--------- +create | Creates a new repository | Yes +delete | Deletes a repository | +add_to | Adds a repository to group repository | +remove_from | Removes a repository to group repository | + + +### Attributes +Attribute | Description | Type | Default +--------- |------------- |----- |-------- +name | Name of the repository to create/delete/add_to /remove_from | String | name +repository | Repository to add/remove from group repo | String | + + +## nexus\_proxy\_repository + +Resource provider for creating and deleting proxy Neuxs repositories. + +### Actions +Action | Description | Default +------- |------------- |--------- +create | Creates a new repository | Yes +delete | Deletes a repository | +update | Updates a repository | + +### Attributes +Attribute | Description | Type | Default +--------- |------------- |----- |-------- +name | Name of the repository to create/delete/update | String | name url | The url used for a proxy repository. | String | policy | Either "HOSTED" or "SNAPSHOT" repository policy for artifacts | String | -publisher | Whether this repository is a publisher of artifacts. | TrueClass, FalseClass | +publisher | The type of repository - either "hosted" or "proxy". | String | subscriber | Whether this repository is a subscriber to artifacts. | TrueClass, FalseClass | preemptive_fetch | Whether this (proxy) repository should preemptively fetch artifacts | TrueClass, FalseClass | @@ -134,8 +172,8 @@ update | Updates a global Nexus setting to a new value. | Yes ### Attributes Attribute | Description | Type | Default --------- |------------- |----- |-------- -path | The element of the settings that is going to be changed. | String | name -value | The new value to update the path to. | String, TrueClass, FalseClass | +path | Period '.' delimited path to element of the settings that is going to be changed. | String | name +value | The new value to update the path to. | String, TrueClass, FalseClass, Hash | ## nexus\_user diff --git a/libraries/chef_nexus.rb b/libraries/chef_nexus.rb index 43730c2..76e554c 100644 --- a/libraries/chef_nexus.rb +++ b/libraries/chef_nexus.rb @@ -220,6 +220,16 @@ def encrypted_data_bag_item(node, data_bag, data_bag_item) Mash.from_hash(item.to_hash) rescue Net::HTTPServerException => e nil + + # chef_data_bag_item.rb fails to handle scenario of missing data bag :-(, + # it reports this as Chef::Exceptions::ValidationFailed exception. + # Adding a different rescue block if things exception needs to be handled differently + rescue Chef::Exceptions::ValidationFailed => e + nil + + # if you are using vault and if data bag it not present we need to handle that exception as well + rescue ChefVault::Exceptions::KeysNotFound + nil end end end diff --git a/providers/settings.rb b/providers/settings.rb index 200659b..1818a8d 100644 --- a/providers/settings.rb +++ b/providers/settings.rb @@ -50,7 +50,8 @@ def get_nexus_settings_json def update_nexus_settings_json require 'json' - json = JSON.parse(get_nexus_settings_json) - edited_json = JsonPath.for(json).gsub("$..#{new_resource.path}") {|value| new_resource.value}.to_hash - Chef::Nexus.nexus(node).upload_global_settings(JSON.dump(edited_json)) + hashed_settings = JSON.parse(get_nexus_settings_json) + *path_elements, setting_to_update = new_resource.path.split(".") + path_elements.inject(hashed_settings, :fetch)[setting_to_update] = new_resource.value + Chef::Nexus.nexus(node).upload_global_settings(JSON.dump(hashed_settings)) end diff --git a/resources/settings.rb b/resources/settings.rb index 3b86ce2..0b72970 100644 --- a/resources/settings.rb +++ b/resources/settings.rb @@ -22,4 +22,4 @@ default_action :update attribute :path, :kind_of => String, :name_attribute => true -attribute :value, :kind_of => [String, TrueClass, FalseClass], :required => true +attribute :value, :kind_of => [String, TrueClass, FalseClass, Hash], :required => true