GithubHelp home page GithubHelp logo

chef / artifactory-client Goto Github PK

View Code? Open in Web Editor NEW
68.0 68.0 49.0 546 KB

A simple, lightweight Ruby client for interacting with the Artifactory API.

License: Apache License 2.0

Ruby 99.83% Shell 0.17%

artifactory-client's Introduction

Chef Infra

Code Climate Build Status Gem Version

Umbrella Project: Chef Infra

Project State: Active

Issues Response Time Maximum: 14 days

Pull Request Response Time Maximum: 14 days

Getting Started

Chef Infra is a configuration management tool designed to bring automation to your entire infrastructure.

Want to try Chef Infra?

For Chef Infra usage, please refer to Learn Chef, our self-paced, entirely free learning platform. Learn Chef also includes module-based training for Chef Infra, as well as Chef Automate, Chef Habitat, and Chef InSpec.

Other useful resources for Chef Infra users:

Reporting Issues

Issues can be reported by using GitHub Issues.

Note that this repository is primarily for reporting issues in the chef-client itself. For reporting issues against other Chef projects, please look up the appropriate repository. If you're unsure where to submit an issue, please ask in the #chef-dev channel in Chef Community Slack.

How We Build & Release Chef

For information on how a contribution goes from PR to released package, see How Chef Infra Is Built

To learn more about our monthly feature releases and yearly major releases, see Chef Infra Release and Support Schedule.

Getting Involved

We'd love to have your help developing Chef Infra. See our Contributing Document for more information on getting started.

License and Copyright

Copyright 2008-2020, Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

artifactory-client's People

Contributors

antoniobeyah avatar bergholdt avatar bodgit avatar chef-ci avatar chef-expeditor[bot] avatar dbell-hubble avatar dependabot-preview[bot] avatar dylanlacey avatar erichelgeson avatar jayashrig158 avatar jgitlin-p21 avatar johnlabarge avatar orgads avatar prototypegoneprod avatar rhass avatar schisamo avatar sethvargo avatar skeshari12 avatar tas50 avatar tduffield avatar vadzay avatar yzl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

artifactory-client's Issues

Manage artifactory config resources

Should we expose functionality for managing resources/objects that are part of the main Artifactory config? Things that come to mind include: repository layouts, property sets and backup schedules.

Alternatively this could just exist as part of the Chef resources we are going to create. It may be easier to do reason about things in an idempotent way in these HWRPs.

allow for searching by sha256 checksum

Describe the Enhancement:

I can search by md5 and sha1 checksums, i would like to be able to search by sha256 checksums

Describe the Need:

sha256 is a supported by modern artifactory, we should be able to search by it

Current Alternative

an md5 or sha1 hash, annoying to use if you don't have it

Can We Help You Implement This?:

yes, pull the simple request

Repository options are not enough

environment

artifactory-client version 2.8.2
Artifactory version 5.3.0
ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux]

describe

Repository's option is defined in https://github.com/chef/artifactory-client/blob/master/lib/artifactory/resources/repository.rb#L68-L86 .
However, There are more repository's option in artifactory official document.
When use undefined option, following error happen.

/usr/lib64/ruby/gems/2.3.0/gems/artifactory-2.8.2/lib/artifactory/resources/base.rb:309:in `block in to_hash': undefined method `repositories' for #<Artifactory::Resource::Repository:0x0000000001fd3f08> (NoMethodError)

If you need more info, please comment in this issue.
Thanks

SSL_CERT errors when trying to talk to a hosted api

OS: Windows
Artifactory: Hosted
Mission: Upload an artifact using the artifactory api

When I try to upload, I get the following stack trace:

C:/bin/ruby21/lib/ruby/2.1.0/net/http.rb:923:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
        from C:/bin/ruby21/lib/ruby/2.1.0/net/http.rb:923:in `block in connect'
        from C:/bin/ruby21/lib/ruby/2.1.0/timeout.rb:76:in `timeout'
        from C:/bin/ruby21/lib/ruby/2.1.0/net/http.rb:923:in `connect'
        from C:/bin/ruby21/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
        from C:/bin/ruby21/lib/ruby/2.1.0/net/http.rb:852:in `start'
        from C:/bin/ruby21/lib/ruby/gems/2.1.0/gems/artifactory-2.3.0/lib/artifactory/client.rb:247:in `request'

The only other time I've seen this error is when trying to use gem with authenticated gem hosts. In that case I had to download cacert.pem and tell gem where to find it. I see that you (helpfully) have an ssl_pem_file property in the global config. I set it like this:

config.ssl_pem_file= File.join(My::Gem.root, 'config/cacert.pem')

Now I get this error:

C:/bin/ruby21/lib/ruby/gems/2.1.0/gems/artifactory-2.3.0/lib/artifactory/client.rb:234:in `initialize': Neither PUB key nor PRIV key: nested asn1 error (OpenSSL::PKey::RSAError)                           

For giggles, I set ssl_verify=false just to see if I had the artifact, urls, and locations set correctly. The file was uploaded like a champ when I did that. I understand that this is a huge security risk, so being satisfied that I've configured everything else correctly, I'm confident that the issue is SSL communication in Ruby on Windows.

I'm hoping you'll be able to tell me something that will help me get past this.

Thanks.

HTTP Error 411: Length Required

Using 2.0.0. Keep getting 411 Length Required. See in the code changes for 2.0.0 that data.size is being passed. Not sure what is going wrong.


require 'artifactory'
include Artifactory::Resource
describe 'test' do

  Artifactory.configure do |config|
    config.endpoint = 'http://artifactory.somewhere/artifactory/'
    config.username = 'admin'
    config.password = 'blahblah'
  end
  it 'should work' do
      artifact = Artifact.new(local_path: '/Users/somebody/Projects/UDEV/apps/app/Cheffile')
      artifact.upload('soco-local', '/app/1-test')
  end
end

Property Searches return empty results when property value contains a plus (+)

Quick example:

