From 4c8fd5b91a347d365ae078b6372d81f17e569161 Mon Sep 17 00:00:00 2001 From: yosep simanjuntak Date: Fri, 18 Oct 2024 15:05:35 +0700 Subject: [PATCH 1/3] fix: optimize profile_by_app_group_name to query only active AppGroups --- app/controllers/api/v2/infrastructures_controller.rb | 3 ++- app/controllers/api/v3/infrastructures_controller.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v2/infrastructures_controller.rb b/app/controllers/api/v2/infrastructures_controller.rb index 5e5e0a3f..22a948de 100644 --- a/app/controllers/api/v2/infrastructures_controller.rb +++ b/app/controllers/api/v2/infrastructures_controller.rb @@ -149,7 +149,8 @@ def profile_by_cluster_name def profile_by_app_group_name @app_group = AppGroup.find_by( - name: params[:app_group_name] + name: params[:app_group_name], + status: "ACTIVE" ) if @app_group.blank? || !@app_group.ACTIVE? diff --git a/app/controllers/api/v3/infrastructures_controller.rb b/app/controllers/api/v3/infrastructures_controller.rb index 179dcfe0..0081015d 100644 --- a/app/controllers/api/v3/infrastructures_controller.rb +++ b/app/controllers/api/v3/infrastructures_controller.rb @@ -138,6 +138,7 @@ def authorize_by_username def profile_by_app_group_name @app_group = AppGroup.find_by( name: params[:app_group_name], + status: "ACTIVE" ) if @app_group.blank? || !@app_group.ACTIVE? From c7b37590844c3b53e9c8d386b08c95f020600e55 Mon Sep 17 00:00:00 2001 From: yosep simanjuntak Date: Fri, 18 Oct 2024 15:46:57 +0700 Subject: [PATCH 2/3] feat : update conditions if the helm infra not found --- app/controllers/api/v2/infrastructures_controller.rb | 10 +++++++++- app/controllers/api/v3/infrastructures_controller.rb | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v2/infrastructures_controller.rb b/app/controllers/api/v2/infrastructures_controller.rb index 22a948de..f56c3635 100644 --- a/app/controllers/api/v2/infrastructures_controller.rb +++ b/app/controllers/api/v2/infrastructures_controller.rb @@ -153,7 +153,7 @@ def profile_by_app_group_name status: "ACTIVE" ) - if @app_group.blank? || !@app_group.ACTIVE? + if @app_group.blank? || @app_group.status != "ACTIVE" render(json: { success: false, errors: ['App Group not found'], @@ -164,6 +164,14 @@ def profile_by_app_group_name @helm_infrastructure = @app_group.helm_infrastructure_in_default_location @helm_infrastructure = @app_group.helm_infrastructures.active.first unless @helm_infrastructure.present? + if @helm_infrastructure.blank? + render json: { + success: false, + errors: ['Helm infrastructure not found'], + code: 404, + }, status: :not_found and return + end + render json: { app_group_name: @app_group.name, app_group_secret: @app_group.secret_key, diff --git a/app/controllers/api/v3/infrastructures_controller.rb b/app/controllers/api/v3/infrastructures_controller.rb index 0081015d..792a56ee 100644 --- a/app/controllers/api/v3/infrastructures_controller.rb +++ b/app/controllers/api/v3/infrastructures_controller.rb @@ -141,7 +141,7 @@ def profile_by_app_group_name status: "ACTIVE" ) - if @app_group.blank? || !@app_group.ACTIVE? + if @app_group.blank? || @app_group.status != "ACTIVE" render(json: { success: false, errors: ['App Group not found'], @@ -149,6 +149,14 @@ def profile_by_app_group_name }, status: :not_found) && return end + if @helm_infrastructure.blank? + render json: { + success: false, + errors: ['Helm infrastructure not found'], + code: 404, + }, status: :not_found and return + end + render json: { id: @app_group.id, name: @app_group.name, From 67a2e5885d339d4a26b281d2b25b2b347d649077 Mon Sep 17 00:00:00 2001 From: yosep simanjuntak Date: Mon, 21 Oct 2024 13:16:14 +0700 Subject: [PATCH 3/3] feat: update condition --- app/controllers/api/v2/infrastructures_controller.rb | 10 +--------- app/controllers/api/v3/infrastructures_controller.rb | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/app/controllers/api/v2/infrastructures_controller.rb b/app/controllers/api/v2/infrastructures_controller.rb index f56c3635..fba65051 100644 --- a/app/controllers/api/v2/infrastructures_controller.rb +++ b/app/controllers/api/v2/infrastructures_controller.rb @@ -153,7 +153,7 @@ def profile_by_app_group_name status: "ACTIVE" ) - if @app_group.blank? || @app_group.status != "ACTIVE" + if @app_group.blank? render(json: { success: false, errors: ['App Group not found'], @@ -164,14 +164,6 @@ def profile_by_app_group_name @helm_infrastructure = @app_group.helm_infrastructure_in_default_location @helm_infrastructure = @app_group.helm_infrastructures.active.first unless @helm_infrastructure.present? - if @helm_infrastructure.blank? - render json: { - success: false, - errors: ['Helm infrastructure not found'], - code: 404, - }, status: :not_found and return - end - render json: { app_group_name: @app_group.name, app_group_secret: @app_group.secret_key, diff --git a/app/controllers/api/v3/infrastructures_controller.rb b/app/controllers/api/v3/infrastructures_controller.rb index 792a56ee..2bf8ae96 100644 --- a/app/controllers/api/v3/infrastructures_controller.rb +++ b/app/controllers/api/v3/infrastructures_controller.rb @@ -141,7 +141,7 @@ def profile_by_app_group_name status: "ACTIVE" ) - if @app_group.blank? || @app_group.status != "ACTIVE" + if @app_group.blank? render(json: { success: false, errors: ['App Group not found'], @@ -149,14 +149,6 @@ def profile_by_app_group_name }, status: :not_found) && return end - if @helm_infrastructure.blank? - render json: { - success: false, - errors: ['Helm infrastructure not found'], - code: 404, - }, status: :not_found and return - end - render json: { id: @app_group.id, name: @app_group.name,