Skip to content

Commit

Permalink
Require "base_url:" to be set and non-empty (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev authored Jul 3, 2024
1 parent 86453d5 commit 814fa61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion internal/command/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func run(cmd *cobra.Command, _ []string) error {
return err
}

if config.BaseURL == nil {
return fmt.Errorf("base URL needs to be specified")
}

maxBytes, err := humanize.ParseBytes(config.Disk.Limit)
if err != nil {
return err
Expand All @@ -62,7 +66,7 @@ func run(cmd *cobra.Command, _ []string) error {
return err
}

server, err := serverpkg.New(addr, (*url.URL)(&config.BaseURL), config.OIDCProviders, localCache, remoteCache)
server, err := serverpkg.New(addr, (*url.URL)(config.BaseURL), config.OIDCProviders, localCache, remoteCache)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"gopkg.in/yaml.v3"
"io"
"net/url"
Expand All @@ -9,6 +10,10 @@ import (
type BaseURL url.URL

func (baseURL *BaseURL) UnmarshalYAML(value *yaml.Node) error {
if value.Value == "" {
return fmt.Errorf("base URL cannot be empty")
}

parsedURL, err := url.Parse(value.Value)
if err != nil {
return err
Expand All @@ -20,7 +25,7 @@ func (baseURL *BaseURL) UnmarshalYAML(value *yaml.Node) error {
}

type Config struct {
BaseURL BaseURL `yaml:"base_url"`
BaseURL *BaseURL `yaml:"base_url"`
OIDCProviders []OIDCProvider `yaml:"oidc_providers"`
Disk Disk `yaml:"disk"`
S3 S3 `yaml:"s3"`
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestParse(t *testing.T) {
actualConfig, err := config.Parse(configFile)
require.NoError(t, err)
require.Equal(t, &config.Config{
BaseURL: config.BaseURL{
BaseURL: &config.BaseURL{
Scheme: "https",
Host: "example.com",
},
Expand Down

0 comments on commit 814fa61

Please sign in to comment.