-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
481 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Project::ClusterContext | ||
attr_reader :user, :user_access_module, :project, :cluster, :params | ||
|
||
def initialize(user, project, user_access_module, cluster, params) | ||
@user = user | ||
@user_access_module = user_access_module | ||
@project = project | ||
@cluster = cluster | ||
@params = params | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
core/app/controllers/uffizzi_core/api/cli/v1/projects/clusters/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Api::Cli::V1::Projects::Clusters::ApplicationController < UffizziCore::Api::Cli::V1::Projects::ApplicationController | ||
def resource_cluster | ||
@resource_cluster ||= if request_by_admin? || valid_request_from_ci_workflow? | ||
active_project_clusters.find_by!(name: params[:cluster_name]) | ||
else | ||
active_project_clusters.deployed_by_user(current_user).find_by!(name: params[:cluster_name]) | ||
end | ||
end | ||
|
||
private | ||
|
||
def active_project_clusters | ||
@active_project_clusters ||= resource_project.clusters.enabled | ||
end | ||
|
||
def request_by_admin? | ||
current_user.admin_access_to_project?(resource_project) | ||
end | ||
|
||
def valid_request_from_ci_workflow? | ||
ci_module.valid_request_from_ci_workflow?(params) | ||
end | ||
|
||
def policy_context | ||
UffizziCore::Project::ClusterContext.new(current_user, resource_project, user_access_module, resource_cluster, params) | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
core/app/controllers/uffizzi_core/api/cli/v1/projects/clusters/ingresses_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Api::Cli::V1::Projects::Clusters::IngressesController < | ||
UffizziCore::Api::Cli::V1::Projects::Clusters::ApplicationController | ||
before_action :authorize_uffizzi_core_api_cli_v1_projects_clusters_ingresses | ||
|
||
def index | ||
hosts = UffizziCore::ControllerService.ingress_hosts(resource_cluster) | ||
user_hosts = UffizziCore::ClusterService.filter_user_ingress_host(resource_cluster, hosts) | ||
|
||
data = { | ||
ingresses: user_hosts, | ||
} | ||
|
||
respond_with data | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/app/policies/uffizzi_core/api/cli/v1/projects/clusters/ingresses_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class UffizziCore::Api::Cli::V1::Projects::Clusters::IngressesPolicy < UffizziCore::ApplicationPolicy | ||
def index? | ||
return true if context.user_access_module.admin_access_to_project?(context.user, context.project) | ||
|
||
context.cluster.deployed_by_id == context.user.id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module UffizziCore | ||
VERSION = '2.2.25' | ||
VERSION = '2.3.0' | ||
end |
25 changes: 25 additions & 0 deletions
25
core/test/controllers/uffizzi_core/api/cli/v1/projects/clusters/ingresses_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class UffizziCore::Api::Cli::V1::Projects::Clusters::IngressesControllerTest < ActionController::TestCase | ||
setup do | ||
@user = create(:user, :with_personal_account) | ||
@project = create(:project, :with_members, account: @user.personal_account, members: [@user]) | ||
@cluster = create(:cluster, project: @project, deployed_by: @user) | ||
|
||
sign_in @user | ||
end | ||
|
||
test '#index' do | ||
data = json_fixture('files/controller/ingresses.json') | ||
stubbed_get_ingresses_request = stub_get_ingresses(data) | ||
|
||
params = { project_slug: @project.slug, cluster_name: @cluster.name } | ||
|
||
get :index, params: params, format: :json | ||
|
||
assert_response(:success) | ||
assert_requested(stubbed_get_ingresses_request) | ||
end | ||
end |
Oops, something went wrong.