irb(main):001:0> require 'artifactory'
=> true
irb(main):002:0>
irb(main):003:0* ARTIFACTORY_ENDPOINT     = 'http://artifactory.chef.co'
=> "http://artifactory.chef.co"
irb(main):004:0> ARTIFACTORY_OMNIBUS_REPO = 'omnibus-current-local'
=> "omnibus-current-local"
irb(main):005:0>
irb(main):006:0* client = Artifactory::Client.new(
irb(main):007:1*   endpoint: ARTIFACTORY_ENDPOINT,
irb(main):008:1* )
=> #<Artifactory::Client:0x007fb648c47a60 @endpoint="http://artifactory.chef.co", @username=nil, @password=nil, @proxy_address=nil, @proxy_password=nil, @proxy_port=nil, @proxy_username=nil, @ssl_pem_file=nil, @ssl_verify=true, @user_agent="Artifactory Ruby Gem 2.2.0", @read_timeout=120>
irb(main):009:0> client.artifact_property_search('repos' => ARTIFACTORY_OMNIBUS_REPO,'omnibus.project' => 'opscode-manage','omnibus.platform' => 'ubuntu', 'omnibus.platform_version' => '10.04', 'omnibus.version' => '1.7.1+20141205090410')
=> []

This should return a single artifact. I believe the issue is the plus (+) is not properly URL encoded to %2B. I can recreate the issue using raw HTTP requests:

➜
curl "http://artifactory.chef.co/api/search/prop?omnibus.project=opscode-manage&omnibus.platform=ubuntu&omnibus.platform_version=10.04&omnibus.version=1.7.1+20141205090410"
{
  "results" : [ ]
}⏎                                                                                                                                                         2.1.2p95 in ~/d/c/o/artifactory-client on master
➜
curl "http://artifactory.chef.co/api/search/prop?omnibus.project=opscode-manage&omnibus.platform=ubuntu&omnibus.platform_version=10.04&omnibus.version=1.7.1%2B20141205090410"
{
  "results" : [ {
    "uri" : "http://artifactory.chef.co/api/storage/omnibus-current-local/com/getchef/opscode-manage/1.7.1+20141205090410/ubuntu/10.04/opscode-manage_1.7.1+20141205090410-1_amd64.deb"
  } ]
}⏎

PermissionTarget fails when updating group-based targets

Version:

2.8.2

Environment:

RHEL7

Scenario:

When attempting to update an existing permissions target with no user in the principal, the gem fails with an exception. I believe it's failing because the user portion of the principal is nil and abbreviate_principal is expecting it. This could cause a variety of issues since principal is not a required field in the PermissionTarget api, but the gem always uses it.

Steps to Reproduce:

Create a permission target with permissions assigned only by group, with no users. Attempt to update the repository list on the permissions target.

Expected Result:

The permissions target should update with the configuration parameters passed in to the request.

Actual Result:

