Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: using cluster_name for update barito app #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/controllers/api/v2/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def increase_log_count

def update_barito_app
valid, error_response = validate_required_keys(
[:app_group_secret, :app_name])
[:cluster_name, :app_name])
render json: error_response, status: error_response[:code] and return unless valid

app_group = AppGroup.find_by(secret_key: params[:app_group_secret])
app_group = AppGroup.find_by(helm_infrastructure: HelmInfrastructure.find_by_cluster_name(params[:cluster_name]))
if app_group.blank? || !app_group.available?
render json: {
success: false,
Expand Down Expand Up @@ -162,6 +162,4 @@ def generate_profile_response(app)
},
}
end


end
25 changes: 13 additions & 12 deletions spec/requests/api/v2/apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ class Datadog::Statsd
describe 'Update BaritoApp API' do
before(:each) do
@app_group = create(:app_group)
create(:helm_infrastructure,
@helm_infra = create(:helm_infrastructure,
app_group: @app_group,
status: HelmInfrastructure.statuses[:active]
status: HelmInfrastructure.statuses[:active],
cluster_name: "test-cluster"
)
@app = create(:barito_app,
app_group: @app_group,
Expand All @@ -301,7 +302,7 @@ class Datadog::Statsd
patch api_v2_update_barito_app_path,
params: {
access_token: @access_token,
app_group_secret: @app_group.secret_key,
cluster_name: @helm_infra.cluster_name,
app_name: "test-app-01",
max_tps: 100,
log_retention_days: 14
Expand All @@ -317,14 +318,14 @@ class Datadog::Statsd
end
end

context 'When app_group_secret is not provided' do
context 'When cluster_name is not provided' do
it 'Should return 422' do
error_msg = 'Invalid Params: app_group_secret is a required parameter'
error_msg = 'Invalid Params: cluster_name is a required parameter'

patch api_v2_update_barito_app_path,
params: {
access_token: @access_token,
app_group_secret: '',
cluster_name: '',
app_name: "test-app-01",
max_tps: 100,
log_retention_days: 14
Expand All @@ -336,14 +337,14 @@ class Datadog::Statsd
end
end

context 'When app_group_secret is provided and valid but params[:app_name] is not provided' do
context 'When cluster_name is provided and valid but params[:app_name] is not provided' do
it 'should return 422' do
error_msg = 'Invalid Params: app_name is a required parameter'

patch api_v2_update_barito_app_path,
params: {
access_token: @access_token,
app_group_secret: @app_group.secret_key,
cluster_name: @helm_infra.cluster_name,
}, headers: headers
expect(response.status).to eq 422

Expand All @@ -352,14 +353,14 @@ class Datadog::Statsd
end
end

context 'When app_group_secret is provided but is not found' do
context 'When cluster_name is provided but is not found' do
it 'Should return 404' do
error_msg = 'AppGroup not found or inactive'

patch api_v2_update_barito_app_path,
params: {
access_token: @access_token,
app_group_secret: "fake_secret",
cluster_name: "fake_cluster",
app_name: "test-app-01",
max_tps: 100,
log_retention_days: 14
Expand All @@ -371,14 +372,14 @@ class Datadog::Statsd
end
end

context 'When app_group_secret is provided and valid BaritoApp is not found' do
context 'When cluster_name is provided and valid but BaritoApp is not found' do
it 'Should return 404' do
error_msg = 'App/Release not found or inactive'

patch api_v2_update_barito_app_path,
params: {
access_token: @access_token,
app_group_secret: @app_group.secret_key,
cluster_name: @helm_infra.cluster_name,
app_name: "test-app-02",
max_tps: 100,
log_retention_days: 14
Expand Down