Class: Artifactory::Resource::PermissionTarget
- Defined in:
- lib/artifactory/resources/permission_target.rb
Defined Under Namespace
Classes: Principal
Constant Summary collapse
- VERBOSE_PERMS =
{ "d" => "delete", "m" => "admin", "n" => "annotate", "r" => "read", "w" => "deploy", }.freeze
Class Method Summary collapse
-
.all(options = {}) ⇒ Array<Resource::PermissionTarget>
Get a list of all PermissionTargets in the system.
-
.find(name, options = {}) ⇒ Resource::PermissionTarget?
Find (fetch) a permission target by its name.
-
.from_hash(hash, options = {}) ⇒ Object
Additionally use verbose names for permissions (e.g. ‘read’ for ‘r’).
Instance Method Summary collapse
- #client_principal ⇒ Object
-
#delete ⇒ Boolean
Delete this PermissionTarget from artifactory, suppressing any
ResourceNotFound
exceptions might occur. -
#excludes_pattern ⇒ Object
Return this object’s
excludes_pattern
. -
#excludes_pattern=(value) ⇒ Object
Set this object’s
excludes_pattern
. -
#excludes_pattern? ⇒ Boolean
Determines if the
excludes_pattern
value exists and is truthy. -
#groups ⇒ Object
Getter for groups.
-
#groups=(groups_hash) ⇒ Object
Setter for groups (groups_hash expected to be friendly).
-
#includes_pattern ⇒ Object
Return this object’s
includes_pattern
. -
#includes_pattern=(value) ⇒ Object
Set this object’s
includes_pattern
. -
#includes_pattern? ⇒ Boolean
Determines if the
includes_pattern
value exists and is truthy. -
#name ⇒ Object
Return this object’s
name
. -
#name=(value) ⇒ Object
Set this object’s
name
. -
#name? ⇒ Boolean
Determines if the
name
value exists and is truthy. -
#principals ⇒ Object
Return this object’s
principals
. -
#principals=(value) ⇒ Object
Set this object’s
principals
. -
#principals? ⇒ Boolean
Determines if the
principals
value exists and is truthy. -
#repositories ⇒ Object
Return this object’s
repositories
. -
#repositories=(value) ⇒ Object
Set this object’s
repositories
. -
#repositories? ⇒ Boolean
Determines if the
repositories
value exists and is truthy. -
#save ⇒ Boolean
Save the PermissionTarget to the artifactory server.
-
#users ⇒ Object
Getter for users.
-
#users=(users_hash) ⇒ Object
Setter for users (expecting users_hash to be friendly).
Methods inherited from Base
attribute, attributes, #attributes, #client, #client=, #client?, #extract_client!, extract_client!, find_from_config, format_repos!, #format_repos!, from_url, has_attribute?, #initialize, #inspect, list_from_config, #set, #to_hash, #to_json, #to_matrix_properties, #to_query_string_parameters, #to_s, uri_parser, #url_safe, url_safe
Constructor Details
This class inherits a constructor from Artifactory::Resource::Base
Class Method Details
.all(options = {}) ⇒ Array<Resource::PermissionTarget>
Get a list of all PermissionTargets in the system.
37 38 39 40 41 42 |
# File 'lib/artifactory/resources/permission_target.rb', line 37 def all( = {}) client = extract_client!() client.get("/api/security/permissions").map do |hash| from_url(hash["uri"], client: client) end end |
.find(name, options = {}) ⇒ Resource::PermissionTarget?
Find (fetch) a permission target by its name.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/artifactory/resources/permission_target.rb', line 62 def find(name, = {}) client = extract_client!() response = client.get("/api/security/permissions/#{url_safe(name)}") from_hash(response, client: client) rescue Error::HTTPError => e raise unless e.code == 404 nil end |
.from_hash(hash, options = {}) ⇒ Object
Additionally use verbose names for permissions (e.g. ‘read’ for ‘r’)
77 78 79 80 81 82 83 84 85 |
# File 'lib/artifactory/resources/permission_target.rb', line 77 def from_hash(hash, = {}) super.tap do |instance| %w{users groups}.each do |key| if instance.principals[key] && !instance.principals[key].nil? instance.principals[key] = Hash[instance.principals[key].map { |k, v| [k, verbose(v)] } ] end end end end |
Instance Method Details
#client_principal ⇒ Object
142 143 144 |
# File 'lib/artifactory/resources/permission_target.rb', line 142 def client_principal @client_principal ||= Principal.new(principals["users"], principals["groups"]) end |
#delete ⇒ Boolean
Delete this PermissionTarget from artifactory, suppressing any ResourceNotFound
exceptions might occur.
153 154 155 156 157 158 |
# File 'lib/artifactory/resources/permission_target.rb', line 153 def delete client.delete(api_path) true rescue Error::HTTPError false end |
#excludes_pattern ⇒ Object
Return this object’s excludes_pattern
138 |
# File 'lib/artifactory/resources/permission_target.rb', line 138 attribute :excludes_pattern, "" |
#excludes_pattern=(value) ⇒ Object
Set this object’s excludes_pattern
138 |
# File 'lib/artifactory/resources/permission_target.rb', line 138 attribute :excludes_pattern, "" |
#excludes_pattern? ⇒ Boolean
Determines if the excludes_pattern
value exists and is truthy
138 |
# File 'lib/artifactory/resources/permission_target.rb', line 138 attribute :excludes_pattern, "" |
#groups ⇒ Object
Getter for groups
175 176 177 |
# File 'lib/artifactory/resources/permission_target.rb', line 175 def groups client_principal.groups end |
#groups=(groups_hash) ⇒ Object
Setter for groups (groups_hash expected to be friendly)
182 183 184 |
# File 'lib/artifactory/resources/permission_target.rb', line 182 def groups=(groups_hash) client_principal.groups = Hash[groups_hash.map { |k, v| [k, v.sort] } ] end |
#includes_pattern ⇒ Object
Return this object’s includes_pattern
137 |
# File 'lib/artifactory/resources/permission_target.rb', line 137 attribute :includes_pattern, "**" |
#includes_pattern=(value) ⇒ Object
Set this object’s includes_pattern
137 |
# File 'lib/artifactory/resources/permission_target.rb', line 137 attribute :includes_pattern, "**" |
#includes_pattern? ⇒ Boolean
Determines if the includes_pattern
value exists and is truthy
137 |
# File 'lib/artifactory/resources/permission_target.rb', line 137 attribute :includes_pattern, "**" |
#name ⇒ Object
Return this object’s name
136 |
# File 'lib/artifactory/resources/permission_target.rb', line 136 attribute :name, -> { raise "Name missing!" } |
#name=(value) ⇒ Object
Set this object’s name
136 |
# File 'lib/artifactory/resources/permission_target.rb', line 136 attribute :name, -> { raise "Name missing!" } |
#name? ⇒ Boolean
Determines if the name
value exists and is truthy
136 |
# File 'lib/artifactory/resources/permission_target.rb', line 136 attribute :name, -> { raise "Name missing!" } |
#principals ⇒ Object
Return this object’s principals
140 |
# File 'lib/artifactory/resources/permission_target.rb', line 140 attribute :principals, { "users" => {}, "groups" => {} } |
#principals=(value) ⇒ Object
Set this object’s principals
140 |
# File 'lib/artifactory/resources/permission_target.rb', line 140 attribute :principals, { "users" => {}, "groups" => {} } |
#principals? ⇒ Boolean
Determines if the principals
value exists and is truthy
140 |
# File 'lib/artifactory/resources/permission_target.rb', line 140 attribute :principals, { "users" => {}, "groups" => {} } |
#repositories ⇒ Object
Return this object’s repositories
139 |
# File 'lib/artifactory/resources/permission_target.rb', line 139 attribute :repositories |
#repositories=(value) ⇒ Object
Set this object’s repositories
139 |
# File 'lib/artifactory/resources/permission_target.rb', line 139 attribute :repositories |
#repositories? ⇒ Boolean
Determines if the repositories
value exists and is truthy
139 |
# File 'lib/artifactory/resources/permission_target.rb', line 139 attribute :repositories |
#save ⇒ Boolean
Save the PermissionTarget to the artifactory server. See bit.ly/1qMOw0L
166 167 168 169 170 |
# File 'lib/artifactory/resources/permission_target.rb', line 166 def save send("principals=", client_principal.to_abbreviated) client.put(api_path, to_json, headers) true end |
#users ⇒ Object
Getter for users
189 190 191 |
# File 'lib/artifactory/resources/permission_target.rb', line 189 def users client_principal.users end |
#users=(users_hash) ⇒ Object
Setter for users (expecting users_hash to be friendly)
196 197 198 |
# File 'lib/artifactory/resources/permission_target.rb', line 196 def users=(users_hash) client_principal.users = Hash[users_hash.map { |k, v| [k, v.sort] } ] end |