diff --git a/cmd/zrok/http_backend.go b/cmd/zrok/http_backend.go index af4cb9d8..20c75c2f 100644 --- a/cmd/zrok/http_backend.go +++ b/cmd/zrok/http_backend.go @@ -103,9 +103,9 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) { auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.Token) req := service.NewShareParams() req.Body = &rest_model_zrok.ShareRequest{ - ZID: env.ZId, - Endpoint: cfg.EndpointAddress, - AuthScheme: string(model.None), + ZID: env.ZId, + BackendProxyEndpoint: cfg.EndpointAddress, + AuthScheme: string(model.None), } if len(self.basicAuth) > 0 { logrus.Infof("configuring basic auth") @@ -162,7 +162,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) { p := widgets.NewParagraph() p.Border = true p.Title = " access your zrok service " - p.Text = fmt.Sprintf("%v%v", strings.Repeat(" ", (((w-12)-len(resp.Payload.ProxyEndpoint))/2)-1), resp.Payload.ProxyEndpoint) + p.Text = fmt.Sprintf("%v%v", strings.Repeat(" ", (((w-12)-len(resp.Payload.FrontendProxyEndpoint))/2)-1), resp.Payload.FrontendProxyEndpoint) p.TextStyle = ui.Style{Fg: ui.ColorWhite} p.PaddingTop = 1 p.SetRect(5, 5, w-10, 10) @@ -216,7 +216,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) { } } } else { - logrus.Infof("access your zrok service: %v", resp.Payload.ProxyEndpoint) + logrus.Infof("access your zrok service: %v", resp.Payload.FrontendProxyEndpoint) for { time.Sleep(30 * time.Second) } diff --git a/cmd/zrok/loop.go b/cmd/zrok/loop.go index c843ae5a..3cd4b291 100644 --- a/cmd/zrok/loop.go +++ b/cmd/zrok/loop.go @@ -184,9 +184,9 @@ func (l *looper) startup() { l.auth = httptransport.APIKeyAuth("x-token", "header", l.env.Token) tunnelReq := service.NewShareParams() tunnelReq.Body = &rest_model_zrok.ShareRequest{ - ZID: l.env.ZId, - Endpoint: fmt.Sprintf("looper#%d", l.id), - AuthScheme: string(model.None), + ZID: l.env.ZId, + BackendProxyEndpoint: fmt.Sprintf("looper#%d", l.id), + AuthScheme: string(model.None), } tunnelReq.SetTimeout(60 * time.Second) tunnelResp, err := l.zrok.Service.Share(tunnelReq, l.auth) @@ -194,7 +194,7 @@ func (l *looper) startup() { panic(err) } l.service = tunnelResp.Payload.SvcName - l.proxyEndpoint = tunnelResp.Payload.ProxyEndpoint + l.proxyEndpoint = tunnelResp.Payload.FrontendProxyEndpoint } func (l *looper) dwell() { diff --git a/controller/share.go b/controller/share.go index fe28530b..42be8be5 100644 --- a/controller/share.go +++ b/controller/share.go @@ -96,7 +96,7 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_ ZId: svcZId, Name: svcName, Frontend: frontendUrl, - Backend: params.Body.Endpoint, + Backend: params.Body.BackendProxyEndpoint, }, tx) if err != nil { logrus.Errorf("error creating service record: %v", err) @@ -110,8 +110,8 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_ logrus.Infof("recorded service '%v' with id '%v' for '%v'", svcName, sid, principal.Email) return service.NewShareCreated().WithPayload(&rest_model_zrok.ShareResponse{ - ProxyEndpoint: frontendUrl, - SvcName: svcName, + FrontendProxyEndpoint: frontendUrl, + SvcName: svcName, }) } diff --git a/rest_model_zrok/share_request.go b/rest_model_zrok/share_request.go index fbb6f36c..d561448e 100644 --- a/rest_model_zrok/share_request.go +++ b/rest_model_zrok/share_request.go @@ -7,11 +7,13 @@ package rest_model_zrok import ( "context" + "encoding/json" "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" + "github.com/go-openapi/validate" ) // ShareRequest share request @@ -25,8 +27,19 @@ type ShareRequest struct { // auth users AuthUsers []*AuthUser `json:"authUsers"` - // endpoint - Endpoint string `json:"endpoint,omitempty"` + // backend mode + // Enum: [proxy web dav] + BackendMode string `json:"backendMode,omitempty"` + + // backend proxy endpoint + BackendProxyEndpoint string `json:"backendProxyEndpoint,omitempty"` + + // frontend selection + FrontendSelection []string `json:"frontendSelection"` + + // share mode + // Enum: [public private] + ShareMode string `json:"shareMode,omitempty"` // z Id ZID string `json:"zId,omitempty"` @@ -40,6 +53,14 @@ func (m *ShareRequest) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateBackendMode(formats); err != nil { + res = append(res, err) + } + + if err := m.validateShareMode(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -72,6 +93,93 @@ func (m *ShareRequest) validateAuthUsers(formats strfmt.Registry) error { return nil } +var shareRequestTypeBackendModePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["proxy","web","dav"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + shareRequestTypeBackendModePropEnum = append(shareRequestTypeBackendModePropEnum, v) + } +} + +const ( + + // ShareRequestBackendModeProxy captures enum value "proxy" + ShareRequestBackendModeProxy string = "proxy" + + // ShareRequestBackendModeWeb captures enum value "web" + ShareRequestBackendModeWeb string = "web" + + // ShareRequestBackendModeDav captures enum value "dav" + ShareRequestBackendModeDav string = "dav" +) + +// prop value enum +func (m *ShareRequest) validateBackendModeEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, shareRequestTypeBackendModePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *ShareRequest) validateBackendMode(formats strfmt.Registry) error { + if swag.IsZero(m.BackendMode) { // not required + return nil + } + + // value enum + if err := m.validateBackendModeEnum("backendMode", "body", m.BackendMode); err != nil { + return err + } + + return nil +} + +var shareRequestTypeShareModePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["public","private"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + shareRequestTypeShareModePropEnum = append(shareRequestTypeShareModePropEnum, v) + } +} + +const ( + + // ShareRequestShareModePublic captures enum value "public" + ShareRequestShareModePublic string = "public" + + // ShareRequestShareModePrivate captures enum value "private" + ShareRequestShareModePrivate string = "private" +) + +// prop value enum +func (m *ShareRequest) validateShareModeEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, shareRequestTypeShareModePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *ShareRequest) validateShareMode(formats strfmt.Registry) error { + if swag.IsZero(m.ShareMode) { // not required + return nil + } + + // value enum + if err := m.validateShareModeEnum("shareMode", "body", m.ShareMode); err != nil { + return err + } + + return nil +} + // ContextValidate validate this share request based on the context it is used func (m *ShareRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error diff --git a/rest_model_zrok/share_response.go b/rest_model_zrok/share_response.go index f4140ce7..9eea7d8d 100644 --- a/rest_model_zrok/share_response.go +++ b/rest_model_zrok/share_response.go @@ -17,8 +17,8 @@ import ( // swagger:model shareResponse type ShareResponse struct { - // proxy endpoint - ProxyEndpoint string `json:"proxyEndpoint,omitempty"` + // frontend proxy endpoint + FrontendProxyEndpoint string `json:"frontendProxyEndpoint,omitempty"` // svc name SvcName string `json:"svcName,omitempty"` diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index 28fc89ac..9d894b2d 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -564,9 +564,30 @@ func init() { "$ref": "#/definitions/authUser" } }, - "endpoint": { + "backendMode": { + "type": "string", + "enum": [ + "proxy", + "web", + "dav" + ] + }, + "backendProxyEndpoint": { "type": "string" }, + "frontendSelection": { + "type": "array", + "items": { + "type": "string" + } + }, + "shareMode": { + "type": "string", + "enum": [ + "public", + "private" + ] + }, "zId": { "type": "string" } @@ -575,7 +596,7 @@ func init() { "shareResponse": { "type": "object", "properties": { - "proxyEndpoint": { + "frontendProxyEndpoint": { "type": "string" }, "svcName": { @@ -1169,9 +1190,30 @@ func init() { "$ref": "#/definitions/authUser" } }, - "endpoint": { + "backendMode": { + "type": "string", + "enum": [ + "proxy", + "web", + "dav" + ] + }, + "backendProxyEndpoint": { "type": "string" }, + "frontendSelection": { + "type": "array", + "items": { + "type": "string" + } + }, + "shareMode": { + "type": "string", + "enum": [ + "public", + "private" + ] + }, "zId": { "type": "string" } @@ -1180,7 +1222,7 @@ func init() { "shareResponse": { "type": "object", "properties": { - "proxyEndpoint": { + "frontendProxyEndpoint": { "type": "string" }, "svcName": { diff --git a/specs/zrok.yml b/specs/zrok.yml index ab27349c..3386f1a7 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -364,7 +364,17 @@ definitions: properties: zId: type: string - endpoint: + shareMode: + type: string + enum: ["public", "private"] + frontendSelection: + type: array + items: + type: string + backendMode: + type: string + enum: ["proxy", "web", "dav"] + backendProxyEndpoint: type: string authScheme: type: string @@ -375,7 +385,7 @@ definitions: shareResponse: type: object properties: - proxyEndpoint: + frontendProxyEndpoint: type: string svcName: type: string diff --git a/ui/src/api/types.js b/ui/src/api/types.js index 6bf666e1..1dfafaad 100644 --- a/ui/src/api/types.js +++ b/ui/src/api/types.js @@ -110,7 +110,10 @@ * @memberof module:types * * @property {string} zId - * @property {string} endpoint + * @property {string} shareMode + * @property {string[]} frontendSelection + * @property {string} backendMode + * @property {string} backendProxyEndpoint * @property {string} authScheme * @property {module:types.authUser[]} authUsers */ @@ -119,7 +122,7 @@ * @typedef shareResponse * @memberof module:types * - * @property {string} proxyEndpoint + * @property {string} frontendProxyEndpoint * @property {string} svcName */