class Artifactory::Resource::PermissionTarget

Constants

VERBOSE_PERMS

Public Class Methods

all(options = {}) click to toggle source

Get a list of all PermissionTargets in the system.

@param [Hash] options

the list of options

@option options [Artifactory::Client] :client

the client object to make the request with

@return [Array<Resource::PermissionTarget>]

the list of PermissionTargets
# File lib/artifactory/resources/permission_target.rb, line 37
def all(options = {})
  client = extract_client!(options)
  client.get("/api/security/permissions").map do |hash|
    from_url(hash["uri"], client: client)
  end
end
find(name, options = {}) click to toggle source

Find (fetch) a permission target by its name.

@example Find a permission target by its name

PermissionTarget.find('readers') #=> #<PermissionTarget name: 'readers' ...>

@param [String] name

the name of the permission target to find

@param [Hash] options

the list of options

@option options [Artifactory::Client] :client

the client object to make the request with

@return [Resource::PermissionTarget, nil]

an instance of the permission target that matches the given name, or +nil+
if one does not exist
# File lib/artifactory/resources/permission_target.rb, line 62
def find(name, options = {})
  client = extract_client!(options)

  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 = {}) click to toggle source

@see Resource::Base.from_hash Additionally use verbose names for permissions (e.g. 'read' for 'r')

Calls superclass method Artifactory::Resource::Base::from_hash
# File lib/artifactory/resources/permission_target.rb, line 77
def from_hash(hash, options = {})
  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

Private Class Methods

verbose(array) click to toggle source

Replace an array of permissions with one using verbose permission names

# File lib/artifactory/resources/permission_target.rb, line 92
def verbose(array)
  array.map { |elt| VERBOSE_PERMS[elt] }.sort
end

Public Instance Methods

client_principal() click to toggle source
# File lib/artifactory/resources/permission_target.rb, line 142
def client_principal
  @client_principal ||= Principal.new(principals["users"], principals["groups"])
end
delete() click to toggle source

Delete this PermissionTarget from artifactory, suppressing any ResourceNotFound exceptions might occur.

@return [Boolean]

true if the object was deleted successfully, false otherwise
# File lib/artifactory/resources/permission_target.rb, line 153
def delete
  client.delete(api_path)
  true
rescue Error::HTTPError
  false
end
groups() click to toggle source

Getter for groups

# File lib/artifactory/resources/permission_target.rb, line 175
def groups
  client_principal.groups
end
groups=(groups_hash) click to toggle source

Setter for groups (groups_hash expected to be friendly)

# 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
save() click to toggle source

Save the PermissionTarget to the artifactory server. See bit.ly/1qMOw0L

@return [Boolean]

# 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() click to toggle source

Getter for users

# File lib/artifactory/resources/permission_target.rb, line 189
def users
  client_principal.users
end
users=(users_hash) click to toggle source

Setter for users (expecting users_hash to be friendly)

# 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

Private Instance Methods

api_path() click to toggle source

The path to this PermissionTarget on the server.

@return [String]

# File lib/artifactory/resources/permission_target.rb, line 207
def api_path
  @api_path ||= "/api/security/permissions/#{url_safe(name)}"
end
headers() click to toggle source

The default headers for this object. This includes the Content-Type.

@return [Hash]

# File lib/artifactory/resources/permission_target.rb, line 216
def headers
  @headers ||= {
    "Content-Type" => "application/vnd.org.jfrog.artifactory.security.PermissionTarget+json",
  }
end