Class: Artifactory::Resource::Repository

Inherits:
Base
  • Object
show all
Defined in:
lib/artifactory/resources/repository.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_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::Repository>

Get a list of all repositories in the system.

Options Hash (options):



32
33
34
35
36
37
# File 'lib/artifactory/resources/repository.rb', line 32

def all(options = {})
  client = extract_client!(options)
  client.get('/api/repositories').map do |hash|
    find(hash['key'], client: client)
  end.compact
end

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

Find (fetch) a repository by name.

Examples:

Find a repository by named key

Repository.find(name: 'libs-release-local') #=> #<Resource::Artifact>

Options Hash (options):

  • :name (String)

    the name of the repository to find

  • :client (Artifactory::Client)

    the client object to make the request with



57
58
59
60
61
62
63
64
65
# File 'lib/artifactory/resources/repository.rb', line 57

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

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

Instance Method Details

#artifactsCollection::Artifact

The list of artifacts in this repository on the remote artifactory server.

Examples:

Get the list of artifacts for a repository

repo = Repository.new('libs-release-local')
repo.artifacts #=> [#<Resource::Artifacts>, ...]

See Also:



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

def artifacts
  @artifacts ||= Collection::Artifact.new(self, repos: key) do
    Resource::Artifact.search(name: '.*', repos: key)
  end
end

#blacked_outObject

Return this object’s blacked_out



68
# File 'lib/artifactory/resources/repository.rb', line 68

attribute :blacked_out, false

#blacked_out=(value) ⇒ Object

Set this object’s blacked_out



68
# File 'lib/artifactory/resources/repository.rb', line 68

attribute :blacked_out, false

#blacked_out?Boolean

Determines if the blacked_out value exists and is truthy



68
# File 'lib/artifactory/resources/repository.rb', line 68

attribute :blacked_out, false

#checksum_policy_typeObject

Return this object’s checksum_policy_type



70
# File 'lib/artifactory/resources/repository.rb', line 70

attribute :checksum_policy_type, 'client-checksums'

#checksum_policy_type=(value) ⇒ Object

Set this object’s checksum_policy_type



70
# File 'lib/artifactory/resources/repository.rb', line 70

attribute :checksum_policy_type, 'client-checksums'

#checksum_policy_type?Boolean

Determines if the checksum_policy_type value exists and is truthy



70
# File 'lib/artifactory/resources/repository.rb', line 70

attribute :checksum_policy_type, 'client-checksums'

#deleteBoolean

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



178
179
180
181
182
183
# File 'lib/artifactory/resources/repository.rb', line 178

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

#descriptionObject

Return this object’s description



69
# File 'lib/artifactory/resources/repository.rb', line 69

attribute :description

#description=(value) ⇒ Object

Set this object’s description



69
# File 'lib/artifactory/resources/repository.rb', line 69

attribute :description

#description?Boolean

Determines if the description value exists and is truthy



69
# File 'lib/artifactory/resources/repository.rb', line 69

attribute :description

#excludes_patternObject

Return this object’s excludes_pattern



71
# File 'lib/artifactory/resources/repository.rb', line 71

attribute :excludes_pattern, ''

#excludes_pattern=(value) ⇒ Object

Set this object’s excludes_pattern



71
# File 'lib/artifactory/resources/repository.rb', line 71

attribute :excludes_pattern, ''

#excludes_pattern?Boolean

Determines if the excludes_pattern value exists and is truthy



71
# File 'lib/artifactory/resources/repository.rb', line 71

attribute :excludes_pattern, ''

#filesObject



160
161
162
163
164
165
166
167
168
169
# File 'lib/artifactory/resources/repository.rb', line 160

def files
  response = client.get("/api/storage/#{url_safe(key)}", {
    deep:            0,
    listFolders:     0,
    mdTimestamps:    0,
    includeRootPath: 0,
  })

  response['children']
end

#handle_releasesObject

Return this object’s handle_releases



72
# File 'lib/artifactory/resources/repository.rb', line 72

attribute :handle_releases, true

#handle_releases=(value) ⇒ Object

Set this object’s handle_releases



72
# File 'lib/artifactory/resources/repository.rb', line 72

attribute :handle_releases, true

#handle_releases?Boolean

Determines if the handle_releases value exists and is truthy



72
# File 'lib/artifactory/resources/repository.rb', line 72

attribute :handle_releases, true

#handle_snapshotsObject

Return this object’s handle_snapshots



73
# File 'lib/artifactory/resources/repository.rb', line 73

attribute :handle_snapshots, true

#handle_snapshots=(value) ⇒ Object

Set this object’s handle_snapshots



73
# File 'lib/artifactory/resources/repository.rb', line 73

attribute :handle_snapshots, true

#handle_snapshots?Boolean

Determines if the handle_snapshots value exists and is truthy



73
# File 'lib/artifactory/resources/repository.rb', line 73

attribute :handle_snapshots, true

#includes_patternObject

Return this object’s includes_pattern



74
# File 'lib/artifactory/resources/repository.rb', line 74

attribute :includes_pattern, '**/*'

#includes_pattern=(value) ⇒ Object

Set this object’s includes_pattern



74
# File 'lib/artifactory/resources/repository.rb', line 74

attribute :includes_pattern, '**/*'

#includes_pattern?Boolean

Determines if the includes_pattern value exists and is truthy



74
# File 'lib/artifactory/resources/repository.rb', line 74

attribute :includes_pattern, '**/*'

#keyObject

Return this object’s key



75
# File 'lib/artifactory/resources/repository.rb', line 75

attribute :key, ->{ raise 'Key is missing!' }

#key=(value) ⇒ Object

Set this object’s key



75
# File 'lib/artifactory/resources/repository.rb', line 75

attribute :key, ->{ raise 'Key is missing!' }

