uffizzi_core 2.2.17 → 2.2.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/uffizzi_core/dependency_injection_concern.rb +6 -6
- data/app/controllers/uffizzi_core/api/cli/v1/accounts/clusters_controller.rb +41 -0
- data/app/lib/uffizzi_core/concerns/models/project.rb +2 -1
- data/app/policies/uffizzi_core/api/cli/v1/accounts/clusters_policy.rb +7 -0
- data/app/repositories/uffizzi_core/cluster_repo.rb +1 -0
- data/app/serializers/uffizzi_core/api/cli/v1/accounts/cluster_serializer/project_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/accounts/cluster_serializer.rb +9 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer.rb +1 -45
- data/config/routes.rb +1 -0
- data/db/migrate/20230824150022_update_name_constraint_to_projects.rb +10 -0
- data/lib/uffizzi_core/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6b90d5ab4a5541985fc4d2759d95026ba31fcebda13efe26d005c90ccd53329
|
4
|
+
data.tar.gz: e92d2ab057e8fc18ae9dbb7520e479acfcef6d4f6c7269cde28e202d8d3f327e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b60359564b861d85210a4c79df1f93882fa58fe51447c16488e40f81854cf71e997c4d9e06ab1d0c0e72ca40b300e95446aff2344675a2dfcf2f6c4bf6da017
|
7
|
+
data.tar.gz: ac60e35f27a030dc11fdca4f1a64da273e343f873322704adae014f83107f3d93a002aeb23f690df5cfdd385dfd7f2fc444c710cf5345de5bc6527438bf4ca76
|
@@ -27,6 +27,12 @@ module UffizziCore::DependencyInjectionConcern
|
|
27
27
|
module_class(:volume_parser)
|
28
28
|
end
|
29
29
|
|
30
|
+
def ci_module
|
31
|
+
return unless module_exists?(:ci_module)
|
32
|
+
|
33
|
+
module_class(:ci_module)
|
34
|
+
end
|
35
|
+
|
30
36
|
def ci_session
|
31
37
|
return unless module_exists?(:ci_session)
|
32
38
|
|
@@ -73,12 +79,6 @@ module UffizziCore::DependencyInjectionConcern
|
|
73
79
|
module_class(:controller_settings)
|
74
80
|
end
|
75
81
|
|
76
|
-
def ci_module
|
77
|
-
return unless module_exists?(:ci_module)
|
78
|
-
|
79
|
-
module_class(:ci_module)
|
80
|
-
end
|
81
|
-
|
82
82
|
private
|
83
83
|
|
84
84
|
def module_exists?(module_name)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Api::Cli::V1::Accounts::ClustersController < UffizziCore::Api::Cli::V1::Accounts::ApplicationController
|
4
|
+
include UffizziCore::DependencyInjectionConcern
|
5
|
+
before_action :authorize_uffizzi_core_api_cli_v1_accounts_clusters
|
6
|
+
|
7
|
+
def index
|
8
|
+
return respond_with(clusters_by_account.includes(:project)) if valid_request_from_ci_workflow?
|
9
|
+
|
10
|
+
clusters = clusters_by_user.or(clusters_by_admin_projects)
|
11
|
+
respond_with(clusters.includes(:project))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def valid_request_from_ci_workflow?
|
17
|
+
ci_module.valid_request_from_ci_workflow?(params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def clusters_by_admin_projects
|
21
|
+
projects = UffizziCore::Project
|
22
|
+
.active
|
23
|
+
.joins(:user_projects)
|
24
|
+
.where(account: resource_account)
|
25
|
+
.where(user_projects: { role: UffizziCore::UserProject.role.admin, user: current_user })
|
26
|
+
|
27
|
+
UffizziCore::Cluster.enabled.where(project_id: projects.select(:id))
|
28
|
+
end
|
29
|
+
|
30
|
+
def clusters_by_user
|
31
|
+
UffizziCore::Cluster.enabled.by_projects(account_projects).deployed_by_user(current_user)
|
32
|
+
end
|
33
|
+
|
34
|
+
def clusters_by_account
|
35
|
+
UffizziCore::Cluster.enabled.by_projects(account_projects)
|
36
|
+
end
|
37
|
+
|
38
|
+
def account_projects
|
39
|
+
UffizziCore::Project.active.where(account: resource_account)
|
40
|
+
end
|
41
|
+
end
|
@@ -24,7 +24,8 @@ module UffizziCore::Concerns::Models::Project
|
|
24
24
|
has_many :host_volume_files, dependent: :destroy
|
25
25
|
has_many :clusters, dependent: :destroy
|
26
26
|
|
27
|
-
validates :name, presence: true
|
27
|
+
validates :name, presence: true
|
28
|
+
validates_uniqueness_of :name, conditions: -> { where(state: :active) }
|
28
29
|
validates :slug, presence: true, uniqueness: true
|
29
30
|
|
30
31
|
aasm(:state) do
|
@@ -7,5 +7,6 @@ module UffizziCore::ClusterRepo
|
|
7
7
|
scope :deployed, -> { where(state: UffizziCore::Cluster::STATE_DEPLOYED) }
|
8
8
|
scope :enabled, -> { where.not(state: UffizziCore::Cluster::STATE_DISABLED) }
|
9
9
|
scope :deployed_by_user, ->(user) { where(deployed_by: user) }
|
10
|
+
scope :by_projects, ->(projects) { where(project_id: projects.select(:id)) }
|
10
11
|
end
|
11
12
|
end
|
@@ -7,19 +7,9 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentSerializer < UffizziCore::B
|
|
7
7
|
type :deployment
|
8
8
|
|
9
9
|
attributes :id,
|
10
|
-
:kind,
|
11
10
|
:project_id,
|
12
|
-
:created_at,
|
13
|
-
:updated_at,
|
14
11
|
:state,
|
15
|
-
:preview_url
|
16
|
-
:tag,
|
17
|
-
:branch,
|
18
|
-
:image_id,
|
19
|
-
:ingress_container_ready,
|
20
|
-
:ingress_container_state,
|
21
|
-
:creation_source,
|
22
|
-
:metadata
|
12
|
+
:preview_url
|
23
13
|
|
24
14
|
has_many :containers
|
25
15
|
|
@@ -28,38 +18,4 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentSerializer < UffizziCore::B
|
|
28
18
|
def containers
|
29
19
|
object.containers.active
|
30
20
|
end
|
31
|
-
|
32
|
-
def tag
|
33
|
-
object.ingress_container&.tag
|
34
|
-
end
|
35
|
-
|
36
|
-
def branch
|
37
|
-
object.ingress_container&.repo&.branch
|
38
|
-
end
|
39
|
-
|
40
|
-
def image_id
|
41
|
-
object.ingress_container&.repo&.name
|
42
|
-
end
|
43
|
-
|
44
|
-
def ingress_container_ready
|
45
|
-
!!object.ingress_container&.activity_items&.last&.events&.last&.deployed?
|
46
|
-
end
|
47
|
-
|
48
|
-
def ingress_container_state
|
49
|
-
last_event = object.ingress_container&.activity_items&.last&.events&.last
|
50
|
-
|
51
|
-
case last_event&.state
|
52
|
-
when UffizziCore::Event.state.deployed
|
53
|
-
:deployed
|
54
|
-
when UffizziCore::Event.state.failed, UffizziCore::Event.state.timeout, UffizziCore::Event.state.cancelled
|
55
|
-
:failed
|
56
|
-
else
|
57
|
-
state_from_activity_items
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def state_from_activity_items
|
62
|
-
activity_items_count = object.ingress_container&.activity_items&.count
|
63
|
-
activity_items_count.to_i > 1 ? :updating : :pending
|
64
|
-
end
|
65
21
|
end
|
data/config/routes.rb
CHANGED
@@ -47,6 +47,7 @@ UffizziCore::Engine.routes.draw do
|
|
47
47
|
resources :accounts, only: ['index'] do
|
48
48
|
scope module: :accounts do
|
49
49
|
resources :projects, only: ['index', 'create']
|
50
|
+
resources :clusters, only: ['index']
|
50
51
|
resources :credentials, only: ['index', 'create', 'update', 'destroy'], param: :type do
|
51
52
|
member do
|
52
53
|
get :check_credential
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UpdateNameConstraintToProjects < ActiveRecord::Migration[6.1]
|
4
|
+
def change
|
5
|
+
remove_index(:uffizzi_core_projects, [:account_id, :name])
|
6
|
+
add_index(:uffizzi_core_projects, [:account_id, :name], unique: true,
|
7
|
+
where: "state = 'active'",
|
8
|
+
name: 'proj_uniq_name')
|
9
|
+
end
|
10
|
+
end
|
data/lib/uffizzi_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uffizzi_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Thurman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aasm
|
@@ -783,6 +783,7 @@ files:
|
|
783
783
|
- app/controllers/concerns/uffizzi_core/authorization_concern.rb
|
784
784
|
- app/controllers/concerns/uffizzi_core/dependency_injection_concern.rb
|
785
785
|
- app/controllers/uffizzi_core/api/cli/v1/accounts/application_controller.rb
|
786
|
+
- app/controllers/uffizzi_core/api/cli/v1/accounts/clusters_controller.rb
|
786
787
|
- app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb
|
787
788
|
- app/controllers/uffizzi_core/api/cli/v1/accounts/projects_controller.rb
|
788
789
|
- app/controllers/uffizzi_core/api/cli/v1/accounts_controller.rb
|
@@ -926,6 +927,7 @@ files:
|
|
926
927
|
- app/models/uffizzi_core/template.rb
|
927
928
|
- app/models/uffizzi_core/user.rb
|
928
929
|
- app/models/uffizzi_core/user_project.rb
|
930
|
+
- app/policies/uffizzi_core/api/cli/v1/accounts/clusters_policy.rb
|
929
931
|
- app/policies/uffizzi_core/api/cli/v1/accounts/credentials_policy.rb
|
930
932
|
- app/policies/uffizzi_core/api/cli/v1/accounts/projects_policy.rb
|
931
933
|
- app/policies/uffizzi_core/api/cli/v1/accounts_policy.rb
|
@@ -960,6 +962,8 @@ files:
|
|
960
962
|
- app/repositories/uffizzi_core/user_repo.rb
|
961
963
|
- app/responders/uffizzi_core/json_responder.rb
|
962
964
|
- app/serializers/uffizzi_core/api/cli/v1/account_serializer.rb
|
965
|
+
- app/serializers/uffizzi_core/api/cli/v1/accounts/cluster_serializer.rb
|
966
|
+
- app/serializers/uffizzi_core/api/cli/v1/accounts/cluster_serializer/project_serializer.rb
|
963
967
|
- app/serializers/uffizzi_core/api/cli/v1/accounts/credential_serializer.rb
|
964
968
|
- app/serializers/uffizzi_core/api/cli/v1/accounts/project_serializer.rb
|
965
969
|
- app/serializers/uffizzi_core/api/cli/v1/project_serializer.rb
|
@@ -1083,6 +1087,7 @@ files:
|
|
1083
1087
|
- db/migrate/20230613101901_create_clusters.rb
|
1084
1088
|
- db/migrate/20230711101901_add_host_to_clusters.rb
|
1085
1089
|
- db/migrate/20230810140316_add_source_to_uffizzi_core_clusters.rb
|
1090
|
+
- db/migrate/20230824150022_update_name_constraint_to_projects.rb
|
1086
1091
|
- db/seeds.rb
|
1087
1092
|
- lib/tasks/uffizzi_core_tasks.rake
|
1088
1093
|
- lib/uffizzi_core.rb
|