NoMethodError: undefined method map' for nil:NilClass /home/ec2-user/.rvm/gems/ruby-2.4.2/gems/artifactory-2.8.2/lib/artifactory/resources/permission_target.rb:116:in abbreviate_principal'
/home/ec2-user/.rvm/gems/ruby-2.4.2/gems/artifactory-2.8.2/lib/artifactory/resources/permission_target.rb:96:in to_abbreviated' /home/ec2-user/.rvm/gems/ruby-2.4.2/gems/artifactory-2.8.2/lib/artifactory/resources/permission_target.rb:151:in save'
/opt/scratch/src/platform-bootstrap-omnibus/rakelib/bug.rake:10:in block (2 levels) in <top (required)>' /home/ec2-user/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in eval'
/home/ec2-user/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in `

'

Thank you!

Given an endpoint with a path part, version 2.3.1 tries to access an invalid URI during a GAVC search

We use artifactory-client in our CI environment, interacting with Artifactory Pro v3.9.4. We noticed that after artifactory-client 2.3.1 was released, our GAVC searches began to fail with a 404 error. This appears to be a result of the attempt to make all requests relative to the original configured endpoint. Based on my reading of the code and the behavior in a debugger, I think it is broken for any case where the Artifactory endpoint is not at the root. In other words, where the endpoint URI has a path part.

Say we have set Artifactory.endpoint to http://artifacts.example.com:8081/artifactory and execute a GAVC search. In Artifact.gavc_search, it makes a GET request to #{endpoint}/api/search/gavc. It then uses the response to build URLs for the results. The issue is in building the URLs for the results. At artifact.rb:106, the uri from the response is passed to from_url. That uri is in the form #{endpoint}/path/to/artifact. For example, http://artifacts.example.com:8081/artifactory/api/storage/libs-sandbox-local/com/example/test/1.0.0/test-1.0.0.txt.

The issue is in from_url. It takes the entire path part of the URI and asks the client instance to get it. However, the client already has part of the path in its endpoint: /artifactory. It joins its endpoint with the given path at client.rb:304. The end result is that the client attempts to request http://artifacts.example.com:8081/artifactory/artifactory/api/storage/libs-sandbox-local/com/example/test/1.0.0/test-1.0.0.txt, which does not exist, because the path part of the endpoint got doubled.

artifact.download does not follow 302 redirects

Version:

3.0.12

Environment:

Artifactory Cloud Pro X hosted by JFrog
ruby 2.7.0p0 under Linux

Scenario:

Using artifactory client gem to download artifacts from a JFrog Artifactory server. Some artifacts download_uri property points to a URI for which the Artifactory server responds with a 302 redirect. This means the response body is empty, and the download method produces a zero-byte file

Steps to Reproduce:

artifacts = artifactory_client.artifact_usage_search(some_search_criteria)
artifacts.each { |artifact| artifact.download "/tmp" }

Issue seen when using pry:

[8] pry(#<Artifactory::Cleaner::Controller>)> r = artifact.client.get(artifact.download_uri) { |chunk| puts "Got #{chunk.length} bytes of data" }
=> #<Net::HTTPFound 302 Found readbody=true>
[9] pry(#<Artifactory::Cleaner::Controller>)> r.inspect
=> "#<Net::HTTPFound 302 Found readbody=true>"
...
[18] pry(#<Net::HTTPFound>):1> @header
=> {"date"=>["Fri, 29 May 2020 17:36:24 GMT"],
 "transfer-encoding"=>["chunked"],
 "connection"=>["keep-alive"],
 "x-artifactory-id"=>["d9d08d7d33e1d33ef1c12c437ef8007d16529d49"],
 "x-artifactory-node-id"=>["pinnacle21-artifactory-primary-0"],
 "location"=>
  ["https://jfrog-prod-use1-shared-virginia-main.s3.amazonaws.com/aol-pinnacle21/filestore/66/66e5adda6c86317bbd3fa9ebdd2bb1397ff29013?response-content-disposition=attachment%3Bfilename%3D%22cinc-15.11.3-1.el8.x86_64.rpm%22&response-content-type=application%2Fx-rpm&OTHER_PARAMS_MASKED_FOR_SECURITY"],
 "strict-transport-security"=>["max-age=15724800; includeSubDomains"],
 "x-request-id"=>["..."]}

Expected Result:

/tmp has many RPM and other artifact files with the same content they had on the Artifactory server

Actual Result:

/tmp has many zero-byte files with the same filenames as the artifacts to be downloaded, but no data

NoMemoryError: failed to allocate memory on artifact.download()

Clueless...please any ideas?
Whenever I try to download a file larger than 300Mb. I get to following error:

Generated at 2017-01-19 06:54:38 -0500
NoMemoryError: failed to allocate memory
C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/protocol.rb:102:in read' C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http/response.rb:290:in block in read_body_0'
C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http/response.rb:275:in inflater' C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http/response.rb:280:in read_body_0'
C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http/response.rb:201:in read_body' C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http/response.rb:226:in body'
C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http/response.rb:163:in reading_body' C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http.rb:1422:in transport_request'
C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http.rb:1384:in request' C:/Users/theuser/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.5.1/lib/artifactory/client.rb:246:in block in request'
C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/http.rb:853:in start' C:/Users/theuser/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.5.1/lib/artifactory/client.rb:245:in request'
C:/Users/theuser/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.5.1/lib/artifactory/client.rb:102:in get' C:/Users/theuser/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.5.1/lib/artifactory/resources/artifact.rb:493:in block in download'
C:/Users/theuser/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.5.1/lib/artifactory/resources/artifact.rb:492:in open' C:/Users/theuser/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.5.1/lib/artifactory/resources/artifact.rb:492:in download

Thread-safe upload/download

Is there really no thread-safe way to upload an artifact?

I don't see a methods that allow me to upload an artifact to a specific repo on remote.

puts @client.methods
artifact_search
artifact_gavc_search
artifact_property_search
artifact_checksum_search
artifact_versions
artifact_latest_version
artifact_from_hash
repository_all
repository_find
user_all
user_find
# ...

So as a workaround, I can simply find the remote repo by name, and upload to it.

# NOTE: Execute all requests using client object to remain thread-safe
# https://github.com/opscode/artifactory-client#threadsafey
@client = Artifactory::Client.new(
  endpoint: MyGem::Constants::ARTIFACTORY_ENDPOINT ,
  username: @username ,
  password: @password)
...
repo = @client.repository_find("libs-release-local")
repo.upload("mygem-1.2.3.jar", "remote/path/to/store/artifact")

But this has a problem, that means I need to set my uploader account as an admin according to this Artifactory REST API doc:
https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-RepositoryConfiguration

Requires a valid user for a shared remote repository and admin user for anything else. Shared remote repository data is sanitized for security when a non-admin user is used.

Downloading the latest artifact

Hey Guys,

I am currently trying download the latest artifact in our artifactory repo and am having some issues. One method I have tried is calling the Artifact.latest_version method to get the version number and then do a property_search for this version number. I keeping getting a nil response on the latest version which causes the search to not work as well. Another method I tried was doing a search on the artifact name and repo and doing a get last on that. This method returns unexpected artifacts. Am I supposed to be sending an sort option and if so what does that look like. Any help would be greatly appreciated on what the best method for acquiring the latest artifact is.

Search by version
artifactVersion = Artifactory::Resource::Artifact.latest_version(name: 'TestArtifact', group: 'app.group', repos: 'local')
artifact = Artifactory::Resource::Artifact.property_search(name: 'TestArtifact' ,repos: 'local', version: artifactVersion ).first
artifact.download(@target_directory, filename: @file_name)

Search on name
artifact = Artifactory::Resource::Artifact.search(name: 'TestArtifact' ,repos: 'local').last
artifact.download(@target_directory, filename: @file_name)

URI.escape is obsolete warnings

Version:

artifactory 3.0.12

Environment:

Ununtu 20.04 LTS "focal"
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
Bundler version 2.1.4

Scenario:

With a stock install of Ununtu 20.04 LTS and including artifactory in my gemfile, I now see lots of depreciation warnings from the underlying URI library:

/var/lib/gems/2.7.0/gems/artifactory-3.0.12/lib/artifactory/resources/base.rb:246: warning: URI.unescape is obsolete
/var/lib/gems/2.7.0/gems/artifactory-3.0.12/lib/artifactory/resources/base.rb:246: warning: URI.escape is obsolete

This is because URI.escape and URI.unescape have been deprecated for 10 years, but something in this new environment is setting $VERBOSE = true and printing warnings everywhere.

Steps to Reproduce:

  1. Add a runtime dependency on Artifactory: spec.add_runtime_dependency "artifactory"
  2. bundle install
  3. bundle exec whatever

Expected Result:

No warning messages to stderr

Actual Result:

Warning messages like:

/var/lib/gems/2.7.0/gems/artifactory-3.0.12/lib/artifactory/resources/base.rb:246: warning: URI.unescape is obsolete
/var/lib/gems/2.7.0/gems/artifactory-3.0.12/lib/artifactory/resources/base.rb:246: warning: URI.escape is obsolete

upload() on repository resource is not uploading correct artifact in matching size

I have a .jar file which is like 47MB (don't ask why it's so big). We are using the upload() under lib/artifactory/resources/repository.rb to upload. We found the uploaded artifact only has ~30 bytes or something in size. We did some debugging and found there could be an issue on how this file is passed.

I'm not sure why file has to pass in the hash { file: file} :

  def upload(path_or_io, path, properties = {}, headers = {})
      file = if path_or_io.is_a?(File)
               path_or_io
             else
               File.new(File.expand_path(path_or_io))
             end

      matrix   = to_matrix_properties(properties)
      endpoint = File.join("#{url_safe(key)}#{matrix}", path)

      response = client.put(endpoint, { file: file }, headers)
      Resource::Artifact.from_hash(response)
    end

But changing it to this will work:

    def upload(path_or_io, path, properties = {}, headers = {})
      file = if path_or_io.is_a?(File)
               path_or_io
             else
               File.new(File.expand_path(path_or_io))
             end

      matrix   = to_matrix_properties(properties)
      endpoint = File.join("#{url_safe(key)}#{matrix}", path)

      headers = { "Content-Length" => "#{File.size(file)}" }
      response = client.put(endpoint, file, headers)
      Resource::Artifact.from_hash(response)
    end

Since I'm not entirely sure this is by design to pass in a hash or not. I cannot file this as a bug, but this definitely need to be addressed.

If we look further at lib/artifactory/client.rb , the passed hash will be setting as a form data which obviously don't work in this case by simply giving a File object.

      # Setup PATCH/POST/PUT
      if [:patch, :post, :put].include?(verb)
        if data.respond_to?(:read)
          request.body_stream = data
        elsif data.is_a?(Hash)
          request.form_data = data
        else
          request.body = data
        end
      end

I could have this fix, but I prefer to discuss whether this is by design or not.

Thanks

proxy=': unsupported proxy https://host:8443/artifactory (ArgumentError)

Artifactory has a self signed cert (which may be the issue) but the error is an argument error. I do not set a proxy in the code nor have a proxy in my env. (on a Mac, ruby via rvm 1.9.1)

This does work: curl -uuser -v https://host:8443/artifactory/api/system -k

$ cat Gemfile
source 'https://rubygems.org'
gem 'artifactory', '~> 1.0'
$ bundle update
Fetching gem metadata from https://rubygems.org/...
Resolving dependencies...
Using httpclient (2.3.4.1)
Using i18n (0.6.9)
Using artifactory (1.1.0)
Using bundler (1.5.2)
Your bundle is updated!
$ cat test2.rb 
require 'artifactory'
include Artifactory::Resource

Artifactory.configure do |config|
  config.endpoint = 'https://host:8443/artifactory'
  config.username = 'user'
  config.password = '***'
end

puts System.info
$ bundle exec ruby test2.rb 
/Users/***/source/artifact/vendor/bundle/ruby/1.9.1/gems/httpclient-2.3.4.1/lib/httpclient.rb:454:in `proxy=': unsupported proxy https://host:8443/artifactory (ArgumentError)
    from /Users/***/source/artifact/vendor/bundle/ruby/1.9.1/gems/httpclient-2.3.4.1/lib/httpclient.rb:397:in `initialize'
    from /Users/***/source/artifact/vendor/bundle/ruby/1.9.1/gems/artifactory-1.1.0/lib/artifactory/client.rb:135:in `new'
    from /Users/***/source/artifact/vendor/bundle/ruby/1.9.1/gems/artifactory-1.1.0/lib/artifactory/client.rb:135:in `agent'
    from /Users/***/source/artifact/vendor/bundle/ruby/1.9.1/gems/artifactory-1.1.0/lib/artifactory/client.rb:178:in `request'
    from /Users/***/source/artifact/vendor/bundle/ruby/1.9.1/gems/artifactory-1.1.0/lib/artifactory/client.rb:75:in `get'
    from /Users/***/source/artifact/vendor/bundle/ruby/1.9.1/gems/artifactory-1.1.0/lib/artifactory/resources/system.rb:21:in `info'
    from test2.rb:16:in `<main>'

Using: Artifactory Pro Power Pack 3.1.1.1 (rev. 30080)

unexpressed dependency on pathname module

The artifactory module depends on the pathname module, but this dependency is not expressed.

$ # Load the artifactory module:
$ ruby <<EOF
> require 'artifactory'
> puts Artifactory.class
> EOF
/var/lib/gems/1.9.1/gems/artifactory-1.1.0/lib/artifactory.rb:36:in `root': uninitialized constant Module::Pathname (NameError)
    from /var/lib/gems/1.9.1/gems/artifactory-1.1.0/lib/artifactory.rb:75:in `<top (required)>'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
    from -:1:in `<main>'
