Skip to content

Commit

Permalink
fix: Use id as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym-tousek-keboola committed Feb 29, 2024
1 parent 32482ad commit ac6817c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/pkg/service/appproxy/appconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type AppProxyConfig struct {
ID string `json:"id"`
Name string `json:"name"`
UpstreamAppHost string `json:"upstreamAppHost"`
AuthProviders []AuthProvider `json:"authProviders"`
AuthRules []AuthRule `json:"authRules"`
Expand All @@ -21,6 +22,7 @@ type AppProxyConfig struct {

type AuthProvider struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
Expand All @@ -43,8 +45,20 @@ func GetAppProxyConfig(sender request.Sender, appID string, eTag string) request
AndPathParam("appId", appID).
AndHeader("If-None-Match", eTag).
WithOnSuccess(func(ctx context.Context, response request.HTTPResponse) error {
// Use id as fallback until name is added to Sandboxes API
if result.Name == "" {
result.Name = result.ID
}
for i, provider := range result.AuthProviders {
if provider.Name == "" {
result.AuthProviders[i].Name = provider.ID
}
}

// Add ETag to result
result.eTag = response.ResponseHeader().Get("ETag")

// Process Cache-Control header
cacheControl := response.ResponseHeader().Get("Cache-Control")
if cacheControl == "" {
return nil
Expand Down
12 changes: 12 additions & 0 deletions internal/pkg/service/appproxy/appconfig/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestLoader_LoadConfig(t *testing.T) {
},
expectedConfig: AppProxyConfig{
ID: "3",
Name: "3",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -90,6 +91,7 @@ func TestLoader_LoadConfig(t *testing.T) {
},
expectedConfig: AppProxyConfig{
ID: "4",
Name: "4",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -98,6 +100,7 @@ func TestLoader_LoadConfig(t *testing.T) {
{
expectedConfig: AppProxyConfig{
ID: "4",
Name: "4",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -115,6 +118,7 @@ func TestLoader_LoadConfig(t *testing.T) {
},
expectedConfig: AppProxyConfig{
ID: "5",
Name: "5",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -129,6 +133,7 @@ func TestLoader_LoadConfig(t *testing.T) {
expectedETag: `"etag-value"`,
expectedConfig: AppProxyConfig{
ID: "5",
Name: "5",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -138,6 +143,7 @@ func TestLoader_LoadConfig(t *testing.T) {
expectedETag: `"etag-value"`,
expectedConfig: AppProxyConfig{
ID: "5",
Name: "5",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -151,6 +157,7 @@ func TestLoader_LoadConfig(t *testing.T) {
expectedETag: `"etag-value"`,
expectedConfig: AppProxyConfig{
ID: "5",
Name: "5",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -168,6 +175,7 @@ func TestLoader_LoadConfig(t *testing.T) {
},
expectedConfig: AppProxyConfig{
ID: "6",
Name: "6",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -181,6 +189,7 @@ func TestLoader_LoadConfig(t *testing.T) {
expectedETag: `"etag-value"`,
expectedConfig: AppProxyConfig{
ID: "6",
Name: "6",
UpstreamAppHost: "new-app.local",
eTag: `"etag-new-value"`,
maxAge: 60 * time.Second,
Expand All @@ -189,6 +198,7 @@ func TestLoader_LoadConfig(t *testing.T) {
{
expectedConfig: AppProxyConfig{
ID: "6",
Name: "6",
UpstreamAppHost: "new-app.local",
eTag: `"etag-new-value"`,
maxAge: 60 * time.Second,
Expand All @@ -206,6 +216,7 @@ func TestLoader_LoadConfig(t *testing.T) {
},
expectedConfig: AppProxyConfig{
ID: "7",
Name: "7",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand All @@ -224,6 +235,7 @@ func TestLoader_LoadConfig(t *testing.T) {
expectedETag: `"etag-value"`,
expectedConfig: AppProxyConfig{
ID: "7",
Name: "7",
UpstreamAppHost: "app.local",
eTag: `"etag-value"`,
maxAge: 60 * time.Second,
Expand Down

0 comments on commit ac6817c

Please sign in to comment.