feat: allow setting port share protocol (#12383)

Co-authored-by: Garrett Delfosse <garrett@coder.com>
This commit is contained in:
Dean Sheather
2024-03-06 09:23:57 -05:00
committed by GitHub
co-authored by Garrett Delfosse
parent 23ff807a27
commit 46a2ff1061
25 changed files with 624 additions and 130 deletions
+18 -7
View File
@@ -13,23 +13,29 @@ const (
WorkspaceAgentPortShareLevelOwner WorkspaceAgentPortShareLevel = "owner"
WorkspaceAgentPortShareLevelAuthenticated WorkspaceAgentPortShareLevel = "authenticated"
WorkspaceAgentPortShareLevelPublic WorkspaceAgentPortShareLevel = "public"
WorkspaceAgentPortShareProtocolHTTP WorkspaceAgentPortShareProtocol = "http"
WorkspaceAgentPortShareProtocolHTTPS WorkspaceAgentPortShareProtocol = "https"
)
type (
WorkspaceAgentPortShareLevel string
WorkspaceAgentPortShareProtocol string
UpsertWorkspaceAgentPortShareRequest struct {
AgentName string `json:"agent_name"`
Port int32 `json:"port"`
ShareLevel WorkspaceAgentPortShareLevel `json:"share_level"`
AgentName string `json:"agent_name"`
Port int32 `json:"port"`
ShareLevel WorkspaceAgentPortShareLevel `json:"share_level" enums:"owner,authenticated,public"`
Protocol WorkspaceAgentPortShareProtocol `json:"protocol" enums:"http,https"`
}
WorkspaceAgentPortShares struct {
Shares []WorkspaceAgentPortShare `json:"shares"`
}
WorkspaceAgentPortShare struct {
WorkspaceID uuid.UUID `json:"workspace_id" format:"uuid"`
AgentName string `json:"agent_name"`
Port int32 `json:"port"`
ShareLevel WorkspaceAgentPortShareLevel `json:"share_level"`
WorkspaceID uuid.UUID `json:"workspace_id" format:"uuid"`
AgentName string `json:"agent_name"`
Port int32 `json:"port"`
ShareLevel WorkspaceAgentPortShareLevel `json:"share_level" enums:"owner,authenticated,public"`
Protocol WorkspaceAgentPortShareProtocol `json:"protocol" enums:"http,https"`
}
DeleteWorkspaceAgentPortShareRequest struct {
AgentName string `json:"agent_name"`
@@ -48,6 +54,11 @@ func (l WorkspaceAgentPortShareLevel) ValidPortShareLevel() bool {
l == WorkspaceAgentPortShareLevelPublic
}
func (p WorkspaceAgentPortShareProtocol) ValidPortProtocol() bool {
return p == WorkspaceAgentPortShareProtocolHTTP ||
p == WorkspaceAgentPortShareProtocolHTTPS
}
func (c *Client) GetWorkspaceAgentPortShares(ctx context.Context, workspaceID uuid.UUID) (WorkspaceAgentPortShares, error) {
var shares WorkspaceAgentPortShares
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/workspaces/%s/port-share", workspaceID), nil)