Skip to content

feat: Enable custom support links #6313

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

Merged
merged 13 commits into from
Feb 27, 2023
Merged
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
15 changes: 15 additions & 0 deletions cli/deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,15 @@ func newConfig() *codersdk.DeploymentConfig {
Flag: "disable-password-auth",
Default: false,
},
Support: &codersdk.SupportConfig{
Links: &codersdk.DeploymentConfigField[[]codersdk.LinkConfig]{
Name: "Support links",
Usage: "Use custom support links",
Flag: "support-links",
Default: []codersdk.LinkConfig{},
Enterprise: true,
},
},
}
}

Expand Down Expand Up @@ -649,6 +658,10 @@ func setConfig(prefix string, vip *viper.Viper, target interface{}) {
// Do not bind to CODER_GITAUTH, instead bind to CODER_GITAUTH_0_*, etc.
values := readSliceFromViper[codersdk.GitAuthConfig](vip, prefix, value)
val.FieldByName("Value").Set(reflect.ValueOf(values))
case []codersdk.LinkConfig:
// Do not bind to CODER_SUPPORT_LINKS, instead bind to CODER_SUPPORT_LINKS_0_*, etc.
values := readSliceFromViper[codersdk.LinkConfig](vip, prefix, value)
val.FieldByName("Value").Set(reflect.ValueOf(values))
default:
panic(fmt.Sprintf("unsupported type %T", value))
}
Expand Down Expand Up @@ -824,6 +837,8 @@ func setFlags(prefix string, flagset *pflag.FlagSet, vip *viper.Viper, target in
_ = flagset.DurationP(flg, shorthand, vip.GetDuration(prefix), usage)
case []string:
_ = flagset.StringSliceP(flg, shorthand, vip.GetStringSlice(prefix), usage)
case []codersdk.LinkConfig:
// Ignore this one!
case []codersdk.GitAuthConfig:
// Ignore this one!
default:
Expand Down
23 changes: 23 additions & 0 deletions cli/deployment/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,29 @@ func TestConfig(t *testing.T) {
Regex: "gitlab.com",
}}, config.GitAuth.Value)
},
}, {
Name: "Support links",
Env: map[string]string{
"CODER_SUPPORT_LINKS_0_NAME": "First link",
"CODER_SUPPORT_LINKS_0_TARGET": "http://target-link-1",
"CODER_SUPPORT_LINKS_0_ICON": "bug",

"CODER_SUPPORT_LINKS_1_NAME": "Second link",
"CODER_SUPPORT_LINKS_1_TARGET": "http://target-link-2",
"CODER_SUPPORT_LINKS_1_ICON": "chat",
},
Valid: func(config *codersdk.DeploymentConfig) {
require.Len(t, config.Support.Links.Value, 2)
require.Equal(t, []codersdk.LinkConfig{{
Name: "First link",
Target: "http://target-link-1",
Icon: "bug",
}, {
Name: "Second link",
Target: "http://target-link-2",
Icon: "chat",
}}, config.Support.Links.Value)
},
}, {
Name: "Wrong env must not break default values",
Env: map[string]string{
Expand Down
84 changes: 82 additions & 2 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 82 additions & 2 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ type DeploymentConfig struct {
Address *DeploymentConfigField[string] `json:"address" typescript:",notnull"`
// DEPRECATED: Use Experiments instead.
Experimental *DeploymentConfigField[bool] `json:"experimental" typescript:",notnull"`

Support *SupportConfig `json:"support" typescript:",notnull"`
}

type DERP struct {
Expand Down Expand Up @@ -276,8 +278,18 @@ type DangerousConfig struct {
AllowPathAppSiteOwnerAccess *DeploymentConfigField[bool] `json:"allow_path_app_site_owner_access" typescript:",notnull"`
}

type SupportConfig struct {
Links *DeploymentConfigField[[]LinkConfig] `json:"links" typescript:",notnull"`
}

type LinkConfig struct {
Name string `json:"name"`
Target string `json:"target"`
Icon string `json:"icon"`
}

type Flaggable interface {
string | time.Duration | bool | int | []string | []GitAuthConfig
string | time.Duration | bool | int | []string | []GitAuthConfig | []LinkConfig
}

type DeploymentConfigField[T Flaggable] struct {
Expand Down Expand Up @@ -348,6 +360,12 @@ func (c *Client) DeploymentConfig(ctx context.Context) (DeploymentConfig, error)
type AppearanceConfig struct {
LogoURL string `json:"logo_url"`
ServiceBanner ServiceBannerConfig `json:"service_banner"`
SupportLinks []LinkConfig `json:"support_links,omitempty"`
}

type UpdateAppearanceConfig struct {
LogoURL string `json:"logo_url"`
ServiceBanner ServiceBannerConfig `json:"service_banner"`
}

type ServiceBannerConfig struct {
Expand All @@ -371,7 +389,7 @@ func (c *Client) Appearance(ctx context.Context) (AppearanceConfig, error) {
return cfg, json.NewDecoder(res.Body).Decode(&cfg)
}

func (c *Client) UpdateAppearance(ctx context.Context, appearance AppearanceConfig) error {
func (c *Client) UpdateAppearance(ctx context.Context, appearance UpdateAppearanceConfig) error {
res, err := c.Request(ctx, http.MethodPut, "/api/v2/appearance", appearance)
if err != nil {
return err
Expand Down
Loading