Skip to content

Commit cab9159

Browse files
committed
feat: add enterprise key for shared ports
1 parent 207328c commit cab9159

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

coderd/coderd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import (
5656
"github.com/coder/coder/v2/coderd/httpapi"
5757
"github.com/coder/coder/v2/coderd/httpmw"
5858
"github.com/coder/coder/v2/coderd/metricscache"
59+
"github.com/coder/coder/v2/coderd/portsharing"
5960
"github.com/coder/coder/v2/coderd/prometheusmetrics"
6061
"github.com/coder/coder/v2/coderd/provisionerdserver"
6162
"github.com/coder/coder/v2/coderd/rbac"
@@ -401,6 +402,7 @@ func New(options *Options) *API {
401402
}
402403

403404
api.AppearanceFetcher.Store(&appearance.DefaultFetcher)
405+
api.PortSharer.Store(&portsharing.DefaultPortSharer)
404406
api.SiteHandler = site.New(&site.Options{
405407
BinFS: binFS,
406408
BinHashes: binHashes,
@@ -1104,6 +1106,7 @@ type API struct {
11041106
// AccessControlStore is a pointer to an atomic pointer since it is
11051107
// passed to dbauthz.
11061108
AccessControlStore *atomic.Pointer[dbauthz.AccessControlStore]
1109+
PortSharer atomic.Pointer[portsharing.PortSharer]
11071110

11081111
HTTPAuth *HTTPAuthorizer
11091112

coderd/portsharing/portsharing.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package portsharing
2+
3+
type PortSharer interface {
4+
Enabled() bool
5+
}
6+
7+
type AGPLPortSharer struct{}
8+
9+
func (AGPLPortSharer) Enabled() bool {
10+
return true
11+
}
12+
13+
var DefaultPortSharer PortSharer = AGPLPortSharer{}

codersdk/deployment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
FeatureWorkspaceBatchActions FeatureName = "workspace_batch_actions"
5353
FeatureAccessControl FeatureName = "access_control"
5454
FeatureOAuth2Provider FeatureName = "oauth2_provider"
55+
FeatureSharedPorts FeatureName = "shared_ports"
5556
)
5657

5758
// FeatureNames must be kept in-sync with the Feature enum above.

enterprise/coderd/coderd.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"time"
1616

1717
"github.com/coder/coder/v2/coderd/appearance"
18+
agplportsharing "github.com/coder/coder/v2/coderd/portsharing"
19+
"github.com/coder/coder/v2/enterprise/coderd/portsharing"
1820

1921
"golang.org/x/xerrors"
2022
"tailscale.com/tailcfg"
@@ -533,6 +535,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
533535
codersdk.FeatureWorkspaceProxy: true,
534536
codersdk.FeatureUserRoleManagement: true,
535537
codersdk.FeatureAccessControl: true,
538+
codersdk.FeatureSharedPorts: true,
536539
})
537540
if err != nil {
538541
return err
@@ -690,6 +693,14 @@ func (api *API) updateEntitlements(ctx context.Context) error {
690693
}
691694
}
692695

696+
if initial, changed, enabled := featureChanged(codersdk.FeatureSharedPorts); shouldUpdate(initial, changed, enabled) {
697+
var ps agplportsharing.PortSharer = agplportsharing.DefaultPortSharer
698+
if enabled {
699+
ps = portsharing.NewEnterprisePortSharer()
700+
}
701+
api.AGPL.PortSharer.Store(&ps)
702+
}
703+
693704
// External token encryption is soft-enforced
694705
featureExternalTokenEncryption := entitlements.Features[codersdk.FeatureExternalTokenEncryption]
695706
featureExternalTokenEncryption.Enabled = len(api.ExternalTokenEncryption) > 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package portsharing
2+
3+
type EnterprisePortSharer struct{}
4+
5+
func NewEnterprisePortSharer() *EnterprisePortSharer {
6+
return &EnterprisePortSharer{}
7+
}
8+
9+
func (EnterprisePortSharer) Enabled() bool {
10+
return true
11+
}

0 commit comments

Comments
 (0)