$ # This time, load the pathname module before loading the artifactory one:
$ ruby <<EOF
> require 'pathname'
> require 'artifactory'
> puts Artifactory.class
> EOF
Module
$ gem list artifactory

*** LOCAL GEMS ***

artifactory (1.1.0)
$ ruby --version
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

undefined local variable or method `params'

I am attempting a search for an artifact with the following code:

require 'artifactory'

include Artifactory::Resource

Artifactory.configure do |config|
  config.endpoint = 'https://192.168.211.10/artifactory'
  config.username = 'myuser'
  config.password = 'mypassword'
end

a = Artifact.search(name: 'my-gem-1.0.0.5.gem', repos: 'my-repo')

The code above results in the following error:

~/.gem/ruby/gems/artifactory-2.2.0/lib/artifactory/client.rb:250:in `block in request': undefined local variable or method `params' for #<Artifactory::Client:0x0000000104d6d8> (NameError)

Line 250 of client.rb currently contains the following:

request(verb, redirect, params, headers)

I believe the line should actually be as follows:

request(verb, redirect, data, headers)

In short, the params argument should be replaced with data.

Support for Virtual Repositories lost

Describe the problem

A virtual repo cannot be configured properly because there is no attribute on the Resource::Repository class that supports setting repositories.

Software Version

Ruby: 2.5.1p57
Artifactory Gem: 3.0.0

Stacktrace

Failure/Error:
  virtual_repo = Artifactory::Resource::Repository.new(
    key:          'cots-test-gems',
    rclass:       'virtual',
    package_type: 'gems',
    repositories: ['cots-test-gems-local', 'cots-test-gems-remote']
  ).save

NoMethodError:
  undefined method `repositories' for #<Artifactory::Resource::Repository:0x000055b9a4e21f90>
# ./vendor/bundle/ruby/2.5.0/gems/artifactory-3.0.0/lib/artifactory/resources/base.rb:309:in `block in to_hash'
# ./vendor/bundle/ruby/2.5.0/gems/artifactory-3.0.0/lib/artifactory/resources/base.rb:307:in `each'
# ./vendor/bundle/ruby/2.5.0/gems/artifactory-3.0.0/lib/artifactory/resources/base.rb:307:in `inject'
# ./vendor/bundle/ruby/2.5.0/gems/artifactory-3.0.0/lib/artifactory/resources/base.rb:307:in `to_hash'
# ./vendor/bundle/ruby/2.5.0/gems/artifactory-3.0.0/lib/artifactory/resources/base.rb:324:in `to_json'
# ./vendor/bundle/ruby/2.5.0/gems/artifactory-3.0.0/lib/artifactory/resources/repository.rb:102:in `save'
# ./spec/artifacts/rubygems_spec.rb:24:in `<top (required)>'