#key?Boolean

Determines if the key value exists and is truthy



75
# File 'lib/artifactory/resources/repository.rb', line 75

attribute :key, ->{ raise 'Key is missing!' }

#max_unique_snapshotsObject

Return this object’s max_unique_snapshots



76
# File 'lib/artifactory/resources/repository.rb', line 76

attribute :max_unique_snapshots, 0

#max_unique_snapshots=(value) ⇒ Object

Set this object’s max_unique_snapshots



76
# File 'lib/artifactory/resources/repository.rb', line 76

attribute :max_unique_snapshots, 0

#max_unique_snapshots?Boolean

Determines if the max_unique_snapshots value exists and is truthy



76
# File 'lib/artifactory/resources/repository.rb', line 76

attribute :max_unique_snapshots, 0

#notesObject

Return this object’s notes



77
# File 'lib/artifactory/resources/repository.rb', line 77

attribute :notes

#notes=(value) ⇒ Object

Set this object’s notes



77
# File 'lib/artifactory/resources/repository.rb', line 77

attribute :notes

#notes?Boolean

Determines if the notes value exists and is truthy



77
# File 'lib/artifactory/resources/repository.rb', line 77

attribute :notes

#property_setsObject

Return this object’s property_sets



78
# File 'lib/artifactory/resources/repository.rb', line 78

attribute :property_sets, []

#property_sets=(value) ⇒ Object

Set this object’s property_sets



78
# File 'lib/artifactory/resources/repository.rb', line 78

attribute :property_sets, []

#property_sets?Boolean

Determines if the property_sets value exists and is truthy



78
# File 'lib/artifactory/resources/repository.rb', line 78

attribute :property_sets, []

#rclassObject

Return this object’s rclass



80
# File 'lib/artifactory/resources/repository.rb', line 80

attribute :rclass, 'local'

#rclass=(value) ⇒ Object

Set this object’s rclass



80
# File 'lib/artifactory/resources/repository.rb', line 80

attribute :rclass, 'local'

#rclass?Boolean

Determines if the rclass value exists and is truthy



80
# File 'lib/artifactory/resources/repository.rb', line 80

attribute :rclass, 'local'

#repo_layout_refObject

Return this object’s repo_layout_ref



79
# File 'lib/artifactory/resources/repository.rb', line 79

attribute :repo_layout_ref, 'maven-2-default'

#repo_layout_ref=(value) ⇒ Object

Set this object’s repo_layout_ref



79
# File 'lib/artifactory/resources/repository.rb', line 79

attribute :repo_layout_ref, 'maven-2-default'

#repo_layout_ref?Boolean

Determines if the repo_layout_ref value exists and is truthy



79
# File 'lib/artifactory/resources/repository.rb', line 79

attribute :repo_layout_ref, 'maven-2-default'

#saveBoolean

Creates or updates a repository configuration depending on if the repository configuration previously existed. This method also works around Artifactory’s dangerous default behavior:

> An existing repository with the same key are removed from the
> configuration and its content is removed!


94
95
96
97
98
99
100
101
# File 'lib/artifactory/resources/repository.rb', line 94

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

#snapshot_version_behaviorObject

Return this object’s snapshot_version_behavior



81
# File 'lib/artifactory/resources/repository.rb', line 81

attribute :snapshot_version_behavior, 'non-unique'

#snapshot_version_behavior=(value) ⇒ Object

Set this object’s snapshot_version_behavior



81
# File 'lib/artifactory/resources/repository.rb', line 81

attribute :snapshot_version_behavior, 'non-unique'

#snapshot_version_behavior?Boolean

Determines if the snapshot_version_behavior value exists and is truthy



81
# File 'lib/artifactory/resources/repository.rb', line 81

attribute :snapshot_version_behavior, 'non-unique'

#suppress_pom_consistency_checksObject

Return this object’s suppress_pom_consistency_checks



82
# File 'lib/artifactory/resources/repository.rb', line 82

attribute :suppress_pom_consistency_checks, false

#suppress_pom_consistency_checks=(value) ⇒ Object

Set this object’s suppress_pom_consistency_checks



82
# File 'lib/artifactory/resources/repository.rb', line 82

attribute :suppress_pom_consistency_checks, false

#suppress_pom_consistency_checks?Boolean

Determines if the suppress_pom_consistency_checks value exists and is truthy



82
# File 'lib/artifactory/resources/repository.rb', line 82

attribute :suppress_pom_consistency_checks, false

#upload(local_path, remote_path, properties = {}, headers = {}) ⇒ Resource::Artifact

Upload to a given repository



110
111
112
113
# File 'lib/artifactory/resources/repository.rb', line 110

def upload(local_path, remote_path, properties = {}, headers = {})
  artifact = Resource::Artifact.new(local_path: local_path)
  artifact.upload(key, remote_path, properties, headers)
end

#upload_from_archive(local_path, remote_path, properties = {}) ⇒ Object

Upload an artifact with the given archive. Consult the artifactory documentation for the format of the archive to upload.



133
134
135
136
# File 'lib/artifactory/resources/repository.rb', line 133

def upload_from_archive(local_path, remote_path, properties = {})
  artifact = Resource::Artifact.new(local_path: local_path)
  artifact.upload_from_archive(key, remote_path, properties)
end

#upload_with_checksum(local_path, remote_path, checksum, properties = {}) ⇒ Object

Upload an artifact with the given SHA checksum. Consult the artifactory documentation for the possible responses when the checksums fail to match.



122
123
124
125
# File 'lib/artifactory/resources/repository.rb', line 122

def upload_with_checksum(local_path, remote_path, checksum, properties = {})
  artifact = Resource::Artifact.new(local_path: local_path)
  artifact.upload_with_checksum(key, remote_path, checksum, properties)
end