Class: Artifactory::Resource::PermissionTarget

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • options (Hash) (defaults to: {})

    the list of options

Options Hash (options):

Returns:



37
38
39
40
41
42
# 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 = {}) ⇒ Resource::PermissionTarget?

Find (fetch) a permission target by its name.

Examples:

Find a permission target by its name

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

Parameters:

  • name (String)

    the name of the permission target to find

  • options (Hash) (defaults to: {})

    the list of options

Options Hash (options):

Returns:

  • (Resource::PermissionTarget, nil)

    an instance of the permission target that matches the given name, or nil if one does not exist



62
63
64
65
66
67
68
69
70
# 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 = {}) ⇒ Object

Additionally use verbose names for permissions (e.g. ‘read’ for ‘r’)

See Also:



76
77
78
79
80
81
82
83
84
# File 'lib/artifactory/resources/permission_target.rb', line 76

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

Instance Method Details

#client_principalObject



140
141
142
# File 'lib/artifactory/resources/permission_target.rb', line 140

def client_principal
  @client_principal ||= Principal.new(principals["users"], principals["groups"])
end

#deleteBoolean

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

Returns:

  • (Boolean)

    true if the object was deleted successfully, false otherwise



151
152
153
154
155
156
# File 'lib/artifactory/resources/permission_target.rb', line 151

def delete
  client.delete(api_path)
  true
rescue Error::HTTPError
  false
end

#excludes_patternObject

Return this object’s excludes_pattern

Returns:

  • (Object)


136
# File 'lib/artifactory/resources/permission_target.rb', line 136

attribute :excludes_pattern, ""

#excludes_pattern=(value) ⇒ Object

Set this object’s excludes_pattern

Parameters:

  • value (Object)

    the value to set for excludes_pattern

  • default (Object)

    the default value for this attribute



136
# File 'lib/artifactory/resources/permission_target.rb', line 136

attribute :excludes_pattern, ""

#excludes_pattern?Boolean

Determines if the excludes_pattern value exists and is truthy

Returns:

  • (Boolean)


136
# File 'lib/artifactory/resources/permission_target.rb', line 136

attribute :excludes_pattern, ""

#groupsObject

Getter for groups



173
174
175
# File 'lib/artifactory/resources/permission_target.rb', line 173

def groups
  client_principal.groups
end

#groups=(groups_hash) ⇒ Object

Setter for groups (groups_hash expected to be friendly)



180
181
182
# File 'lib/artifactory/resources/permission_target.rb', line 180

def groups=(groups_hash)
  client_principal.groups = Hash[groups_hash.map { |k, v| [k, v.sort] } ]
end

#includes_patternObject

Return this object’s includes_pattern

Returns:

  • (Object)


135
# File 'lib/artifactory/resources/permission_target.rb', line 135

attribute :includes_pattern, "**"

#includes_pattern=(value) ⇒ Object

Set this object’s includes_pattern

Parameters:

  • value (Object)

    the value to set for includes_pattern

  • default (Object)

    the default value for this attribute



135
# File 'lib/artifactory/resources/permission_target.rb', line 135

attribute :includes_pattern, "**"

#includes_pattern?Boolean

Determines if the includes_pattern value exists and is truthy

Returns:

  • (Boolean)


135
# File 'lib/artifactory/resources/permission_target.rb', line 135

attribute :includes_pattern, "**"

#nameObject

Return this object’s name

Returns:

  • (Object)


134
# File 'lib/artifactory/resources/permission_target.rb', line 134

attribute :name, -> { raise "Name missing!" }

#name=(value) ⇒ Object

Set this object’s name

Parameters:

  • value (Object)

    the value to set for name

  • default (Object)

    the default value for this attribute



134
# File 'lib/artifactory/resources/permission_target.rb', line 134

attribute :name, -> { raise "Name missing!" }

#name?Boolean

Determines if the name value exists and is truthy

Returns:

  • (Boolean)


134
# File 'lib/artifactory/resources/permission_target.rb', line 134

attribute :name, -> { raise "Name missing!" }

#principalsObject

Return this object’s principals

Returns:

  • (Object)


138
# File 'lib/artifactory/resources/permission_target.rb', line 138

attribute :principals, { "users" => {}, "groups" => {} }

#principals=(value) ⇒ Object

Set this object’s principals

Parameters:

  • value (Object)

    the value to set for principals

  • default (Object)

    the default value for this attribute



138
# File 'lib/artifactory/resources/permission_target.rb', line 138

attribute :principals, { "users" => {}, "groups" => {} }

#principals?Boolean

Determines if the principals value exists and is truthy

Returns:

  • (Boolean)


138
# File 'lib/artifactory/resources/permission_target.rb', line 138

attribute :principals, { "users" => {}, "groups" => {} }

#repositoriesObject

Return this object’s repositories

Returns:

  • (Object)


137
# File 'lib/artifactory/resources/permission_target.rb', line 137

attribute :repositories

#repositories=(value) ⇒ Object

Set this object’s repositories

Parameters:

  • value (Object)

    the value to set for repositories

  • default (Object)

    the default value for this attribute



137
# File 'lib/artifactory/resources/permission_target.rb', line 137

attribute :repositories

#repositories?Boolean

Determines if the repositories value exists and is truthy

Returns:

  • (Boolean)


137
# File 'lib/artifactory/resources/permission_target.rb', line 137

attribute :repositories

#saveBoolean

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

Returns:

  • (Boolean)


164
165
166
167
168
# File 'lib/artifactory/resources/permission_target.rb', line 164

def save
  send("principals=", client_principal.to_abbreviated)
  client.put(api_path, to_json, headers)
  true
end

#usersObject

Getter for users



187
188
189
# File 'lib/artifactory/resources/permission_target.rb', line 187

def users
  client_principal.users
end

#users=(users_hash) ⇒ Object

Setter for users (expecting users_hash to be friendly)



194
195
196
# File 'lib/artifactory/resources/permission_target.rb', line 194

def users=(users_hash)
  client_principal.users = Hash[users_hash.map { |k, v| [k, v.sort] } ]
end