Possible Solution

Make sure that there is parity between the Resource::Respository class attributes and the properties required by the support JSON schemas:

    def content_type
      case rclass.to_s.downcase
      when "local"
        "application/vnd.org.jfrog.artifactory.repositories.LocalRepositoryConfiguration+json"
      when "remote"
        "application/vnd.org.jfrog.artifactory.repositories.RemoteRepositoryConfiguration+json"
      when "virtual"
        "application/vnd.org.jfrog.artifactory.repositories.VirtualRepositoryConfiguration+json"
      else
        raise "Unknown Repository type `#{rclass}'!"
      end
    end

HTTPErrors are more cryptic than we intend

We are trying to provide user-friendly error messages for HTTPError in errors.rb, but they are being lost, e.g.

require 'artifactory'

Artifactory.configure do |config|
  config.endpoint = 'http://localhost:8081/artifactory/nosuchendpoint' 
  config.username = 'admin' 
  config.password = 'password' 
end

gives this error

sealam01:artifactory-client yvonnelam$ bundle exec ruby thing2.rb
/Users/yvonnelam/src/artifactory-client/lib/artifactory/client.rb:341:in `error': Artifactory::Error::HTTPError
    from /Users/yvonnelam/src/artifactory-client/lib/artifactory/client.rb:227:in `block in request'
    from /Users/yvonnelam/.rbenv/versions/1.9.3-p448/lib/ruby/1.9.1/net/http.rb:746:in `start'
    from /Users/yvonnelam/src/artifactory-client/lib/artifactory/client.rb:217:in `request'
    from /Users/yvonnelam/src/artifactory-client/lib/artifactory/client.rb:80:in `get'
    from /Users/yvonnelam/src/artifactory-client/lib/artifactory/resources/system.rb:68:in `configuration'
    from thing2.rb:9:in `<main>'

Oddly, we do get the user-friendly errors for ConnectionError, e.g.

require 'artifactory'

Artifactory.configure do |config|
  config.endpoint = 'http://nowhere:8081/artifactory' 
  config.username = 'admin' 
  config.password = 'password' 
end

does produce output with a nice error message as well as the exception:

sealam01:artifactory-client yvonnelam$ bundle exec ruby thing1.rb 
/Users/yvonnelam/src/artifactory-client/lib/artifactory/client.rb:231:in `rescue in request': The Artifactory server at `http://nowhere:8081/artifactory' is not currently accepting connections. Please ensure that the server is running an that your authentication information is correct. (Artifactory::Error::ConnectionError)
    from /Users/yvonnelam/src/artifactory-client/lib/artifactory/client.rb:163:in `request'
    from /Users/yvonnelam/src/artifactory-client/lib/artifactory/client.rb:80:in `get'
    from /Users/yvonnelam/src/artifactory-client/lib/artifactory/resources/system.rb:68:in `configuration'
    from thing1.rb:9:in `<main>'

Basic auth credentials get re-passed too often

Version:

3.0.15

Environment:

JFrog Cloud, access is from a CentOS 7 using Ruby 2.4.3p205, also replicated with 2.6.3p62 on MacOS 10.14.6

Scenario:

In the newest version of JFrog Cloud, artifact downloads often result in a 302 redirect. The redirect is handled by recursing to the redirect location, but the username/password are passed as basic auth credentials every time. When the redirect to AWS S3 is made, amazon interprets those basic auth credentials as s3 authentication and rejects the request with HTTP 400.

This does not happen when using api keys, since S3 does not intercept the custom header. This also doesn't happen with api requests, since those don't seem to trigger redirects.

Steps to Reproduce:

Request an artifact from the newest version of hosted Artifactory with username/password authentication

Expected Result:

An HTTP 200 and successful download

Actual Result:

An HTTP 400 and no payload

URI with space causes artifact error

URI::InvalidURIError: bad URI(is not URI?): http://artifactory.8081/artifactory/api/storage/bin-release-local/com/prod/IP/2016.02/PROD IP-2016.02.msi

version 2.3.2

The download_uri from artifactory is not encoded so the client request fails.

Local fix artifactory/resources/artifact.rb
`
client.get('/api/search/artifact', params)['results'].map do |artifact|

--- from_url(artifact['uri'], client: client)

+++ from_url(URI.encode(artifact['uri']), client: client)

end
`

Get artifact latest version error

When i use this gem to get the latest version of an artiface. An error appear. Do i have something wrong in my code? The code and error are shown below.

code

latest_version = Artifact.latest_version(name: 'artifact.apk')
puts latest_version.inspect

error

/home/user/.rvm/gems/ruby-2.3.0/gems/artifactory-2.5.0/lib/artifactory/client.rb:374:in `error': The Artifactory server responded with an HTTP Error 400: `The groupId and artifactId cannot be empty' (Artifactory::Error::HTTPError)
    from /home/user/.rvm/gems/ruby-2.3.0/gems/artifactory-2.5.0/lib/artifactory/client.rb:255:in `block in request'
    from /home/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:853:in `start'
    from /home/user/.rvm/gems/ruby-2.3.0/gems/artifactory-2.5.0/lib/artifactory/client.rb:245:in `request'
    from /home/user/.rvm/gems/ruby-2.3.0/gems/artifactory-2.5.0/lib/artifactory/client.rb:102:in `get'
    from /home/user/.rvm/gems/ruby-2.3.0/gems/artifactory-2.5.0/lib/artifactory/resources/artifact.rb:355:in `latest_version'
    from artifactory_test.rb:12:in `<main>'

Besides, the artifact object's last_modified, local_path, created values are nil but i can get these values from api using curl directly.

The Artifactory server version 4.13.0.

Support for new repository packaging type attribute for Artifactory 4.x

With the introduction of Artifactory 4, it is now a requirement that each repository has exactly 1 packaging type, and it cannot be changed after the repository is created with that type.

The default package type is 'generic', which is unsuitable for some (read most) scenarios.

The new element in the rest api (taken from the link below) is:
  - "packageType": "maven" | "gradle" | "ivy" | "sbt" | "nuget" | "gems" | "npm" | "bower" | "debian" | "pypi" | "docker" | "vagrant" | "gitlfs" | "yum" | "generic"

