Skip to content

Commit a2eacaa

Browse files
committed
feat: app sharing pt.4
1 parent 2a5bcc8 commit a2eacaa

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

enterprise/cli/server.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/coder/coder/cli/cliflag"
99
"github.com/coder/coder/cli/cliui"
10+
"github.com/coder/coder/coderd/database"
1011
"github.com/coder/coder/enterprise/coderd"
1112

1213
agpl "github.com/coder/coder/cli"
@@ -15,26 +16,33 @@ import (
1516

1617
func server() *cobra.Command {
1718
var (
18-
auditLogging bool
19-
browserOnly bool
20-
scimAuthHeader string
21-
userWorkspaceQuota int
19+
auditLogging bool
20+
browserOnly bool
21+
scimAuthHeader string
22+
userWorkspaceQuota int
23+
allowedApplicationSharingLevels []string
2224
)
2325
cmd := agpl.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, error) {
26+
appSharingLevels := make([]database.AppSharingLevel, len(allowedApplicationSharingLevels))
27+
for i, val := range allowedApplicationSharingLevels {
28+
appSharingLevels[i] = database.AppSharingLevel(val)
29+
}
30+
2431
api, err := coderd.New(ctx, &coderd.Options{
25-
AuditLogging: auditLogging,
26-
BrowserOnly: browserOnly,
27-
SCIMAPIKey: []byte(scimAuthHeader),
28-
UserWorkspaceQuota: userWorkspaceQuota,
29-
Options: options,
32+
AuditLogging: auditLogging,
33+
BrowserOnly: browserOnly,
34+
SCIMAPIKey: []byte(scimAuthHeader),
35+
UserWorkspaceQuota: userWorkspaceQuota,
36+
AllowedApplicationSharingLevels: appSharingLevels,
37+
Options: options,
3038
})
3139
if err != nil {
3240
return nil, err
3341
}
3442
return api.AGPL, nil
3543
})
36-
enterpriseOnly := cliui.Styles.Keyword.Render("This is an Enterprise feature. Contact sales@coder.com for licensing")
3744

45+
enterpriseOnly := cliui.Styles.Keyword.Render("This is an Enterprise feature. Contact sales@coder.com for licensing")
3846
cliflag.BoolVarP(cmd.Flags(), &auditLogging, "audit-logging", "", "CODER_AUDIT_LOGGING", true,
3947
"Specifies whether audit logging is enabled. "+enterpriseOnly)
4048
cliflag.BoolVarP(cmd.Flags(), &browserOnly, "browser-only", "", "CODER_BROWSER_ONLY", false,
@@ -43,6 +51,8 @@ func server() *cobra.Command {
4351
"Enables SCIM and sets the authentication header for the built-in SCIM server. New users are automatically created with OIDC authentication. "+enterpriseOnly)
4452
cliflag.IntVarP(cmd.Flags(), &userWorkspaceQuota, "user-workspace-quota", "", "CODER_USER_WORKSPACE_QUOTA", 0,
4553
"A positive number applies a limit on how many workspaces each user can create. "+enterpriseOnly)
54+
cliflag.StringArrayVarP(cmd.Flags(), &allowedApplicationSharingLevels, "permitted-app-sharing-levels", "", "CODER_PERMITTED_APP_SHARING_LEVELS", []string{"owner"},
55+
`Specifies the application sharing levels that are available site-wide. Available values are "owner", "template", "authenticated", "public". Multiple values can be specified, comma separated. `+enterpriseOnly)
4656

4757
return cmd
4858
}

provisioner/terraform/resources.go

+27-14
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ type agentAttributes struct {
2525

2626
// A mapping of attributes on the "coder_app" resource.
2727
type agentAppAttributes struct {
28-
AgentID string `mapstructure:"agent_id"`
29-
Name string `mapstructure:"name"`
30-
Icon string `mapstructure:"icon"`
31-
URL string `mapstructure:"url"`
32-
Command string `mapstructure:"command"`
33-
SharingLevel string `mapstructure:"share_level"`
34-
Subdomain bool `mapstructure:"subdomain"`
35-
Healthcheck []appHealthcheckAttributes `mapstructure:"healthcheck"`
28+
AgentID string `mapstructure:"agent_id"`
29+
Name string `mapstructure:"name"`
30+
Icon string `mapstructure:"icon"`
31+
URL string `mapstructure:"url"`
32+
Command string `mapstructure:"command"`
33+
Share string `mapstructure:"share"`
34+
Subdomain bool `mapstructure:"subdomain"`
35+
Healthcheck []appHealthcheckAttributes `mapstructure:"healthcheck"`
3636
}
3737

3838
// A mapping of attributes on the "healthcheck" resource.
@@ -236,19 +236,32 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
236236
}
237237
}
238238

239+
sharingLevel := proto.AppSharingLevel_OWNER
240+
switch strings.ToLower(attrs.Share) {
241+
case "owner":
242+
sharingLevel = proto.AppSharingLevel_OWNER
243+
case "template":
244+
sharingLevel = proto.AppSharingLevel_TEMPLATE
245+
case "authenticated":
246+
sharingLevel = proto.AppSharingLevel_AUTHENTICATED
247+
case "public":
248+
sharingLevel = proto.AppSharingLevel_PUBLIC
249+
}
250+
239251
for _, agents := range resourceAgents {
240252
for _, agent := range agents {
241253
// Find agents with the matching ID and associate them!
242254
if agent.Id != attrs.AgentID {
243255
continue
244256
}
245257
agent.Apps = append(agent.Apps, &proto.App{
246-
Name: attrs.Name,
247-
Command: attrs.Command,
248-
Url: attrs.URL,
249-
Icon: attrs.Icon,
250-
Subdomain: attrs.Subdomain,
251-
Healthcheck: healthcheck,
258+
Name: attrs.Name,
259+
Command: attrs.Command,
260+
Url: attrs.URL,
261+
Icon: attrs.Icon,
262+
Subdomain: attrs.Subdomain,
263+
SharingLevel: sharingLevel,
264+
Healthcheck: healthcheck,
252265
})
253266
}
254267
}

0 commit comments

Comments
 (0)