pdc 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +23 -0
- data/.travis.yml +3 -4
- data/Gemfile +0 -1
- data/docs/sphinx_deployment.mk +1 -1
- data/examples/local_pdc_dev.rb +10 -1
- data/examples/logger.rb +7 -14
- data/examples/pdc_global_component_contact.rb +18 -0
- data/examples/pdc_release_rpm_mapping.rb +2 -2
- data/examples/pdc_resource_tests.rb +3 -3
- data/examples/pdc_test_cache.rb +1 -1
- data/examples/prod_failures.rb +1 -1
- data/examples/prod_pdc.rb +10 -1
- data/examples/test_no_ssl_verification.rb +1 -1
- data/examples/url.rb +4 -4
- data/lib/pdc.rb +1 -1
- data/lib/pdc/base.rb +1 -0
- data/lib/pdc/config.rb +0 -7
- data/lib/pdc/http/request/token_fetcher.rb +1 -1
- data/lib/pdc/http/response/pagination.rb +0 -2
- data/lib/pdc/resource.rb +1 -0
- data/lib/pdc/resource/associations.rb +39 -0
- data/lib/pdc/resource/associations/association.rb +21 -0
- data/lib/pdc/resource/associations/builder.rb +46 -0
- data/lib/pdc/resource/associations/has_many.rb +26 -0
- data/lib/pdc/resource/attributes.rb +13 -4
- data/lib/pdc/resource/identity.rb +1 -1
- data/lib/pdc/resource/relation.rb +5 -0
- data/lib/pdc/resource/relation/pagination.rb +4 -4
- data/lib/pdc/resource/rest_api.rb +1 -1
- data/lib/pdc/resource/scopes.rb +1 -1
- data/lib/pdc/v1.rb +4 -0
- data/lib/pdc/v1/global_component_contact.rb +5 -0
- data/lib/pdc/v1/multi_destination.rb +8 -0
- data/lib/pdc/v1/release.rb +3 -1
- data/lib/pdc/v1/release_variant.rb +6 -1
- data/lib/pdc/v1/released_file.rb +10 -0
- data/lib/pdc/v1/variant_cpe.rb +7 -0
- data/lib/pdc/version.rb +1 -1
- data/pdc.gemspec +8 -10
- data/spec/fixtures/vcr/_page_count_returns_total_count.yml +6 -6
- data/spec/fixtures/vcr/behaves_like_an_array.yml +141 -0
- data/spec/fixtures/vcr/brew_can_be_nil.yml +23 -14
- data/spec/fixtures/vcr/brew_may_be_present.yml +4 -2
- data/spec/fixtures/vcr/caches_multiple_response.yml +42 -36
- data/spec/fixtures/vcr/caches_response_with_a_query.yml +16 -16
- data/spec/fixtures/vcr/caches_response_with_multiple_query.yml +16 -16
- data/spec/fixtures/vcr/caches_response_without_query.yml +14 -14
- data/spec/fixtures/vcr/can_find_global_contact_by_component_name.yml +47 -0
- data/spec/fixtures/vcr/can_get_release_by_multi_product_version.yml +9 -9
- data/spec/fixtures/vcr/can_iterate_using_each.yml +8 -8
- data/spec/fixtures/vcr/content_delivery_repos_must_return_a_record.yml +2 -2
- data/spec/fixtures/vcr/cpe_returns_number.yml +44 -0
- data/spec/fixtures/vcr/cpe_works_with_where.yml +85 -0
- data/spec/fixtures/vcr/destination_returns_count.yml +44 -0
- data/spec/fixtures/vcr/destination_works_with_where.yml +44 -0
- data/spec/fixtures/vcr/fetches_variants_of_a_release.yml +20 -20
- data/spec/fixtures/vcr/find_on_has_many_association.yml +48 -0
- data/spec/fixtures/vcr/get_released_files_by_file_primary_key.yml +44 -0
- data/spec/fixtures/vcr/get_released_files_by_release_id.yml +44 -0
- data/spec/fixtures/vcr/has_many_association.yml +48 -0
- data/spec/fixtures/vcr/has_serveral_cdn_content_delivery_repos.yml +1 -1
- data/spec/fixtures/vcr/must_has_compose.yml +45 -1
- data/spec/fixtures/vcr/must_has_version__attributes.yml +2 -2
- data/spec/fixtures/vcr/must_return_number_of_resources.yml +62 -14
- data/spec/fixtures/vcr/preserves_the_filters.yml +2 -2
- data/spec/fixtures/vcr/returns_a_contact_email.yml +47 -0
- data/spec/fixtures/vcr/returns_a_gloabl_contact_id.yml +47 -0
- data/spec/fixtures/vcr/returns_a_mail_name.yml +47 -0
- data/spec/fixtures/vcr/returns_contact_for_component.yml +47 -0
- data/spec/fixtures/vcr/returns_contact_role.yml +48 -0
- data/spec/fixtures/vcr/returns_cpe.yml +88 -0
- data/spec/fixtures/vcr/returns_number_of_released_files.yml +48 -0
- data/spec/fixtures/vcr/returns_release_file_by_retrieve.yml +44 -0
- data/spec/fixtures/vcr/returns_resources_on_that_page.yml +2 -2
- data/spec/fixtures/vcr/returns_the_total_count_and_not_items_in_page.yml +6 -6
- data/spec/fixtures/vcr/returns_url_of_a_release.yml +2 -2
- data/spec/fixtures/vcr/returns_url_of_a_release_variant.yml +7 -7
- data/spec/fixtures/vcr/scopes_on_associations.yml +48 -0
- data/spec/fixtures/vcr/should_not_be_in_the_list_of_attributes.yml +4 -4
- data/spec/fixtures/vcr/works_with_where.yml +45 -1
- data/spec/pdc/resource/associations_spec.rb +111 -0
- data/spec/pdc/resource/attributes_spec.rb +30 -20
- data/spec/pdc/resource/cache_spec.rb +1 -1
- data/spec/pdc/resource/identity_spec.rb +10 -10
- data/spec/pdc/resource/path_spec.rb +1 -1
- data/spec/pdc/resource/relation_spec.rb +1 -1
- data/spec/pdc/v1/content_delivery_repo_spec.rb +6 -6
- data/spec/pdc/v1/global_component_contact_spec.rb +64 -0
- data/spec/pdc/v1/multi_destination_sepc.rb +27 -0
- data/spec/pdc/v1/release_spec.rb +10 -10
- data/spec/pdc/v1/release_variant_spec.rb +8 -0
- data/spec/pdc/v1/released_file_spec.rb +37 -0
- data/spec/pdc/v1/variant_cpe_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -4
- data/spec/support/fixtures.rb +29 -2
- metadata +77 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f51f89eae34983035f4768fee0475cb2bed9a2b
|
4
|
+
data.tar.gz: b304391d32258708648f2d623cbc630fef9ff424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f50d8c5d916bf243a1726602870730e52dc30495356b8b69295284bec9e45383cfe45441a6ac361a91252ff50710d55e26df691060bb6c51aa19838ec05b720
|
7
|
+
data.tar.gz: ecbfd3ac9df4b19f266c317ad52a0175a8813df97e93eb5440ce656c5a92dd0827ea2bd54a46cbf1707d85f3672241d0bd851e4850311a077e9b90debc86274d
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
AllCops:
|
2
2
|
DisplayCopNames: true
|
3
3
|
DisplayStyleGuide: true
|
4
|
+
Exclude:
|
5
|
+
- bin/console
|
4
6
|
|
5
7
|
Style/Documentation:
|
6
8
|
Enabled: false
|
@@ -9,12 +11,33 @@ Style/ClassAndModuleChildren:
|
|
9
11
|
Enabled: false
|
10
12
|
EnforcedStyle: compact
|
11
13
|
|
14
|
+
Style/MethodMissing:
|
15
|
+
Exclude:
|
16
|
+
- lib/pdc/resource/per_thread_registry.rb
|
17
|
+
|
12
18
|
Metrics/LineLength:
|
13
19
|
Max: 100
|
20
|
+
Exclude:
|
21
|
+
- spec/**/*.rb
|
22
|
+
- examples/**/*.rb
|
14
23
|
|
15
24
|
Metrics/MethodLength:
|
16
25
|
Max: 25
|
17
26
|
|
18
27
|
Metrics/AbcSize:
|
19
28
|
Max: 25
|
29
|
+
Exclude:
|
30
|
+
- lib/pdc/config.rb
|
31
|
+
|
32
|
+
Metrics/BlockLength:
|
33
|
+
Max: 100
|
34
|
+
Exclude:
|
35
|
+
- spec/pdc/**/*.rb
|
36
|
+
- examples/**/*.rb
|
37
|
+
|
38
|
+
Naming/PredicateName:
|
39
|
+
Enabled: false
|
20
40
|
|
41
|
+
Metrics/ModuleLength:
|
42
|
+
Exclude:
|
43
|
+
- lib/pdc/config.rb
|
data/.travis.yml
CHANGED
@@ -15,14 +15,13 @@ script:
|
|
15
15
|
- bundle exec rake test
|
16
16
|
- >
|
17
17
|
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
|
18
|
-
bundle exec
|
18
|
+
bundle exec rubocop
|
19
19
|
fi
|
20
|
-
|
21
20
|
after_success:
|
22
21
|
- >
|
23
22
|
[ "$TRAVIS_BRANCH" = "master" ] &&
|
24
|
-
[ "$TRAVIS_PULL_REQUEST" = "false" ]
|
25
|
-
|
23
|
+
[ "$TRAVIS_PULL_REQUEST" = "false" ]
|
24
|
+
make -C docs/ setup_gh_pages gen_deploy
|
26
25
|
env:
|
27
26
|
global:
|
28
27
|
PRONTO_PULL_REQUEST_ID=${TRAVIS_PULL_REQUEST}
|
data/Gemfile
CHANGED
data/docs/sphinx_deployment.mk
CHANGED
@@ -62,7 +62,7 @@ endif
|
|
62
62
|
#if REPO_URL_GITHUB was NOT defined by travis-ci
|
63
63
|
ifndef REPO_URL_GITHUB
|
64
64
|
# Configure your right github project repo
|
65
|
-
|
65
|
+
REPO_URL_GITHUB = https://github.com/product-definition-center/pdc-ruby-gem.git
|
66
66
|
endif
|
67
67
|
|
68
68
|
## end deployment configuration, don't edit anything below this line ##
|
data/examples/local_pdc_dev.rb
CHANGED
@@ -10,6 +10,15 @@ def main
|
|
10
10
|
|
11
11
|
releases = PDC::V1::Release.all!.to_a
|
12
12
|
ap releases
|
13
|
+
|
14
|
+
released_files = PDC::V1::ReleasedFile.all!.to_a
|
15
|
+
ap released_files
|
16
|
+
|
17
|
+
destinations = PDC::V1::MultiDestination.all!.to_a
|
18
|
+
ap destinations
|
19
|
+
|
20
|
+
cpes = PDC::V1::VariantCpe.all!.to_a
|
21
|
+
ap cpes
|
13
22
|
end
|
14
23
|
|
15
|
-
main if
|
24
|
+
main if $PROGRAM_NAME == __FILE__
|
data/examples/logger.rb
CHANGED
@@ -5,20 +5,15 @@ require 'ap'
|
|
5
5
|
class FakeLogger
|
6
6
|
attr_accessor :level
|
7
7
|
|
8
|
-
def debug(*args)
|
9
|
-
end
|
8
|
+
def debug(*args) end
|
10
9
|
|
11
|
-
def info(*args)
|
12
|
-
end
|
10
|
+
def info(*args) end
|
13
11
|
|
14
|
-
def warn(*args)
|
15
|
-
end
|
12
|
+
def warn(*args) end
|
16
13
|
|
17
|
-
def fatal(*args)
|
18
|
-
end
|
14
|
+
def fatal(*args) end
|
19
15
|
|
20
|
-
def error(*args)
|
21
|
-
end
|
16
|
+
def error(*args) end
|
22
17
|
end
|
23
18
|
|
24
19
|
# PDC.logger = FakeLogger.new
|
@@ -39,11 +34,9 @@ path = 'a_non_existent_file'
|
|
39
34
|
|
40
35
|
begin
|
41
36
|
File.foreach(path) do |line|
|
42
|
-
unless line =~ /^(\w+) = (.*)$/
|
43
|
-
logger.error("Line in wrong format: #{line.chomp}")
|
44
|
-
end
|
37
|
+
logger.error("Line in wrong format: #{line.chomp}") unless line =~ /^(\w+) = (.*)$/
|
45
38
|
end
|
46
|
-
rescue => err
|
39
|
+
rescue StandardError => err
|
47
40
|
logger.fatal('Caught exception; exiting')
|
48
41
|
logger.fatal(err)
|
49
42
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require './lib/pdc'
|
4
|
+
|
5
|
+
def main
|
6
|
+
PDC.configure do |config|
|
7
|
+
config.site = 'https://pdc.engineering.redhat.com'
|
8
|
+
config.log_level = :debug
|
9
|
+
config.disable_caching = true
|
10
|
+
end
|
11
|
+
|
12
|
+
comp_contact = PDC::V1::GlobalComponentContact.where(
|
13
|
+
component: 'vlgothic-fonts'
|
14
|
+
).find_one!
|
15
|
+
puts comp_contact.contact
|
16
|
+
end
|
17
|
+
|
18
|
+
main if $PROGRAM_NAME == __FILE__
|
@@ -10,9 +10,9 @@ def main
|
|
10
10
|
end
|
11
11
|
|
12
12
|
mapping = PDC::V1::ReleaseRpmMapping.where(
|
13
|
-
release_id: '
|
13
|
+
release_id: 'rhceph-2.1@rhel-7', package: 'ceph'
|
14
14
|
).first
|
15
15
|
puts mapping.mapping
|
16
16
|
end
|
17
17
|
|
18
|
-
main if
|
18
|
+
main if $PROGRAM_NAME == __FILE__
|
@@ -5,7 +5,7 @@ WebMock.disable! # this uses real server
|
|
5
5
|
|
6
6
|
#### service config ####
|
7
7
|
def token
|
8
|
-
script_path = File.expand_path(
|
8
|
+
script_path = File.expand_path(__dir__)
|
9
9
|
token_path = File.join(script_path, '.token', 'pdc.prod')
|
10
10
|
File.read(token_path).chomp.tap { |x| puts "Using token :#{x}" }
|
11
11
|
rescue Errno::ENOENT => e
|
@@ -23,7 +23,7 @@ server = {
|
|
23
23
|
|
24
24
|
prod: {
|
25
25
|
site: 'https://pdc.engineering.redhat.com',
|
26
|
-
token: ->
|
26
|
+
token: -> { token } # read token only if needed
|
27
27
|
}
|
28
28
|
}
|
29
29
|
|
@@ -198,7 +198,7 @@ end
|
|
198
198
|
describe PDC::V1::ReleaseRpmMapping do
|
199
199
|
let(:mapping) do
|
200
200
|
PDC::V1::ReleaseRpmMapping.where(
|
201
|
-
release_id: '
|
201
|
+
release_id: 'rhceph-2.1@rhel-7',
|
202
202
|
package: 'ceph'
|
203
203
|
).first
|
204
204
|
end
|
data/examples/pdc_test_cache.rb
CHANGED
data/examples/prod_failures.rb
CHANGED
data/examples/prod_pdc.rb
CHANGED
@@ -9,6 +9,15 @@ def main
|
|
9
9
|
|
10
10
|
releases = PDC::V1::Release.all!.to_a
|
11
11
|
ap releases
|
12
|
+
|
13
|
+
released_files = PDC::V1::ReleasedFile.all!.to_a
|
14
|
+
ap released_files
|
15
|
+
|
16
|
+
destinations = PDC::V1::MultiDestination.all!.to_a
|
17
|
+
ap destinations
|
18
|
+
|
19
|
+
cpes = PDC::V1::VariantCpe.all!.to_a
|
20
|
+
ap cpes
|
12
21
|
end
|
13
22
|
|
14
|
-
main if
|
23
|
+
main if $PROGRAM_NAME == __FILE__
|
data/examples/url.rb
CHANGED
@@ -7,11 +7,11 @@ PDC.configure do |config|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def main
|
10
|
-
|
11
|
-
puts "release url : #{
|
12
|
-
|
10
|
+
rhel71 = PDC::V1::Release.find('rhel-7.1')
|
11
|
+
puts "release url : #{rhel71.url}"
|
12
|
+
rhel71.variants.all.each do |v|
|
13
13
|
puts "release variant url : #{v.url}"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
main if
|
17
|
+
main if $PROGRAM_NAME == __FILE__
|
data/lib/pdc.rb
CHANGED
data/lib/pdc/base.rb
CHANGED
data/lib/pdc/config.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'faraday-http-cache'
|
2
2
|
require 'pdc/http/request/token_fetcher'
|
3
3
|
|
4
|
-
# rubocop:disable ModuleLength
|
5
4
|
module PDC
|
6
5
|
# This class is the main access point for all PDC::Resource instances.
|
7
6
|
#
|
@@ -23,17 +22,13 @@ module PDC
|
|
23
22
|
Config = Struct.new(
|
24
23
|
:site,
|
25
24
|
:api_root,
|
26
|
-
|
27
25
|
:ssl_verify_mode,
|
28
|
-
|
29
26
|
:requires_token,
|
30
27
|
:token_obtain_path,
|
31
28
|
:token,
|
32
|
-
|
33
29
|
:log_level,
|
34
30
|
:enable_logging,
|
35
31
|
:logger,
|
36
|
-
|
37
32
|
:cache_store,
|
38
33
|
:disable_caching
|
39
34
|
) do
|
@@ -76,7 +71,6 @@ module PDC
|
|
76
71
|
def config=(new_config)
|
77
72
|
@config = new_config
|
78
73
|
apply_config
|
79
|
-
@config
|
80
74
|
end
|
81
75
|
|
82
76
|
def token_url
|
@@ -113,7 +107,6 @@ module PDC
|
|
113
107
|
end
|
114
108
|
|
115
109
|
# resets and returns the +Faraday+ +connection+ object
|
116
|
-
# rubocop:disable AbcSize
|
117
110
|
def reset_base_connection
|
118
111
|
faraday_config = {
|
119
112
|
url: api_url,
|
@@ -13,10 +13,8 @@ module PDC::Response
|
|
13
13
|
|
14
14
|
metadata[PDC::Resource::PAGINATION] = {
|
15
15
|
resource_count: metadata.delete(:count),
|
16
|
-
|
17
16
|
# TODO: decide if this is okay to discard the
|
18
17
|
# schema://host:port/ of the next and previous
|
19
|
-
|
20
18
|
next_page: request_uri(metadata.delete(:next)),
|
21
19
|
previous_page: request_uri(metadata.delete(:previous))
|
22
20
|
}
|
data/lib/pdc/resource.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'pdc/resource/associations/has_many'
|
2
|
+
require 'pdc/resource/associations/association'
|
3
|
+
require 'pdc/resource/associations/builder'
|
4
|
+
|
5
|
+
module PDC::Resource
|
6
|
+
module Associations
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_attribute :associations
|
11
|
+
self.associations = {}.freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def has_many(name, options = {})
|
16
|
+
create_association(name, HasMany, options)
|
17
|
+
|
18
|
+
define_method "#{name.to_s.singularize}_ids=" do |ids|
|
19
|
+
attributes[name] = []
|
20
|
+
ids.reject(&:blank?).each { |id| association(name).build(id: id) }
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method "#{name.to_s.singularize}_ids" do
|
24
|
+
association(name).map(&:id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def reflect_on_association(name)
|
29
|
+
associations[name] || associations[name.to_s.pluralize.to_sym]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def create_association(name, type, options)
|
35
|
+
self.associations = associations.merge(name => Builder.new(self, name, type, options))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'pdc/resource/relation'
|
2
|
+
|
3
|
+
module PDC::Resource
|
4
|
+
module Associations
|
5
|
+
class Association < Relation
|
6
|
+
attr_reader :parent, :name
|
7
|
+
|
8
|
+
def initialize(klass, parent, name, options = {})
|
9
|
+
super(klass, options)
|
10
|
+
@parent = parent
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def foreign_key
|
17
|
+
(@options[:foreign_key] || "#{parent.class.model_name.element}_id").to_sym
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'active_support/dependencies'
|
2
|
+
|
3
|
+
module PDC::Resource
|
4
|
+
module Associations
|
5
|
+
class Builder
|
6
|
+
def initialize(parent_class, name, type, options = {})
|
7
|
+
@parent_class = parent_class
|
8
|
+
@name = name
|
9
|
+
@type = type
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def build(parent)
|
14
|
+
@type.new(klass, parent, @name, @options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def klass
|
18
|
+
@klass ||= custom_class || compute_class(@name)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def custom_class
|
24
|
+
@options[:class_name].constantize if @options[:class_name]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Compute class if no custom class name provided.
|
28
|
+
# Referencing the codes from rails in following link:
|
29
|
+
# https://github.com/rails/rails/blob/70ac072976c8cc6f013f0df3777e54ccae3f4f8c/activerecord/lib/active_record/inheritance.rb#L132-L150
|
30
|
+
def compute_class(type_name)
|
31
|
+
parent_name = @parent_class.to_s
|
32
|
+
type_name = type_name.to_s.classify
|
33
|
+
|
34
|
+
candidates = []
|
35
|
+
parent_name.scan(/::|$/) { candidates.unshift "#{$`}::#{type_name}" }
|
36
|
+
candidates << type_name
|
37
|
+
|
38
|
+
candidates.each do |candidate|
|
39
|
+
constant = ActiveSupport::Dependencies.safe_constantize(candidate)
|
40
|
+
return constant if candidate == constant.to_s
|
41
|
+
end
|
42
|
+
raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|