foreman_scc_manager 1.8.8 → 1.8.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d51eed6c2336237f44aa0fad512060a43f4bc0dae6fd9a93daa2baa555f915a
4
- data.tar.gz: 876ebdd4e76443deec6016c657b44ddcb1e60dcc2c8a81631e5f87cccafcc9b1
3
+ metadata.gz: 18d3ef9cc3c2af2f26b0da68c6abbb88491361ff689ddeb66061dc574f9604b6
4
+ data.tar.gz: f4a1152c05a14eab317d058f551a738c2e2f676d570e1810b747e05192382c3a
5
5
  SHA512:
6
- metadata.gz: ef379e703604fc444d312969f4dd389c952b03dc3f3d5ba98d95989941c9b397b7879bef97d309ae54270f70ffb5b1ef50ee1ba214571800dc82f2ea7d301bd7
7
- data.tar.gz: 70c8ddeef5a5ad620dfb6fe1ed3b2296e56cef24be9fc3b07223bc2978b5fb0f116d996bddea4e0bc50db1accef6a82ed263183d13fad7d23a56a9c15da077fc
6
+ metadata.gz: a5f96e7074f6372e072b99c6a49ec300d151e9f0c9b013b254f70ed1f92011849adbe3c5fa9b2c84658f9919030784ced02116682d5f77ca38b316c17bcb8665
7
+ data.tar.gz: 39d1e30b2ac55968f70fe1653e2f0e32127e5cec6cb3f5072e8c5936980f0df4c53b7fde847c00f0d5f5961d72b8207e43fe2df0d56f77137a38881d47ce2bc4
data/README.md CHANGED
@@ -1,18 +1,26 @@
1
- [![Build Status master](https://travis-ci.org/ATIX-AG/foreman_scc_manager.svg?branch=master)](https://travis-ci.org/ATIX-AG/foreman_scc_manager)
1
+ ![Rubocop](https://github.com/ATIX-AG/foreman_scc_manager/actions/workflows/rubocop.yaml/badge.svg)
2
+ ![Unit Tests](https://github.com/ATIX-AG/foreman_scc_manager/actions/workflows/unit_tests.yaml/badge.svg)
3
+ [![Gem Version](https://badge.fury.io/rb/foreman_scc_manager.svg)](https://badge.fury.io/rb/foreman_scc_manager)
2
4
 
3
- # ForemanSccManager
5
+ # Foreman SCC Manager
4
6
 
5
- Foreman plugin to sync SUSE Customer Center products and repositories into Katello
7
+ Foreman plugin to sync SUSE Customer Center products and repositories into Katello.
6
8
 
7
9
  ## Installation
8
10
 
9
- See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
10
- for how to install Foreman plugins
11
+ This plugin installation is not supported by foreman-installer and has to be installed manually:
12
+
13
+ ```sh
14
+ yum install tfm-rubygem-foreman_scc_manager
15
+
16
+ foreman-installer
17
+ ```
11
18
 
12
19
  ## Compatibility
13
20
 
14
21
  | Foreman Version | Katello Version | Plugin Version |
15
22
  | --------------- | --------------- | -------------- |
23
+ | 2.3 | 3.18 | ~> 1.8.9 |
16
24
  | 2.1 | 3.16 | ~> 1.8.5 |
17
25
  | 2.0 | 3.16 | ~> 1.8.4 |
18
26
  | 1.24 | 3.14 | ~> 1.8.0 |
@@ -26,7 +34,12 @@ for how to install Foreman plugins
26
34
  | 1.15 | 3.4 | ~> 1.1.0 |
27
35
 
28
36
  ## Documentation
29
- The plugin documentation can be found at https://docs.orcharhino.com/sources/management_ui/the_content_menu/suse_subscriptions.html.
37
+
38
+ [Plugin documentation](https://docs.orcharhino.com/or/docs/sources/usage_guides/managing_sles_systems_guide.html#mssg_installing_the_scc_manager_plugin)
39
+
40
+ ## Hammer CLI Extension
41
+
42
+ [Hammer CLI for Foreman SCC Manager](https://github.com/ATIX-AG/hammer-cli-foreman-scc-manager)
30
43
 
31
44
  ## Contributing
32
45
 
@@ -34,7 +47,7 @@ Fork and send a Pull Request. Thanks!
34
47
 
35
48
  ## Copyright
36
49
 
37
- Copyright (c) 2017 ATIX AG - http://www.atix.de
50
+ Copyright (c) 2021 ATIX AG - https://atix.de
38
51
 
39
52
  This program is free software: you can redistribute it and/or modify
40
53
  it under the terms of the GNU General Public License as published by
@@ -48,4 +61,3 @@ GNU General Public License for more details.
48
61
 
49
62
  You should have received a copy of the GNU General Public License
50
63
  along with this program. If not, see <http://www.gnu.org/licenses/>.
51
-
data/Rakefile CHANGED
@@ -35,13 +35,9 @@ end
35
35
 
36
36
  task default: :test
37
37
 
38
- begin
39
- require 'rubocop/rake_task'
40
- RuboCop::RakeTask.new
41
- rescue StandardError => _e
42
- puts 'Rubocop not loaded.'
43
- end
44
-
45
- task :default do
46
- Rake::Task['rubocop'].execute
38
+ class ForemanSccManager::Engine
39
+ def self.root
40
+ File.expand_path('__dir__')
41
+ end
47
42
  end
43
+ import 'lib/tasks/rubocop.rake'
@@ -12,11 +12,22 @@ module Api
12
12
 
13
13
  before_action :find_resource, :only => [:show, :subscribe]
14
14
 
15
- api :GET, '/scc_accounts/:scc_account_id/scc_products/', N_('List all products for scc_account')
15
+ def metadata_subtotal
16
+ if @scc_products.present?
17
+ @scc_products.count
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ api :GET, '/scc_accounts/:scc_account_id/scc_products/', N_('List products for an scc_account')
16
24
  param :scc_account_id, :identifier_dottable, :required => true
25
+ param :subscribed_only, :bool, :required => false, :desc => N_('Show subscribed products only')
17
26
  param_group :search_and_pagination, ::Api::V2::BaseController
27
+
18
28
  def index
19
29
  scope = resource_scope
30
+ scope = scope.where.not(:product_id => nil) if ::Foreman::Cast.to_bool(params[:subscribed_only])
20
31
  scope = scope.where(:organization => params[:organization_id]) if params[:organization_id].present?
21
32
  @scc_products = scope.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
22
33
  end
@@ -47,8 +58,8 @@ module Api
47
58
  private
48
59
 
49
60
  def find_resource
50
- @scc_account = ::SccAccount.find_by!(id: params[:scc_account_id])
51
- @scc_product = @scc_account.scc_products.find_by!(id: params[:id])
61
+ @scc_account = ::SccAccount.find(params[:scc_account_id])
62
+ @scc_product = @scc_account.scc_products.find(params[:id])
52
63
  end
53
64
 
54
65
  def action_permission
@@ -2,7 +2,7 @@ class SccAccountsController < ApplicationController
2
2
  helper_method :scc_filtered_products
3
3
  before_action :find_organization
4
4
  before_action :find_resource, only: %i[show edit update destroy sync bulk_subscribe]
5
- before_action :find_available_gpg_keys, only: %i[new edit]
5
+ before_action :find_available_gpg_keys, only: %i[new edit update create]
6
6
  include Foreman::Controller::AutoCompleteSearch
7
7
 
8
8
  # GET /scc_accounts
@@ -37,7 +37,7 @@ class SccAccountsController < ApplicationController
37
37
  # POST /scc_accounts/test_connection
38
38
  def test_connection
39
39
  @scc_account = SccAccount.new(scc_account_params)
40
- @scc_account.password = SccAccount.find_by!(id: params[:scc_account_id]).password if params[:scc_account_id].present? && scc_account_params[:password].empty?
40
+ @scc_account.password = SccAccount.find(params[:scc_account_id]).password if params[:scc_account_id].present? && scc_account_params[:password].empty?
41
41
  respond_to do |format|
42
42
  if @scc_account.test_connection
43
43
  format.json { render json: nil, status: :ok }
@@ -106,7 +106,7 @@ class SccAccountsController < ApplicationController
106
106
 
107
107
  def find_organization
108
108
  @organization = Organization.current
109
- redirect_to '/select_organization?toState=' + request.path unless @organization
109
+ redirect_to "/select_organization?toState=#{request.path}" unless @organization
110
110
  end
111
111
 
112
112
  # Use callbacks to share common setup or constraints between actions.
@@ -1,21 +1,17 @@
1
1
  module SccManager
2
2
  # adapted from https://github.com/SUSE/connect
3
3
  def self.get_scc_data(base_url, rest_url, login, password)
4
- if SETTINGS[:katello][:cdn_proxy] && SETTINGS[:katello][:cdn_proxy][:host]
5
- proxy_config = SETTINGS[:katello][:cdn_proxy]
6
- uri = URI('')
7
-
8
- uri.scheme = URI.parse(proxy_config[:host]).scheme
9
- uri.host = URI.parse(proxy_config[:host]).host
10
- uri.port = proxy_config[:port].try(:to_s)
11
- uri.user = proxy_config[:user]
4
+ if (proxy_config = ::HttpProxy.default_global_content_proxy)
5
+ uri = URI(proxy_config[:url])
6
+ uri.user = proxy_config[:username]
12
7
  uri.password = proxy_config[:password] if uri.user.present?
13
8
 
14
9
  RestClient.proxy = uri.to_s
15
10
  end
16
11
 
17
12
  url = base_url + rest_url
18
- auth_header = { Authorization: 'Basic ' + Base64.encode64("#{login}:#{password}").chomp,
13
+ credentials = Base64.encode64("#{login}:#{password}").chomp
14
+ auth_header = { Authorization: "Basic #{credentials}",
19
15
  Accept: 'application/vnd.scc.suse.com.v4+json' }
20
16
  results = []
21
17
  loop do
@@ -45,12 +45,7 @@ class SccAccount < ApplicationRecord
45
45
  end
46
46
 
47
47
  def sync_date_is_valid_datetime
48
- errors.add(:sync_date, 'must be a valid datetime') if interval != NEVER &&
49
- sync_date.present? &&
50
- !sync_date.respond_to?(:min) &&
51
- !sync_date.respond_to?(:hour) &&
52
- !sync_date.respond_to?(:wday) &&
53
- !sync_date.respond_to?(:day)
48
+ errors.add(:sync_date, 'must be a valid datetime') if interval != NEVER && sync_date.blank?
54
49
  end
55
50
 
56
51
  def to_s
@@ -104,7 +99,7 @@ class SccAccount < ApplicationRecord
104
99
  end
105
100
 
106
101
  def add_recurring_logic(sync_date, interval)
107
- sd = sync_date
102
+ sd = sync_date.presence || Time.now
108
103
 
109
104
  raise _('Interval cannot be nil') if interval.nil?
110
105
 
@@ -177,7 +172,7 @@ class SccAccount < ApplicationRecord
177
172
  def update_scc_repositories(upstream_repositories)
178
173
  upstream_repo_ids = []
179
174
  # initially invalidate all repositories and validate them during update
180
- invalidated_repos = invalidate_subscription_status(scc_repositories)
175
+ invalidated_repos = invalidate_subscription_status(scc_repositories, save_record: false)
181
176
  # import repositories
182
177
  upstream_repositories.each do |ur|
183
178
  cached_repository = scc_repositories.find_or_initialize_by(scc_id: ur['id'])
@@ -201,7 +196,7 @@ class SccAccount < ApplicationRecord
201
196
  # subscription_valid can be set to nil
202
197
  to_invalidate = invalidated_repos.select { |ir| ir.katello_root_repository_id.present? && !ir.subscription_valid }
203
198
  ::Foreman::Logging.logger('foreman_scc_manager').debug "Invalidating #{to_invalidate.count} expired repositories"
204
- invalidate_subscription_status(to_invalidate, true)
199
+ invalidate_subscription_status(to_invalidate, save_record: true)
205
200
 
206
201
  # delete repositories being removed upstream and that are not subscribed to
207
202
  to_delete = scc_repositories.where.not(scc_id: upstream_repo_ids)
@@ -212,7 +207,7 @@ class SccAccount < ApplicationRecord
212
207
  def update_scc_products(upstream_products)
213
208
  upstream_product_ids = []
214
209
  # initially invalidate all products and validate them during update
215
- invalidated_products = invalidate_subscription_status(scc_products)
210
+ invalidated_products = invalidate_subscription_status(scc_products, save_record: false)
216
211
  # import products
217
212
  upstream_products.each do |up|
218
213
  cached_product = scc_products.find_or_initialize_by(scc_id: up['id'])
@@ -238,7 +233,7 @@ class SccAccount < ApplicationRecord
238
233
  # subscription_valid can be set to nil
239
234
  to_invalidate = invalidated_products.select { |ip| ip.product_id.present? && !ip.subscription_valid }
240
235
  ::Foreman::Logging.logger('foreman_scc_manager').debug "Invalidating #{to_invalidate.count} expired products"
241
- invalidate_subscription_status(to_invalidate, true)
236
+ invalidate_subscription_status(to_invalidate, save_record: true)
242
237
 
243
238
  # delete products being removed upstream and that are not subscribed to
244
239
  to_delete = scc_products.where.not(scc_id: upstream_product_ids).where(product_id: nil)
@@ -271,9 +266,9 @@ class SccAccount < ApplicationRecord
271
266
 
272
267
  # set all products/repos invalid
273
268
  # params: items_to_invalidate: ActiveRecord_(*)
274
- # save_record: store in database or not (default)
269
+ # save_record: store in database or not
275
270
  # return: ActiveRecord elements with invalidated subscription status
276
- def invalidate_subscription_status(items_to_invalidate, save_record = false)
271
+ def invalidate_subscription_status(items_to_invalidate, save_record:)
277
272
  if items_to_invalidate.present?
278
273
  items_to_invalidate.each do |inv|
279
274
  inv.subscription_valid = false
@@ -9,11 +9,11 @@ class SccRepository < ApplicationRecord
9
9
  has_and_belongs_to_many :scc_products
10
10
 
11
11
  def full_url
12
- token.blank? ? url : url + '?' + token
12
+ token.blank? ? url : "#{url}?#{token}"
13
13
  end
14
14
 
15
15
  def uniq_name(scc_product)
16
- scc_product.scc_id.to_s + ' ' + description
16
+ "#{scc_product.scc_id} #{description}"
17
17
  end
18
18
 
19
19
  def pretty_name
data/config/routes.rb CHANGED
@@ -23,7 +23,7 @@ Rails.application.routes.draw do
23
23
  :defaults => { :apiv => 'v2' },
24
24
  :apiv => /v1|v2/,
25
25
  :constraints => ApiConstraints.new(:version => 2, :default => true) do
26
- resources :scc_accounts do
26
+ resources :scc_accounts, except: %i[new edit] do
27
27
  collection do
28
28
  post 'test_connection'
29
29
  get 'auto_complete_search'
@@ -0,0 +1,19 @@
1
+ class AddPermissions < ActiveRecord::Migration[6.0]
2
+ PRODUCT_PERMISSION_NAMES = [
3
+ 'view_scc_products',
4
+ 'subscribe_scc_products'
5
+ ].freeze
6
+
7
+ def up
8
+ Permission.create!(:name => 'test_connection_scc_accounts', :resource_type => 'SccAccount')
9
+ PRODUCT_PERMISSION_NAMES.each do |p|
10
+ Permission.create!(:name => p, :resource_type => SccProduct)
11
+ end
12
+ end
13
+
14
+ def down
15
+ (PRODUCT_PERMISSION_NAMES + ['test_connection_scc_accounts']).each do |p|
16
+ Permission.where(:name => p).destroy_all
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ class AddProductClassToSccProduct < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :scc_products, :product_class, :string
4
+ end
5
+ end
@@ -22,16 +22,18 @@ module ForemanSccManager
22
22
 
23
23
  initializer 'foreman_scc_manager.register_plugin', :before => :finisher_hook do |_app|
24
24
  Foreman::Plugin.register :foreman_scc_manager do
25
- requires_foreman '>= 1.22'
26
- requires_foreman_plugin 'katello', '>= 3.12.0'
25
+ requires_foreman '>= 2.1'
26
+ requires_foreman_plugin 'katello', '>= 3.16.0'
27
+
28
+ precompile_assets 'foreman_scc_manager/scc_accounts.js'
27
29
 
28
30
  apipie_documented_controllers ["#{ForemanSccManager::Engine.root}/app/controllers/api/v2/*.rb"]
29
31
 
30
32
  # Add permissions
31
33
  security_block :foreman_scc_manager do
32
34
  permission :view_scc_accounts,
33
- { :scc_accounts => [:show, :index],
34
- :'api/v2/scc_accounts' => [:show, :index] },
35
+ { :scc_accounts => [:show, :index, :auto_complete_search],
36
+ :'api/v2/scc_accounts' => [:show, :index, :auto_complete_search] },
35
37
  :resource_type => 'SccAccount'
36
38
 
37
39
  permission :use_scc_accounts,
@@ -58,15 +60,33 @@ module ForemanSccManager
58
60
  { :scc_accounts => [:sync],
59
61
  :'api/v2/scc_accounts' => [:sync] },
60
62
  :resource_type => 'SccAccount'
63
+
64
+ permission :test_connection_scc_accounts,
65
+ { :scc_accounts => [:test_connection],
66
+ :'api/v2/scc_accounts' => [:test_connection] },
67
+ :resource_type => 'SccAccount'
68
+
69
+ permission :view_scc_products,
70
+ { :scc_products => [:index, :show],
71
+ :'api/v2/scc_products' => [:index, :show] },
72
+ :resource_type => 'SccProduct'
73
+
74
+ permission :subscribe_scc_products,
75
+ { :scc_products => [:subscribe, :unsubscribe],
76
+ :'api/v2/scc_products' => [:subscribe, :unsibscribe] },
77
+ :resource_type => 'SccProduct'
61
78
  end
62
79
 
63
80
  # Add a new role called 'SccManager' if it doesn't exist
64
81
  role 'SccManager',
65
- %i[view_scc_accounts use_scc_accounts new_scc_accounts edit_scc_accounts delete_scc_accounts sync_scc_accounts],
82
+ %i[view_scc_accounts use_scc_accounts new_scc_accounts edit_scc_accounts
83
+ delete_scc_accounts sync_scc_accounts test_connection_scc_accounts
84
+ view_scc_products subscribe_scc_products],
66
85
  'Role granting permissons to manage SUSE Subscriptions'
67
86
 
68
87
  role 'SccViewer',
69
- %i[view_scc_accounts use_scc_accounts sync_scc_accounts create_products view_products],
88
+ %i[view_scc_accounts use_scc_accounts sync_scc_accounts
89
+ create_products view_products subscribe_scc_products view_scc_products],
70
90
  'Role granting permissons to view and use SUSE Subscriptions'
71
91
 
72
92
  add_all_permissions_to_default_roles
@@ -1,3 +1,3 @@
1
1
  module ForemanSccManager
2
- VERSION = '1.8.8'.freeze
2
+ VERSION = '1.8.13'.freeze
3
3
  end