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', }
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, 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.
23 24 25 26 27 28 |
# File 'lib/artifactory/resources/permission_target.rb', line 23 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.
48 49 50 51 52 53 54 55 56 |
# File 'lib/artifactory/resources/permission_target.rb', line 48 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’)
62 63 64 65 66 67 68 69 70 |
# File 'lib/artifactory/resources/permission_target.rb', line 62 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
126 127 128 |
# File 'lib/artifactory/resources/permission_target.rb', line 126 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.
137 138 139 140 141 142 |
# File 'lib/artifactory/resources/permission_target.rb', line 137 def delete client.delete(api_path) true rescue Error::HTTPError false end |
#excludes_pattern ⇒ Object
Return this object’s excludes_pattern
122 |
# File 'lib/artifactory/resources/permission_target.rb', line 122 attribute :excludes_pattern, '' |
#excludes_pattern=(value) ⇒ Object
Set this object’s excludes_pattern
122 |
# File 'lib/artifactory/resources/permission_target.rb', line 122 attribute :excludes_pattern, '' |
#excludes_pattern? ⇒ Boolean
Determines if the excludes_pattern
value exists and is truthy
122 |
# File 'lib/artifactory/resources/permission_target.rb', line 122 attribute :excludes_pattern, '' |
#groups ⇒ Object
Getter for groups
159 160 161 |
# File 'lib/artifactory/resources/permission_target.rb', line 159 def groups client_principal.groups end |
#groups=(groups_hash) ⇒ Object
Setter for groups (groups_hash expected to be friendly)
166 167 168 |
# File 'lib/artifactory/resources/permission_target.rb', line 166 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
121 |
# File 'lib/artifactory/resources/permission_target.rb', line 121 attribute :includes_pattern, '**' |
#includes_pattern=(value) ⇒ Object
Set this object’s includes_pattern
121 |
# File 'lib/artifactory/resources/permission_target.rb', line 121 attribute :includes_pattern, '**' |
#includes_pattern? ⇒ Boolean
Determines if the includes_pattern
value exists and is truthy
121 |
# File 'lib/artifactory/resources/permission_target.rb', line 121 attribute :includes_pattern, '**' |
#name ⇒ Object
Return this object’s name
120 |
# File 'lib/artifactory/resources/permission_target.rb', line 120 attribute :name, ->{ raise 'Name missing!' } |
#name=(value) ⇒ Object
Set this object’s name
120 |
# File 'lib/artifactory/resources/permission_target.rb', line 120 attribute :name, ->{ raise 'Name missing!' } |
#name? ⇒ Boolean
Determines if the name
value exists and is truthy
120 |
# File 'lib/artifactory/resources/permission_target.rb', line 120 attribute :name, ->{ raise 'Name missing!' } |
#principals ⇒ Object
Return this object’s principals
124 |
# File 'lib/artifactory/resources/permission_target.rb', line 124 attribute :principals, { 'users' => {}, 'groups' => {} } |
#principals=(value) ⇒ Object
Set this object’s principals
124 |
# File 'lib/artifactory/resources/permission_target.rb', line 124 attribute :principals, { 'users' => {}, 'groups' => {} } |
#principals? ⇒ Boolean
Determines if the principals
value exists and is truthy
124 |
# File 'lib/artifactory/resources/permission_target.rb', line 124 attribute :principals, { 'users' => {}, 'groups' => {} } |
#repositories ⇒ Object
Return this object’s repositories
123 |
# File 'lib/artifactory/resources/permission_target.rb', line 123 attribute :repositories |
#repositories=(value) ⇒ Object
Set this object’s repositories
123 |
# File 'lib/artifactory/resources/permission_target.rb', line 123 attribute :repositories |
#repositories? ⇒ Boolean
Determines if the repositories
value exists and is truthy
123 |
# File 'lib/artifactory/resources/permission_target.rb', line 123 attribute :repositories |
#save ⇒ Boolean
Save the PermissionTarget to the artifactory server. See bit.ly/1qMOw0L
150 151 152 153 154 |
# File 'lib/artifactory/resources/permission_target.rb', line 150 def save send("#{:principals}=", client_principal.to_abbreviated) client.put(api_path, to_json, headers) true end |
#users ⇒ Object
Getter for users
173 174 175 |
# File 'lib/artifactory/resources/permission_target.rb', line 173 def users client_principal.users end |
#users=(users_hash) ⇒ Object
Setter for users (expecting users_hash to be friendly)
180 181 182 |
# File 'lib/artifactory/resources/permission_target.rb', line 180 def users=(users_hash) client_principal.users = Hash[users_hash.map { |k, v| [k, v.sort] } ] end |