foreman_scc_manager 1.6.3 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/Rakefile +1 -1
- data/app/controllers/api/v2/scc_accounts_controller.rb +159 -0
- data/app/controllers/api/v2/scc_products_controller.rb +64 -0
- data/app/models/scc_account.rb +2 -1
- data/app/models/scc_product.rb +1 -0
- data/app/views/api/v2/scc_accounts/base.json.rabl +5 -0
- data/app/views/api/v2/scc_accounts/index.json.rabl +4 -0
- data/app/views/api/v2/scc_accounts/main.json.rabl +5 -0
- data/app/views/api/v2/scc_accounts/show.json.rabl +4 -0
- data/app/views/api/v2/scc_products/base.json.rabl +5 -0
- data/app/views/api/v2/scc_products/index.json.rabl +4 -0
- data/app/views/api/v2/scc_products/main.json.rabl +5 -0
- data/app/views/api/v2/scc_products/show.json.rabl +5 -0
- data/config/routes.rb +30 -1
- data/lib/foreman_scc_manager/engine.rb +28 -9
- data/lib/foreman_scc_manager/version.rb +1 -1
- data/lib/tasks/rubocop.rake +0 -1
- data/locale/action_names.rb +5 -61
- data/locale/de/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/de/foreman_scc_manager.po +139 -210
- data/locale/en/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/en/foreman_scc_manager.po +129 -152
- data/locale/foreman_scc_manager.pot +120 -212
- data/test/controllers/api/v2/scc_accounts_test.rb +302 -0
- data/test/controllers/api/v2/scc_products_test.rb +40 -0
- data/test/features/sync_test.rb +3 -6
- data/test/{features → fixtures/files}/data_products_page1.json +0 -0
- data/test/{features → fixtures/files}/data_products_page2.json +0 -0
- data/test/fixtures/files/data_repositories.json +502 -0
- data/test/{features → fixtures/files}/data_subscriptions.json +0 -0
- data/test/models/scc_account_test.rb +4 -4
- data/test/models/scc_product_test.rb +2 -2
- data/test/test_plugin_helper.rb +2 -0
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1049862eb94d3a0e5da9add1afcf83da6a7edf3e8e315f126c3ec531f3b8d3fc
|
4
|
+
data.tar.gz: aae14c2ae2305b52281b4c270dcec231b01bfe3745fc4b66b0da084d26b57a15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87c896f8ad3c8e279e068ebe14d6a7a7c1648d94ae4c677500232208f6d8f181d67e4120d4cd1cd8aa3bfed1961851f49cda1e786cd2a7bbf11a20d604bdd030
|
7
|
+
data.tar.gz: 7cf6d36616da6866fb1f641e2f28b927bf789467c7bea6c6adecef0dc1bf4a841c603b79fac309cb3626b9ad2846eae16cdf8a7ac79f4569d47ea4e5c9bb1fb8
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
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)
|
2
|
+
|
1
3
|
# ForemanSccManager
|
2
4
|
|
3
5
|
Foreman plugin to sync SUSE Customer Center products and repositories into Katello
|
@@ -11,6 +13,7 @@ for how to install Foreman plugins
|
|
11
13
|
|
12
14
|
| Foreman Version | Katello Version | Plugin Version |
|
13
15
|
| --------------- | --------------- | -------------- |
|
16
|
+
| 1.22 | 3.12 | ~> 1.7.0 |
|
14
17
|
| 1.21 | 3.10 | ~> 1.6.0 |
|
15
18
|
| 1.20 | 3.9 | ~> 1.6.0 |
|
16
19
|
| 1.19 | 3.8 | ~> 1.5.1 |
|
data/Rakefile
CHANGED
@@ -0,0 +1,159 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
class SccAccountsController < ::Api::V2::BaseController
|
4
|
+
include Api::Version2
|
5
|
+
include Foreman::Controller::AutoCompleteSearch
|
6
|
+
|
7
|
+
resource_description do
|
8
|
+
resource_id 'scc_accounts'
|
9
|
+
api_version 'v2'
|
10
|
+
api_base_url '/api/v2'
|
11
|
+
end
|
12
|
+
|
13
|
+
before_action :find_resource, :only => [:show, :update, :destroy, :sync, :bulk_subscribe]
|
14
|
+
|
15
|
+
api :GET, '/scc_accounts/', N_('List all scc_accounts')
|
16
|
+
param :organization_id, :identifier, :required => true
|
17
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
18
|
+
def index
|
19
|
+
scope = resource_scope
|
20
|
+
scope = scope.where(:organization => params[:organization_id]) if params[:organization_id].present?
|
21
|
+
@scc_accounts = scope.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
22
|
+
end
|
23
|
+
|
24
|
+
api :GET, '/scc_accounts/:id/', N_('Show scc_account')
|
25
|
+
param :id, :identifier_dottable, :required => true
|
26
|
+
param :organization_id, :identifier, :required => true
|
27
|
+
def show; end
|
28
|
+
|
29
|
+
def_param_group :scc_account do
|
30
|
+
param :scc_account, Hash, :required => true, :action_aware => true do
|
31
|
+
param :organization_id, :identifier, :required => true
|
32
|
+
param :name, String, :required => true, :desc => N_('Name of the scc_account')
|
33
|
+
param :login, String, :required => true, :desc => N_('Login id of scc_account')
|
34
|
+
param :password, String, :required => true, :desc => N_('Password of scc_account')
|
35
|
+
param :base_url, String, :required => false, :desc => N_('URL of SUSE for scc_account')
|
36
|
+
param :interval, ['never', 'daily', 'weekly', 'monthy'], :desc => N_('Interval for syncing scc_account')
|
37
|
+
param :sync_date, String, :desc => N_('Last Sync time of scc_account')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
api :POST, '/scc_accounts/', N_('Create an scc_account')
|
42
|
+
param_group :scc_account, :as => :create
|
43
|
+
def create
|
44
|
+
@scc_account = resource_class.new(scc_account_params)
|
45
|
+
process_response @scc_account.save_with_logic!
|
46
|
+
end
|
47
|
+
|
48
|
+
api :PUT, '/scc_accounts/:id', N_('Update scc_account')
|
49
|
+
param :id, :identifier_dottable, :required => true
|
50
|
+
param_group :scc_account
|
51
|
+
def update
|
52
|
+
process_response @scc_account.update(scc_account_params)
|
53
|
+
end
|
54
|
+
|
55
|
+
api :DELETE, '/scc_accounts/:id', N_('Delete scc_account')
|
56
|
+
param :id, :identifier_dottable, :required => true
|
57
|
+
def destroy
|
58
|
+
process_response @scc_account.destroy
|
59
|
+
end
|
60
|
+
|
61
|
+
api :POST, '/scc_accounts/test_connection', N_('Test connection for scc_account')
|
62
|
+
api :PUT, '/scc_accounts/:id/test_connection', N_('Test connection for scc_account')
|
63
|
+
param :id, :identifier_dottable, :required => false
|
64
|
+
param :login, String, :required => false, :desc => N_('Login id of scc_account')
|
65
|
+
param :password, String, :required => false, :desc => N_('Password of scc_account')
|
66
|
+
param :base_url, String, :required => false, :desc => N_('URL of SUSE for scc_account')
|
67
|
+
def test_connection
|
68
|
+
if params[:id].present?
|
69
|
+
find_resource
|
70
|
+
begin
|
71
|
+
local_scc_account_params = scc_account_params
|
72
|
+
rescue ActionController::ParameterMissing
|
73
|
+
local_scc_account_params = {}
|
74
|
+
end
|
75
|
+
@scc_account.login = local_scc_account_params[:login] unless local_scc_account_params[:login].empty?
|
76
|
+
@scc_account.password = local_scc_account_params[:password] unless local_scc_account_params[:password].empty?
|
77
|
+
else
|
78
|
+
@scc_account = resource_class.new(scc_account_params)
|
79
|
+
end
|
80
|
+
respond_to do |format|
|
81
|
+
if @scc_account.test_connection
|
82
|
+
format.json { render json: 'Success'.to_json, status: :ok }
|
83
|
+
else
|
84
|
+
format.json { render json: 'Failed'.to_json, status: :not_found }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
api :PUT, '/scc_accounts/:id/sync', N_('Sync scc_account')
|
90
|
+
param :id, :identifier_dottable, :required => true
|
91
|
+
def sync
|
92
|
+
sync_task = ForemanTasks.async_task(::Actions::SccManager::Sync, @scc_account)
|
93
|
+
synced = @scc_account.update! sync_task: sync_task
|
94
|
+
respond_to do |format|
|
95
|
+
format.json { render json: sync_task.to_json } if synced
|
96
|
+
end
|
97
|
+
rescue ::Foreman::Exception => e
|
98
|
+
render json: { error: ('Failed to add task to queue: %s' % e).to_s }, status: :unprocessable_entity
|
99
|
+
rescue ForemanTasks::Lock::LockConflict => e
|
100
|
+
render json: { error: ('Lock on SCC account already taken: %s' % e).to_s }, status: :unprocessable_entity
|
101
|
+
end
|
102
|
+
|
103
|
+
api :PUT, '/scc_accounts/:id/bulk_subscribe/', N_('Bulk subscription of scc_products for scc_account')
|
104
|
+
param :id, :identifier_dottable, :required => true
|
105
|
+
param :scc_subscribe_product_ids, Array
|
106
|
+
def bulk_subscribe
|
107
|
+
scc_products_to_subscribe = @scc_account.scc_products.where(:id => params[:scc_subscribe_product_ids])
|
108
|
+
respond_to do |format|
|
109
|
+
if scc_products_to_subscribe.count > 0
|
110
|
+
subscribe_task = ForemanTasks.async_task(::Actions::BulkAction,
|
111
|
+
::Actions::SccManager::SubscribeProduct,
|
112
|
+
scc_products_to_subscribe)
|
113
|
+
format.json { render json: subscribe_task.to_json, status: :ok }
|
114
|
+
else
|
115
|
+
format.json { render json: 'No Product selected'.to_json, status: :expectation_failed }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
rescue ::Foreman::Exception => e
|
119
|
+
render json: { error: ('Failed to add task to queue: %s' % e).to_s }, status: :unprocessable_entity
|
120
|
+
rescue ForemanTasks::Lock::LockConflict => e
|
121
|
+
render json: { error: ('Lock on SCC account already taken: %s' % e).to_s }, status: :unprocessable_entity
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def scc_account_params
|
127
|
+
params[:scc_account].delete(:password) if params[:scc_account][:password].blank?
|
128
|
+
params.require(:scc_account).permit(
|
129
|
+
:name,
|
130
|
+
:login,
|
131
|
+
:password,
|
132
|
+
:base_url,
|
133
|
+
:interval,
|
134
|
+
:sync_date,
|
135
|
+
:organization_id
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
def find_resource
|
140
|
+
@scc_account = resource_class.find(params[:id])
|
141
|
+
end
|
142
|
+
|
143
|
+
def resource_class
|
144
|
+
::SccAccount
|
145
|
+
end
|
146
|
+
|
147
|
+
def action_permission
|
148
|
+
case params[:action]
|
149
|
+
when 'sync', 'test_connection'
|
150
|
+
:sync
|
151
|
+
when 'bulk_subscribe'
|
152
|
+
:bulk_subscribe
|
153
|
+
else
|
154
|
+
super
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Api
|
2
|
+
module V2
|
3
|
+
class SccProductsController < ::Api::V2::BaseController
|
4
|
+
include Api::Version2
|
5
|
+
include Foreman::Controller::AutoCompleteSearch
|
6
|
+
|
7
|
+
resource_description do
|
8
|
+
resource_id 'scc_products'
|
9
|
+
api_version 'v2'
|
10
|
+
api_base_url '/api/v2'
|
11
|
+
end
|
12
|
+
|
13
|
+
before_action :find_resource, :only => [:show, :subscribe]
|
14
|
+
|
15
|
+
api :GET, '/scc_accounts/:scc_account_id/scc_products/', N_('List all products for scc_account')
|
16
|
+
param :scc_account_id, :identifier_dottable, :required => true
|
17
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
18
|
+
def index
|
19
|
+
scope = resource_scope
|
20
|
+
scope = scope.where(:organization => params[:organization_id]) if params[:organization_id].present?
|
21
|
+
@scc_products = scope.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
22
|
+
end
|
23
|
+
|
24
|
+
api :GET, '/scc_accounts/:scc_account_id/scc_products/:id/', N_('Show an scc_account product')
|
25
|
+
param :id, :identifier_dottable, :required => true
|
26
|
+
param :scc_account_id, :identifier_dottable, :required => true
|
27
|
+
def show; end
|
28
|
+
|
29
|
+
api :PUT, '/scc_accounts/:scc_account_id/scc_products/:id/subscribe/', N_('Subscribe product')
|
30
|
+
param :id, :identifier_dottable, :required => true
|
31
|
+
param :scc_account_id, :identifier_dottable, :required => true
|
32
|
+
def subscribe
|
33
|
+
subcribe_task = ForemanTasks.async_task(::Actions::SccManager::SubscribeProduct, @scc_product) if @scc_product
|
34
|
+
respond_to do |format|
|
35
|
+
if subcribe_task
|
36
|
+
format.json { render json: subcribe_task.to_json, status: :ok }
|
37
|
+
else
|
38
|
+
format.json { render json: 'Failed to subscribe product'.to_json, status: :not_found }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
rescue ::Foreman::Exception => e
|
42
|
+
render json: { error: ('Failed to add task to queue: %s' % e).to_s }, status: :unprocessable_entity
|
43
|
+
rescue ForemanTasks::Lock::LockConflict => e
|
44
|
+
render json: { error: ('Lock on SCC account already taken: %s' % e).to_s }, status: :unprocessable_entity
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
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])
|
52
|
+
end
|
53
|
+
|
54
|
+
def action_permission
|
55
|
+
case params[:action]
|
56
|
+
when 'subscribe'
|
57
|
+
:subscribe
|
58
|
+
else
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/app/models/scc_account.rb
CHANGED
@@ -34,6 +34,7 @@ class SccAccount < ApplicationRecord
|
|
34
34
|
default_scope -> { order(:login) }
|
35
35
|
|
36
36
|
scoped_search on: :login, complete_value: true
|
37
|
+
scoped_search on: :name
|
37
38
|
|
38
39
|
def init
|
39
40
|
# set default values
|
@@ -84,7 +85,7 @@ class SccAccount < ApplicationRecord
|
|
84
85
|
|
85
86
|
def update_attributes_with_logic!(params)
|
86
87
|
transaction do
|
87
|
-
self.
|
88
|
+
self.update!(params)
|
88
89
|
if rec_logic_changed?
|
89
90
|
old_rec_logic = self.foreman_tasks_recurring_logic
|
90
91
|
associate_recurring_logic
|
data/app/models/scc_product.rb
CHANGED
data/config/routes.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
resources :scc_accounts do
|
3
3
|
collection do
|
4
|
-
|
4
|
+
post 'test_connection'
|
5
5
|
get 'auto_complete_search'
|
6
6
|
end
|
7
7
|
member do
|
8
|
+
put 'test_connection'
|
8
9
|
put 'sync'
|
9
10
|
put 'bulk_subscribe'
|
10
11
|
end
|
@@ -15,4 +16,32 @@ Rails.application.routes.draw do
|
|
15
16
|
put 'unsubscribe'
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
20
|
+
namespace :api, :defaults => { :format => 'json' } do
|
21
|
+
scope '(:apiv)', :module => :v2,
|
22
|
+
:defaults => { :apiv => 'v2' },
|
23
|
+
:apiv => /v1|v2/,
|
24
|
+
:constraints => ApiConstraints.new(:version => 2, :default => true) do
|
25
|
+
resources :scc_accounts do
|
26
|
+
collection do
|
27
|
+
post 'test_connection'
|
28
|
+
get 'auto_complete_search'
|
29
|
+
end
|
30
|
+
member do
|
31
|
+
put 'test_connection'
|
32
|
+
put 'sync'
|
33
|
+
put 'bulk_subscribe'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
constraints(:scc_account_id => /[^\/]+/) do
|
37
|
+
resources :scc_accounts, :only => [] do
|
38
|
+
resources :scc_products, only: %i[index show] do
|
39
|
+
member do
|
40
|
+
put 'subscribe'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
18
47
|
end
|
@@ -22,18 +22,37 @@ 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.
|
26
|
-
requires_foreman_plugin 'katello', '>= 3.
|
25
|
+
requires_foreman '>= 1.22'
|
26
|
+
requires_foreman_plugin 'katello', '>= 3.12.0'
|
27
|
+
|
28
|
+
apipie_documented_controllers ["#{ForemanSccManager::Engine.root}/app/controllers/api/v2/*.rb"]
|
27
29
|
|
28
30
|
# Add permissions
|
29
31
|
security_block :foreman_scc_manager do
|
30
|
-
permission :view_scc,
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
permission :
|
35
|
-
|
36
|
-
|
32
|
+
permission :view_scc, {
|
33
|
+
:'foreman_scc_manager/scc_accounts' => [:show, :index],
|
34
|
+
:'api/v2/scc_accounts' => [:show, :index]
|
35
|
+
}
|
36
|
+
permission :use_scc, {
|
37
|
+
:'foreman_scc_manager/scc_accounts' => [:bulk_subscribe],
|
38
|
+
:'api/v2/scc_accounts' => [:bulk_subscribe]
|
39
|
+
}
|
40
|
+
permission :new_scc, {
|
41
|
+
:'foreman_scc_manager/scc_accounts' => [:new, :create],
|
42
|
+
:'api/v2/scc_accounts' => [:create]
|
43
|
+
}
|
44
|
+
permission :edit_scc, {
|
45
|
+
:'foreman_scc_manager/scc_accounts' => [:edit, :update],
|
46
|
+
:'api/v2/scc_accounts' => [:update]
|
47
|
+
}
|
48
|
+
permission :delete_scc, {
|
49
|
+
:'foreman_scc_manager/scc_accounts' => [:destroy],
|
50
|
+
:'api/v2/scc_accounts' => [:destroy]
|
51
|
+
}
|
52
|
+
permission :sync_scc, {
|
53
|
+
:'foreman_scc_manager/scc_accounts' => [:sync],
|
54
|
+
:'api/v2/scc_accounts' => [:sync]
|
55
|
+
}
|
37
56
|
end
|
38
57
|
|
39
58
|
# Add a new role called 'SccManager' if it doesn't exist
|
data/lib/tasks/rubocop.rake
CHANGED
@@ -9,7 +9,6 @@ begin
|
|
9
9
|
"#{ForemanSccManager::Engine.root}/db/**/*.rb",
|
10
10
|
"#{ForemanSccManager::Engine.root}/lib/**/*.rake",
|
11
11
|
"#{ForemanSccManager::Engine.root}/lib/**/*.rb",
|
12
|
-
"#{ForemanSccManager::Engine.root}/locale/**/*.rb",
|
13
12
|
"#{ForemanSccManager::Engine.root}/test/**/*.rb"
|
14
13
|
]
|
15
14
|
|