See:
https://www.jfrog.com/confluence/display/RTF/Configuring+Repositories
https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON#RepositoryConfigurationJSON-application/vnd.org.jfrog.artifactory.repositories.LocalRepositoryConfiguration+json

Specs fail on windows

Running the test suite fails on windows in test that check on file path, on windows path does not start with '/' but include drive letter.

If windows user should contribute they must be able to pass test locally before pushing.

λ bundle exec rake travis:ci
C:/Ruby22/bin/ruby.exe -I'C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib';'C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-support-3.4.1/lib' 'C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/exe/rspec' --pattern 'spec/**{,/*/**}/*_spec.rb' --tag ~integration
Run options:
  include {:focus=>true}
  exclude {:integration=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 23668
....................FFFFFFF.................................................................................FFFFFF...................................................................................

Failures:

  1) Artifactory::Resource::Artifact#upload when the md5 is available PUTs the file with the checksum headers set
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/local/path")
              got: ("D:/local/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./spec/unit/resources/artifact_spec.rb:62:in `block (4 levels) in <module:Artifactory>'

  2) Artifactory::Resource::Artifact#upload when matrix properties are given converts "+" to "%2B"
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/local/path")
              got: ("D:/local/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./spec/unit/resources/artifact_spec.rb:96:in `block (4 levels) in <module:Artifactory>'

  3) Artifactory::Resource::Artifact#upload when matrix properties are given converts the hash into matrix properties
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/local/path")
              got: ("D:/local/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./spec/unit/resources/artifact_spec.rb:79:in `block (4 levels) in <module:Artifactory>'

  4) Artifactory::Resource::Artifact#upload when matrix properties are given converts spaces to "+" characters
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/local/path")
              got: ("D:/local/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./spec/unit/resources/artifact_spec.rb:88:in `block (4 levels) in <module:Artifactory>'

  5) Artifactory::Resource::Artifact#upload when the sha1 is available PUTs the file with the checksum headers set
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/local/path")
              got: ("D:/local/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./spec/unit/resources/artifact_spec.rb:71:in `block (4 levels) in <module:Artifactory>'

  6) Artifactory::Resource::Artifact#upload when custom headers are given passes the headers to the client
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/local/path")
              got: ("D:/local/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./spec/unit/resources/artifact_spec.rb:107:in `block (4 levels) in <module:Artifactory>'

  7) Artifactory::Resource::Artifact#upload when the artifact is a file path PUTs the file at the path to the server
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/local/path")
              got: ("D:/local/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./spec/unit/resources/artifact_spec.rb:53:in `block (4 levels) in <module:Artifactory>'

  8) Artifactory::Resource::Repository#upload when custom headers are given passes the headers to the client
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/fake/path")
              got: ("D:/fake/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./lib/artifactory/resources/repository.rb:116:in `upload'
     # ./spec/unit/resources/repository_spec.rb:184:in `block (4 levels) in <module:Artifactory>'

  9) Artifactory::Resource::Repository#upload when matrix properties are given converts the hash into matrix properties
     Failure/Error: file     = File.new(File.expand_path(local_path))

       #<File (class)> received :new with unexpected arguments
         expected: ("/fake/path")
              got: ("D:/fake/path")
        Please stub a default value first if message might be received with other args as well.
     # ./lib/artifactory/resources/artifact.rb:533:in `upload'
     # ./lib/artifactory/resources/repository.rb:116:in `upload'
     # ./spec/unit/resources/repository_spec.rb:156:in `block (4 levels) in <module:Artifactory>'

  10) Artifactory::Resource::Repository#upload when matrix properties are given converts "+" to "%2B"
      Failure/Error: file     = File.new(File.expand_path(local_path))

        #<File (class)> received :new with unexpected arguments
          expected: ("/fake/path")
               got: ("D:/fake/path")
         Please stub a default value first if message might be received with other args as well.
      # ./lib/artifactory/resources/artifact.rb:533:in `upload'
      # ./lib/artifactory/resources/repository.rb:116:in `upload'
      # ./spec/unit/resources/repository_spec.rb:173:in `block (4 levels) in <module:Artifactory>'

  11) Artifactory::Resource::Repository#upload when matrix properties are given converts spaces to "+" characters
      Failure/Error: file     = File.new(File.expand_path(local_path))

        #<File (class)> received :new with unexpected arguments
          expected: ("/fake/path")
               got: ("D:/fake/path")
         Please stub a default value first if message might be received with other args as well.
      # ./lib/artifactory/resources/artifact.rb:533:in `upload'
      # ./lib/artifactory/resources/repository.rb:116:in `upload'
      # ./spec/unit/resources/repository_spec.rb:165:in `block (4 levels) in <module:Artifactory>'

  12) Artifactory::Resource::Repository#upload when matrix properties are given converts the hash into matrix properties
      Failure/Error: file     = File.new(File.expand_path(local_path))

        #<File (class)> received :new with unexpected arguments
          expected: ("/fake/path")
               got: ("D:/fake/path")
         Please stub a default value first if message might be received with other args as well.
      # ./lib/artifactory/resources/artifact.rb:533:in `upload'
      # ./lib/artifactory/resources/repository.rb:116:in `upload'
      # ./spec/unit/resources/repository_spec.rb:147:in `block (4 levels) in <module:Artifactory>'

  13) Artifactory::Resource::Repository#upload when the artifact is a file path PUTs the file at the path to the server
      Failure/Error: file     = File.new(File.expand_path(local_path))

        #<File (class)> received :new with unexpected arguments
          expected: ("/fake/path")
               got: ("D:/fake/path")
         Please stub a default value first if message might be received with other args as well.
      # ./lib/artifactory/resources/artifact.rb:533:in `upload'
      # ./lib/artifactory/resources/repository.rb:116:in `upload'
      # ./spec/unit/resources/repository_spec.rb:139:in `block (4 levels) in <module:Artifactory>'

Finished in 1.82 seconds (files took 1.26 seconds to load)
197 examples, 13 failures

Failed examples:

