-
Notifications
You must be signed in to change notification settings - Fork 13
fix: api regional endpoint [IDE-1488] #1045
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,11 +157,33 @@ func getPrioritizedApiUrl(customUrl string, engineUrl string) string { | |
| return engineUrl | ||
| } | ||
|
|
||
| // #IDE-1488 Fix for production debugging issue on the EU server. | ||
| if isApiSubdomain(defaultUrl, customUrl) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the logical reasoning for this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to only apply the switch between URLs for those particular cases. |
||
| return defaultUrl | ||
| } | ||
|
|
||
| // Otherwise, return the custom URL set by the user. | ||
| // FedRAMP and single tenant environments. | ||
| return customUrl | ||
| } | ||
|
|
||
| func isApiSubdomain(domain, subdomain string) bool { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I read the code correctly, this method returns, whether the given domain starts with
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method tests if a given subdomain URL is a region subdomain of the parent domain, but only do it if both URLs start with |
||
| domain = strings.TrimPrefix(domain, "https://") | ||
| subdomain = strings.TrimPrefix(subdomain, "https://") | ||
|
|
||
| if !strings.HasPrefix(domain, "api.") || !strings.HasPrefix(subdomain, "api.") { | ||
| return false | ||
| } | ||
|
|
||
| domain = strings.TrimPrefix(domain, "api.") | ||
| subdomain = strings.TrimPrefix(subdomain, "api.") | ||
|
|
||
| domain = strings.ToLower(strings.TrimSpace(domain)) | ||
| subdomain = strings.ToLower(strings.TrimSpace(subdomain)) | ||
|
|
||
| return strings.HasSuffix(subdomain, "."+domain) | ||
| } | ||
|
|
||
| func (a *AuthenticationServiceImpl) UpdateCredentials(newToken string, sendNotification bool, updateApiUrl bool) { | ||
| a.m.Lock() | ||
| defer a.m.Unlock() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -341,6 +341,12 @@ func TestGetApiUrl(t *testing.T) { | |
| engineUrl: "", | ||
| expectedResult: customUrl, | ||
| }, | ||
| { | ||
| name: "Default URL when custom URL is subdomain", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? This does not seem right.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will only apply the switch in the case when both URLs start with |
||
| customUrl: "https://api.eu.snyk.io", | ||
| engineUrl: "", | ||
| expectedResult: defaultUrl, // equals to "https://api.snyk.io" | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this comment needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope of the comment is to link the bug fix to a ticket.
Sometimes when fixing a bug, the change does not make sense after some time and this would help avoid removing or refactoring it.
If this does not fit team's conventions, I will remove it.