Class: Artifactory::Resource::User

Inherits:
Base
  • Object
show all
Defined in:
lib/artifactory/resources/user.rb

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_hash, 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::User>

Get a list of all users in the system.

Parameters:

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

    the list of options

Options Hash (options):

Returns:



16
17
18
19
20
21
# File 'lib/artifactory/resources/user.rb', line 16

def all(options = {})
  client = extract_client!(options)
  client.get('/api/security/users').map do |hash|
    from_url(hash['uri'], client: client)
  end
end

.find(name, options = {}) ⇒ Resource::User?

Find (fetch) a user by its name.

Examples:

Find a user by its name

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

Parameters:

  • name (String)

    the name of the user to find

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

    the list of options

Options Hash (options):

Returns:

  • (Resource::User, nil)

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



41
42
43
44
45
46
47
48
49
# File 'lib/artifactory/resources/user.rb', line 41

def find(name, options = {})
  client = extract_client!(options)

  response = client.get("/api/security/users/#{url_safe(name)}")
  from_hash(response, client: client)
rescue Error::HTTPError => e
  raise unless e.code == 404
  nil
end

Instance Method Details

#adminObject

Return this object’s admin

Returns:

  • (Object)


52
# File 'lib/artifactory/resources/user.rb', line 52

attribute :admin, false

#admin=(value) ⇒ Object

Set this object’s admin

Parameters:

  • value (Object)

    the value to set for admin

  • default (Object)

    the default value for this attribute



52
# File 'lib/artifactory/resources/user.rb', line 52

attribute :admin, false

#admin?Boolean

Determines if the admin value exists and is truthy

Returns:

  • (Boolean)


52
# File 'lib/artifactory/resources/user.rb', line 52

attribute :admin, false

#deleteBoolean

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

Returns:

  • (Boolean)

    true if the object was deleted successfully, false otherwise



69
70
71
72
73
74
# File 'lib/artifactory/resources/user.rb', line 69

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

#emailObject

Return this object’s email

Returns:

  • (Object)


53
# File 'lib/artifactory/resources/user.rb', line 53

attribute :email

#email=(value) ⇒ Object

Set this object’s email

Parameters:

  • value (Object)

    the value to set for email

  • default (Object)

    the default value for this attribute



53
# File 'lib/artifactory/resources/user.rb', line 53

attribute :email

#email?Boolean

Determines if the email value exists and is truthy

Returns:

  • (Boolean)


53
# File 'lib/artifactory/resources/user.rb', line 53

attribute :email

#groupsObject

Return this object’s groups

Returns:

  • (Object)


54
# File 'lib/artifactory/resources/user.rb', line 54

attribute :groups, []

#groups=(value) ⇒ Object

Set this object’s groups

Parameters:

  • value (Object)

    the value to set for groups

  • default (Object)

    the default value for this attribute



54
# File 'lib/artifactory/resources/user.rb', line 54

attribute :groups, []

#groups?Boolean

Determines if the groups value exists and is truthy

Returns:

  • (Boolean)


54
# File 'lib/artifactory/resources/user.rb', line 54

attribute :groups, []

#internal_password_disabledObject

Return this object’s internal_password_disabled

Returns:

  • (Object)


55
# File 'lib/artifactory/resources/user.rb', line 55

attribute :internal_password_disabled, false

#internal_password_disabled=(value) ⇒ Object

Set this object’s internal_password_disabled

Parameters:

  • value (Object)

    the value to set for internal_password_disabled

  • default (Object)

    the default value for this attribute



55
# File 'lib/artifactory/resources/user.rb', line 55

attribute :internal_password_disabled, false

#internal_password_disabled?Boolean

Determines if the internal_password_disabled value exists and is truthy

Returns:

  • (Boolean)


55
# File 'lib/artifactory/resources/user.rb', line 55

attribute :internal_password_disabled, false

#last_logged_inObject

Return this object’s last_logged_in

Returns:

  • (Object)


56
# File 'lib/artifactory/resources/user.rb', line 56

attribute :last_logged_in

#last_logged_in=(value) ⇒ Object

Set this object’s last_logged_in

Parameters:

  • value (Object)

    the value to set for last_logged_in

  • default (Object)

    the default value for this attribute



56
# File 'lib/artifactory/resources/user.rb', line 56

attribute :last_logged_in

#last_logged_in?Boolean

Determines if the last_logged_in value exists and is truthy

Returns:

  • (Boolean)


56
# File 'lib/artifactory/resources/user.rb', line 56

attribute :last_logged_in

#nameObject

Return this object’s name

Returns:

  • (Object)


57
# File 'lib/artifactory/resources/user.rb', line 57

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



57
# File 'lib/artifactory/resources/user.rb', line 57

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

#name?Boolean

Determines if the name value exists and is truthy

Returns:

  • (Boolean)


57
# File 'lib/artifactory/resources/user.rb', line 57

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

#passwordObject

Return this object’s password

Returns:

  • (Object)


58
# File 'lib/artifactory/resources/user.rb', line 58

attribute :password

#password=(value) ⇒ Object

Set this object’s password

Parameters:

  • value (Object)

    the value to set for password

  • default (Object)

    the default value for this attribute



58
# File 'lib/artifactory/resources/user.rb', line 58

attribute :password

#password?Boolean

Determines if the password value exists and is truthy

Returns:

  • (Boolean)


58
# File 'lib/artifactory/resources/user.rb', line 58

attribute :password

#profile_updatableObject

Return this object’s profile_updatable

Returns:

  • (Object)


59
# File 'lib/artifactory/resources/user.rb', line 59

attribute :profile_updatable, true

#profile_updatable=(value) ⇒ Object

Set this object’s profile_updatable

Parameters:

  • value (Object)

    the value to set for profile_updatable

  • default (Object)

    the default value for this attribute



59
# File 'lib/artifactory/resources/user.rb', line 59

attribute :profile_updatable, true

#profile_updatable?Boolean

Determines if the profile_updatable value exists and is truthy

Returns:

  • (Boolean)


59
# File 'lib/artifactory/resources/user.rb', line 59

attribute :profile_updatable, true

#realmObject

Return this object’s realm

Returns:

  • (Object)


60
# File 'lib/artifactory/resources/user.rb', line 60

attribute :realm

#realm=(value) ⇒ Object

Set this object’s realm

Parameters:

  • value (Object)

    the value to set for realm

  • default (Object)

    the default value for this attribute



60
# File 'lib/artifactory/resources/user.rb', line 60

attribute :realm

#realm?Boolean

Determines if the realm value exists and is truthy

Returns:

  • (Boolean)


60
# File 'lib/artifactory/resources/user.rb', line 60

attribute :realm

#saveBoolean

Creates or updates a user configuration depending on if the user configuration previously existed.

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
# File 'lib/artifactory/resources/user.rb', line 82

def save
  if self.class.find(name, client: client)
    client.post(api_path, to_json, headers)
  else
    client.put(api_path, to_json, headers)
  end
  true
end