rspec ./spec/unit/resources/artifact_spec.rb:60 # Artifactory::Resource::Artifact#upload when the md5 is available PUTs the file with the checksum headers set
rspec ./spec/unit/resources/artifact_spec.rb:93 # Artifactory::Resource::Artifact#upload when matrix properties are given converts "+" to "%2B"
rspec ./spec/unit/resources/artifact_spec.rb:76 # Artifactory::Resource::Artifact#upload when matrix properties are given converts the hash into matrix properties
rspec ./spec/unit/resources/artifact_spec.rb:85 # Artifactory::Resource::Artifact#upload when matrix properties are given converts spaces to "+" characters
rspec ./spec/unit/resources/artifact_spec.rb:69 # Artifactory::Resource::Artifact#upload when the sha1 is available PUTs the file with the checksum headers set
rspec ./spec/unit/resources/artifact_spec.rb:103 # Artifactory::Resource::Artifact#upload when custom headers are given passes the headers to the client
rspec ./spec/unit/resources/artifact_spec.rb:51 # Artifactory::Resource::Artifact#upload when the artifact is a file path PUTs the file at the path to the server
rspec ./spec/unit/resources/repository_spec.rb:180 # Artifactory::Resource::Repository#upload when custom headers are given passes the headers to the client
rspec ./spec/unit/resources/repository_spec.rb:153 # Artifactory::Resource::Repository#upload when matrix properties are given converts the hash into matrix properties
rspec ./spec/unit/resources/repository_spec.rb:170 # Artifactory::Resource::Repository#upload when matrix properties are given converts "+" to "%2B"
rspec ./spec/unit/resources/repository_spec.rb:162 # Artifactory::Resource::Repository#upload when matrix properties are given converts spaces to "+" characters
rspec ./spec/unit/resources/repository_spec.rb:144 # Artifactory::Resource::Repository#upload when matrix properties are given converts the hash into matrix properties
rspec ./spec/unit/resources/repository_spec.rb:136 # Artifactory::Resource::Repository#upload when the artifact is a file path PUTs the file at the path to the server

Randomized with seed 23668

C:/Ruby22/bin/ruby.exe -I'C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/lib';'C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-support-3.4.1/lib' 'C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.4.4/exe/rspec' --pattern 'spec/**{,/*/**}/*_spec.rb' --tag ~integration failed

Build statuses

Build that has been promoted will have a key 'statuses' containing an array of status hashes.

curl -u user:api_key https://artifactory.../api/build/my-build/123

   ...
    } ],
    "statuses" : [ {
      "status" : "promoted",
      "comment" : "",
      "repository" : "my-repo",
      "timestamp" : "2017-02-20T12:33:59.570+0100",
      "user" : "me",
      "ciUser" : "me",
      "timestampDate" : 1487590439570
    } ]
  },
  "uri" : "http://artifactory.../api/build/my-build/123"
}

We will need this attribute on Artifactory::Resource::Build to be able to implement a build cleanup procedure.

I have not been able to find it documented by JFrog, so build info status might be available on more endpoints as well.
https://github.com/JFrogDev/build-info/blob/master/README.md#build-info-json-format

Using ssl_verify=true within a Chef run?

I am attempting to configure the client to run within a Chef run using an internal CA issued certificate. To do this I must set the environment variable SSL_CERT_FILE but I can't seem to get this environment variable to be present during a Chef run. While I know its not really an issue that is unique to this particular gem I was hoping since the Chef team supports this gem you would have some insight into using it within a Chef run.

The specific error I receive is the following:
OpenSSL::SSL::SSLError ---------------------- SSL_connect returned=1 errno=0 state=error: certificate verify failed

Which is resolved by flipping ssl_verify=false

This is the first time I have come across needing an environment variable in a Chef run and its proved to be very difficult. I have tried exporting it in /etc/profile and /etc/bash.bashrc - I've tried a Ruby ENV variable within the run (wrapped in a ruby block also) - I've tried both the "magic_shell" and "bash" cookbooks to set it but nothing seems to set the environment variable. I have also placed the cert in question in "/etc/chef/trusted_certs/" which I thought was akin to placing a cert in the "ssl" directory in a normal Ruby installation, making Chef's embedded Ruby aware of this cert during the run. I've also added the cert to the OS's store. I am running Ubuntu 14.04.

Any help is greatly appreciated.

Publish v3.0.5 gem

Any chance v3.0.5 of this gem can be published? I have a gem that depends on the unreleased changes. Thanks.

TypeError thrown on build.save (artifactory server 5.2.1)

After upgrading artifactory server to 5.2.1, build creation using Resource::Build.save results in a TypeError

/opt/chefdk/embedded/lib/ruby/2.1.0/json/common.rb:155:in `initialize': no implicit conversion of nil into String (TypeError)
	from /opt/chefdk/embedded/lib/ruby/2.1.0/json/common.rb:155:in `new'
	from /opt/chefdk/embedded/lib/ruby/2.1.0/json/common.rb:155:in `parse'
	from /media/drive1/jenkins/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.8.1/lib/artifactory/client.rb:372:in `success'
	from /media/drive1/jenkins/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.8.1/lib/artifactory/client.rb:272:in `block in request'
	from /opt/chefdk/embedded/lib/ruby/2.1.0/net/http.rb:853:in `start'
	from /media/drive1/jenkins/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.8.1/lib/artifactory/client.rb:256:in `request'
	from /media/drive1/jenkins/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.8.1/lib/artifactory/client.rb:136:in `put'
	from /media/drive1/jenkins/.chefdk/gem/ruby/2.1.0/gems/artifactory-2.8.1/lib/artifactory/resources/build.rb:208:in `save'

The server operation succeeded, but returns an HTTP 204 (no content) now and an empty response. Code in Client.success() needs to check for this HTTP code instead of blindly passing nil content to the json parser.

Delete artifact returns false on successful delete

Calling artifact.delete, where artifact is a valid artifact returned from a search function, always returns false, even if the artifact was successfully deleted.
Doing the same with CURL shows that on successful deletion we get back 204 (no content) as the success code, compared to getting back 404 (not found) if the artifact does not exist.
Does delete consider 204 to be a success code?

Upload with checksum not working

Hi
I am trying to use the method "upload_with_checksum" but i get this error

C:\Ruby21-x64\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/ruby_workspace/samigit/PA/Utilities/bin/test_upload_artifactory.rb
C:/Ruby21-x64/lib/ruby/2.1.0/net/http/generic_request.rb:189:in `send_request_with_body_stream': Content-Length not given and Transfer-Encoding is not `chunked' (ArgumentError)
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http/generic_request.rb:132:in `exec'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1412:in `block in transport_request'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1411:in `catch'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1411:in `transport_request'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:1384:in `request'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:218:in `block in request'
    from C:/Ruby21-x64/lib/ruby/2.1.0/net/http.rb:853:in `start'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:217:in `request'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/client.rb:109:in `put'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/resources/artifact.rb:447:in `upload'
    from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/artifactory-1.2.0/lib/artifactory/resources/artifact.rb:467:in `upload_with_checksum'
    from C:/ruby_workspace/samigit/PA/Utilities/bin/test_upload_artifactory.rb:23:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

