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',
}

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_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:



23
24
25
26
27
28
# File 'lib/artifactory/resources/permission_target.rb', line 23

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



48
49
50
51
52
53
54
55
56
# File 'lib/artifactory/resources/permission_target.rb', line 48

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:



62
63
64
65
66
67
68
69
70
# File 'lib/artifactory/resources/permission_target.rb', line 62

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



126
127
128
# File 'lib/artifactory/resources/permission_target.rb', line 126

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



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_patternObject

Return this object’s excludes_pattern

Returns:

  • (Object)


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

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



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

Returns:

  • (Boolean)


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

attribute :excludes_pattern, ''

#groupsObject

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_patternObject

Return this object’s includes_pattern

Returns:

  • (Object)


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

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



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

Returns:

  • (Boolean)


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

attribute :includes_pattern, '**'

#nameObject

Return this object’s name

Returns:

  • (Object)


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

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



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

Returns:

  • (Boolean)


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

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

#principalsObject

Return this object’s principals

Returns:

  • (Object)


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

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



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

Returns:

  • (Boolean)


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

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

#repositoriesObject

Return this object’s repositories

Returns:

  • (Object)


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

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



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

attribute :repositories

#repositories?Boolean

Determines if the repositories value exists and is truthy

Returns:

  • (Boolean)


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

attribute :repositories

#saveBoolean

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

Returns:

  • (Boolean)


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

#usersObject

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