additional service share/unshare and related naming refactoring (#102)

This commit is contained in:
Michael Quigley 2022-11-18 15:48:13 -05:00
parent 11068394b8
commit 82d9f6f6ed
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
8 changed files with 187 additions and 24 deletions

View File

@ -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)
}

View File

@ -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() {

View File

@ -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,
})
}

View File

@ -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

View File

@ -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"`

View File

@ -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": {

View File

@ -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

View File

@ -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
*/