Process finished with exit code 1

-------------The code is below------------

require 'artifactory'
require 'digest'
include Artifactory::Resource

ARTIFACTORY_ENDPOINT="http://<BAMS_DOMAIN>/artifactory"
LOCAL_REPOSITORY_KEY='xxx.xxx.local'

Artifactory.configure do |config|
  config.endpoint = ARTIFACTORY_ENDPOINT
  config.username = 'user'
  config.password = 'password'
end


@client = Artifactory::Client.new(endpoint: Artifactory.endpoint, username: Artifactory.username, password: Artifactory.password)
path_to_file='../Testdata/BAMS/TestFileForBams'
repository_path='Testing/AbezarTest/'
file_checksum = Digest::SHA1.file(path_to_file).hexdigest
file_name=File.basename(path_to_file)
artifact=Artifact.new(client: @client)
artifact.upload_with_checksum(LOCAL_REPOSITORY_KEY, path_to_file, repository_path+"#{file_name}",file_checksum)

Any idea what i am doing wrong here???

Need support for remote and virtual Repository creation

Need support for remote and virtual Repository creation

irb(main):142:0> repo = Repository.new(key: 'russ-repo2', rclass: 'remote', url: 'http://host:port/some-repo')
=> #<Repository blacked_out: nil, description: nil, checksum_policy_type: nil, excludes_pattern: nil, handle_releases: nil, handle_snapshots: nil, includes_pattern: nil, key: "russ-repo2", max_unique_snapshots: nil, notes: nil, property_sets: nil, repo_layout_ref: nil, rclass: "remote", snapshot_version_behavior: nil, suppress_pom_consistency_checks: nil, url: "http://host:port/some-repo">
irb(main):143:0> repo.save
NoMethodError: undefined method `url' for #<Artifactory::Resource::Repository:0x007fda8aaa7aa0>
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/resources/base.rb:300:in `block in to_hash'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/resources/base.rb:298:in `each'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/resources/base.rb:298:in `inject'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/resources/base.rb:298:in `to_hash'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/resources/base.rb:315:in `to_json'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/resources/repository.rb:98:in `save'
    from (irb):143
    from /Users/rroy/.rbenv/versions/1.9.3-p547/bin/irb:12:in `<main>'
irb(main):144:0>

Or ... if you try to create a remote repo w/o the req'd url:

irb(main):145:0> repo = Repository.new(key: 'russ-repo2', rclass: 'remote')
=> #<Repository blacked_out: nil, description: nil, checksum_policy_type: nil, excludes_pattern: nil, handle_releases: nil, handle_snapshots: nil, includes_pattern: nil, key: "russ-repo2", max_unique_snapshots: nil, notes: nil, property_sets: nil, repo_layout_ref: nil, rclass: "remote", snapshot_version_behavior: nil, suppress_pom_consistency_checks: nil>
irb(main):146:0> repo.save
Artifactory::Error::HTTPError: The Artifactory server responded with an HTTP Error 400: `No URL defined for remote repository
'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/client.rb:374:in `error'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/client.rb:255:in `block in request'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/1.9.1/net/http.rb:746:in `start'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/client.rb:245:in `request'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/client.rb:131:in `put'
    from /Users/rroy/.rbenv/versions/1.9.3-p547/lib/ruby/gems/1.9.1/gems/artifactory-2.3.0/lib/artifactory/resources/repository.rb:98:in `save'
    from (irb):146
    from /Users/rroy/.rbenv/versions/1.9.3-p547/bin/irb:12:in `<main>'
irb(main):147:0>

Downloading of JSON artifact writes Ruby Hash to file

To replicate;

  • Ensure there is a JSON file in your Artifactory
  • Create Artifactory::Client instance
  • Get Artifactory::Resource::Artifact by searching for JSON artifact
  • Call 'download' method to save to File System

The saved file will contain the string representation of a Ruby Hash rather than the document held in Artifactory.

This can be explained by the following code in Artifactory:Client;

def success(response)
  if (response.content_type || '').include?('json')
    JSON.parse(response.body)
  else
    response.body
  end
end

Using Artifactory.search() goes through the list of objects with GET -> slow performance

Hi,

I'm trying to use the Artifactory.search() here like this:

Artifactory::Resource::Artifact.search(name: 'project*.gz', repos: 'project-artifacts-local')

And it does produce the list of objects yes - but it also goes through every object one by one with GET (at least by looking Artifactory's access.log) - which means it takes about a minute to run this (with current amount of artifacts on search scope).

Is this intentional?

Artifactory Query Language Support?

Hi,

I have been digging through the codes to find if there is support for Artifactory Query Language but would like to ask the question here before I dig too far.

https://www.jfrog.com/article/artifactory-query-language-aql/

We used a couple of methods (artifact_search, artifact_latest_version, artifact_versions, etc) in the artifact.rb to find what we need in Artifactory. One specific case is to find the version of an artifact but it seems that the methods search all the available versions inside maven-metadata.xml (see below for an example). It seems that if the version doesn't get append to the "versions" tag (see below) after a build, the search results will only return the available versions inside the versions tag, which might not have all the versions. After writing this paragraph, I was able to verify that this is the case.

https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactLatestVersionSearchBasedonLayout

https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactVersionSearch

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>one.two.three.four</groupId>
  <artifactId>someArtifactId</artifactId>
  <versioning>
    <latest>1.0.0.16</latest>
    <release>1.0.0.16</release>
    <versions>
      <version>1.0.0.2</version>
      <version>1.0.0.6</version>
      <version>1.0.0.11</version>
      <version>1.0.0.14</version>
      <version>1.0.0.15</version>
      <version>1.0.0.16</version>
    </versions>
    <lastUpdated>20170724102939</lastUpdated>
  </versioning>
</metadata>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.