Skip to content

feat(site): connect open_in parameter #16036

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 7 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
1,144 changes: 600 additions & 544 deletions agent/proto/agent.pb.go

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion agent/proto/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ message WorkspaceApp {
AUTHENTICATED = 2;
PUBLIC = 3;
}

SharingLevel sharing_level = 10;

message Healthcheck {
Expand All @@ -42,7 +43,13 @@ message WorkspaceApp {
}
Health health = 12;
bool hidden = 13;
string open_in = 14;

enum OpenIn {
WINDOW = 0;
SLIM_WINDOW = 1;
TAB = 2;
}
OpenIn open_in = 14;
}

message WorkspaceAgentScript {
Expand Down
15 changes: 14 additions & 1 deletion coderd/apidoc/docs.go

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

11 changes: 10 additions & 1 deletion coderd/apidoc/swagger.json

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

1 change: 1 addition & 0 deletions coderd/database/db2sdk/db2sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerNa
},
Health: codersdk.WorkspaceAppHealth(dbApp.Health),
Hidden: dbApp.Hidden,
OpenIn: codersdk.WorkspaceAppOpenIn(dbApp.OpenIn),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece is the most important of the PR - basically extracting data from the db to make them be visible in the SDK and API calls.

})
}
return apps
Expand Down
29 changes: 27 additions & 2 deletions codersdk/agentsdk/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ func AppFromProto(protoApp *proto.WorkspaceApp) (codersdk.WorkspaceApp, error) {
return codersdk.WorkspaceApp{}, xerrors.Errorf("unknown app health: %v (%q)", protoApp.Health, protoApp.Health.String())
}

var openIn codersdk.WorkspaceAppOpenIn
switch protoApp.OpenIn {
case proto.WorkspaceApp_OpenIn(proto.WorkspaceApp_OpenIn_value["SLIM_WINDOW"]):
openIn = codersdk.WorkspaceAppOpenInSlimWindow
case proto.WorkspaceApp_OpenIn(proto.WorkspaceApp_OpenIn_value["WINDOW"]):
openIn = codersdk.WorkspaceAppOpenInWindow
case proto.WorkspaceApp_OpenIn(proto.WorkspaceApp_OpenIn_value["TAB"]):
openIn = codersdk.WorkspaceAppOpenInTab
default:
return codersdk.WorkspaceApp{}, xerrors.Errorf("unknown app open in option: %v (%q)", protoApp.OpenIn, protoApp.OpenIn.String())
}

return codersdk.WorkspaceApp{
ID: id,
URL: protoApp.Url,
Expand All @@ -255,7 +267,7 @@ func AppFromProto(protoApp *proto.WorkspaceApp) (codersdk.WorkspaceApp, error) {
},
Health: health,
Hidden: protoApp.Hidden,
OpenIn: protoApp.OpenIn,
OpenIn: openIn,
}, nil
}

Expand All @@ -268,6 +280,19 @@ func ProtoFromApp(a codersdk.WorkspaceApp) (*proto.WorkspaceApp, error) {
if !ok {
return nil, xerrors.Errorf("unknown health %s", a.Health)
}

var openIn proto.WorkspaceApp_OpenIn
switch a.OpenIn {
case "slim-window":
openIn = proto.WorkspaceApp_SLIM_WINDOW
case "window":
openIn = proto.WorkspaceApp_WINDOW
case "tab":
openIn = proto.WorkspaceApp_TAB
default:
return nil, xerrors.Errorf("unknown open_in %s", a.OpenIn)
}

return &proto.WorkspaceApp{
Id: a.ID[:],
Url: a.URL,
Expand All @@ -286,7 +311,7 @@ func ProtoFromApp(a codersdk.WorkspaceApp) (*proto.WorkspaceApp, error) {
},
Health: proto.WorkspaceApp_Health(health),
Hidden: a.Hidden,
OpenIn: a.OpenIn,
OpenIn: openIn,
}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions codersdk/agentsdk/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestManifest(t *testing.T) {
},
Health: codersdk.WorkspaceAppHealthHealthy,
Hidden: false,
OpenIn: codersdk.WorkspaceAppOpenInSlimWindow,
},
{
ID: uuid.New(),
Expand All @@ -64,6 +65,7 @@ func TestManifest(t *testing.T) {
},
Health: codersdk.WorkspaceAppHealthInitializing,
Hidden: true,
OpenIn: codersdk.WorkspaceAppOpenInTab,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed the test inputs and it passes with no futher changes? Are we not checking for this in the test?
Should we also add a test with an invalid value for OpenIn?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed will add some more tests 👀

},
},
DERPMap: &tailcfg.DERPMap{
Expand Down
16 changes: 11 additions & 5 deletions codersdk/workspaceapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const (
WorkspaceAppSharingLevelPublic WorkspaceAppSharingLevel = "public"
)

var MapWorkspaceAppSharingLevels = map[WorkspaceAppSharingLevel]struct{}{
WorkspaceAppSharingLevelOwner: {},
WorkspaceAppSharingLevelAuthenticated: {},
WorkspaceAppSharingLevelPublic: {},
}

type WorkspaceAppOpenIn string

const (
Expand All @@ -36,10 +42,10 @@ const (
WorkspaceAppOpenInTab WorkspaceAppOpenIn = "tab"
)

var MapWorkspaceAppSharingLevels = map[WorkspaceAppSharingLevel]struct{}{
WorkspaceAppSharingLevelOwner: {},
WorkspaceAppSharingLevelAuthenticated: {},
WorkspaceAppSharingLevelPublic: {},
var MapWorkspaceAppOpenIns = map[WorkspaceAppOpenIn]struct{}{
WorkspaceAppOpenInSlimWindow: {},
WorkspaceAppOpenInWindow: {},
WorkspaceAppOpenInTab: {},
}

type WorkspaceApp struct {
Expand Down Expand Up @@ -70,7 +76,7 @@ type WorkspaceApp struct {
Healthcheck Healthcheck `json:"healthcheck"`
Health WorkspaceAppHealth `json:"health"`
Hidden bool `json:"hidden"`
OpenIn string `json:"open_in"`
OpenIn WorkspaceAppOpenIn `json:"open_in"`
}

type Healthcheck struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/api/agents.md

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

22 changes: 14 additions & 8 deletions docs/reference/api/builds.md

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

Loading
Loading