Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Conversation

honnix
Copy link
Member

@honnix honnix commented Jul 5, 2023

Hey, I just made a Pull Request!

Description

Handle GCP project not found correctly.

Motivation and Context

GCP will never return 404 in case of project not found, due to security reason. So we need to treat 403 as 404 for some case.

I also did some small refactorings along the way.

Have you tested this? If so, how?

I updated existing tests to reflect this change.

Checklist for PR author(s)

  • Changes are covered by unit test
  • All tests pass
  • Code coverage check passes
  • Error handling is tested
  • Errors are handled at the appropriate layer
  • Errors that cannot be handled where they occur are propagated
  • (optional) Changes are covered by system test
  • Relevant documentation updated
  • This PR has NO breaking change to public API
  • This PR has breaking change to public API and it is documented

Checklist for PR reviewer(s)

  • This PR has been incorporated in release note for the coming version
  • Risky changes introduced by this PR have been all considered

// GCP returns 403 in case of project not found for security reason, but that makes it impossible
// to differentiate that from missing permission; we take the risk here assuming Styx service account does have
// proper permissions
if (e.getStatusCode() == FORBIDDEN.code()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real change.

if (cause instanceof GoogleJsonResponseException
&& ((GoogleJsonResponseException) cause).getStatusCode() == 404) {
&& ((GoogleJsonResponseException) cause).getStatusCode() == FORBIDDEN.code()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real change.

@@ -37,7 +39,7 @@
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deprecated.

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Merging #1092 (bb70f26) into master (dcec378) will increase coverage by 0.03%.
The diff coverage is 72.72%.

@@             Coverage Diff              @@
##             master    #1092      +/-   ##
============================================
+ Coverage     92.33%   92.37%   +0.03%     
- Complexity     2150     2152       +2     
============================================
  Files           200      200              
  Lines          8326     8325       -1     
  Branches        504      504              
============================================
+ Hits           7688     7690       +2     
+ Misses          522      521       -1     
+ Partials        116      114       -2     

@@ -20,6 +20,8 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no test we need to change for the 404->403 code change in styx-service-common/src/main/java/com/spotify/styx/api/Authenticator.java ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/spotify/styx/pull/1092/files#diff-6d62dc7647527de82216a154436bab32cb014d6a27fc005028168031ea1a95f2R313-R332f those are the changes. There is no externally observable difference though because we treat exceptions the same except the logging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah true

@honnix honnix merged commit 8436604 into master Jul 6, 2023
@honnix honnix deleted the handle-non-exist-gcp-project branch July 6, 2023 08:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants