mirror of
https://github.com/openziti/zrok.git
synced 2025-02-16 18:20:51 +01:00
additional service share/unshare and related naming refactoring (#102)
This commit is contained in:
parent
11068394b8
commit
82d9f6f6ed
@ -103,9 +103,9 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.Token)
|
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.Token)
|
||||||
req := service.NewShareParams()
|
req := service.NewShareParams()
|
||||||
req.Body = &rest_model_zrok.ShareRequest{
|
req.Body = &rest_model_zrok.ShareRequest{
|
||||||
ZID: env.ZId,
|
ZID: env.ZId,
|
||||||
Endpoint: cfg.EndpointAddress,
|
BackendProxyEndpoint: cfg.EndpointAddress,
|
||||||
AuthScheme: string(model.None),
|
AuthScheme: string(model.None),
|
||||||
}
|
}
|
||||||
if len(self.basicAuth) > 0 {
|
if len(self.basicAuth) > 0 {
|
||||||
logrus.Infof("configuring basic auth")
|
logrus.Infof("configuring basic auth")
|
||||||
@ -162,7 +162,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
p := widgets.NewParagraph()
|
p := widgets.NewParagraph()
|
||||||
p.Border = true
|
p.Border = true
|
||||||
p.Title = " access your zrok service "
|
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.TextStyle = ui.Style{Fg: ui.ColorWhite}
|
||||||
p.PaddingTop = 1
|
p.PaddingTop = 1
|
||||||
p.SetRect(5, 5, w-10, 10)
|
p.SetRect(5, 5, w-10, 10)
|
||||||
@ -216,7 +216,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("access your zrok service: %v", resp.Payload.ProxyEndpoint)
|
logrus.Infof("access your zrok service: %v", resp.Payload.FrontendProxyEndpoint)
|
||||||
for {
|
for {
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
}
|
}
|
||||||
|
@ -184,9 +184,9 @@ func (l *looper) startup() {
|
|||||||
l.auth = httptransport.APIKeyAuth("x-token", "header", l.env.Token)
|
l.auth = httptransport.APIKeyAuth("x-token", "header", l.env.Token)
|
||||||
tunnelReq := service.NewShareParams()
|
tunnelReq := service.NewShareParams()
|
||||||
tunnelReq.Body = &rest_model_zrok.ShareRequest{
|
tunnelReq.Body = &rest_model_zrok.ShareRequest{
|
||||||
ZID: l.env.ZId,
|
ZID: l.env.ZId,
|
||||||
Endpoint: fmt.Sprintf("looper#%d", l.id),
|
BackendProxyEndpoint: fmt.Sprintf("looper#%d", l.id),
|
||||||
AuthScheme: string(model.None),
|
AuthScheme: string(model.None),
|
||||||
}
|
}
|
||||||
tunnelReq.SetTimeout(60 * time.Second)
|
tunnelReq.SetTimeout(60 * time.Second)
|
||||||
tunnelResp, err := l.zrok.Service.Share(tunnelReq, l.auth)
|
tunnelResp, err := l.zrok.Service.Share(tunnelReq, l.auth)
|
||||||
@ -194,7 +194,7 @@ func (l *looper) startup() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
l.service = tunnelResp.Payload.SvcName
|
l.service = tunnelResp.Payload.SvcName
|
||||||
l.proxyEndpoint = tunnelResp.Payload.ProxyEndpoint
|
l.proxyEndpoint = tunnelResp.Payload.FrontendProxyEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *looper) dwell() {
|
func (l *looper) dwell() {
|
||||||
|
@ -96,7 +96,7 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_
|
|||||||
ZId: svcZId,
|
ZId: svcZId,
|
||||||
Name: svcName,
|
Name: svcName,
|
||||||
Frontend: frontendUrl,
|
Frontend: frontendUrl,
|
||||||
Backend: params.Body.Endpoint,
|
Backend: params.Body.BackendProxyEndpoint,
|
||||||
}, tx)
|
}, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error creating service record: %v", err)
|
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)
|
logrus.Infof("recorded service '%v' with id '%v' for '%v'", svcName, sid, principal.Email)
|
||||||
|
|
||||||
return service.NewShareCreated().WithPayload(&rest_model_zrok.ShareResponse{
|
return service.NewShareCreated().WithPayload(&rest_model_zrok.ShareResponse{
|
||||||
ProxyEndpoint: frontendUrl,
|
FrontendProxyEndpoint: frontendUrl,
|
||||||
SvcName: svcName,
|
SvcName: svcName,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,11 +7,13 @@ package rest_model_zrok
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-openapi/errors"
|
"github.com/go-openapi/errors"
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
"github.com/go-openapi/swag"
|
"github.com/go-openapi/swag"
|
||||||
|
"github.com/go-openapi/validate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShareRequest share request
|
// ShareRequest share request
|
||||||
@ -25,8 +27,19 @@ type ShareRequest struct {
|
|||||||
// auth users
|
// auth users
|
||||||
AuthUsers []*AuthUser `json:"authUsers"`
|
AuthUsers []*AuthUser `json:"authUsers"`
|
||||||
|
|
||||||
// endpoint
|
// backend mode
|
||||||
Endpoint string `json:"endpoint,omitempty"`
|
// 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
|
// z Id
|
||||||
ZID string `json:"zId,omitempty"`
|
ZID string `json:"zId,omitempty"`
|
||||||
@ -40,6 +53,14 @@ func (m *ShareRequest) Validate(formats strfmt.Registry) error {
|
|||||||
res = append(res, err)
|
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 {
|
if len(res) > 0 {
|
||||||
return errors.CompositeValidationError(res...)
|
return errors.CompositeValidationError(res...)
|
||||||
}
|
}
|
||||||
@ -72,6 +93,93 @@ func (m *ShareRequest) validateAuthUsers(formats strfmt.Registry) error {
|
|||||||
return nil
|
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
|
// ContextValidate validate this share request based on the context it is used
|
||||||
func (m *ShareRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
func (m *ShareRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||||
var res []error
|
var res []error
|
||||||
|
@ -17,8 +17,8 @@ import (
|
|||||||
// swagger:model shareResponse
|
// swagger:model shareResponse
|
||||||
type ShareResponse struct {
|
type ShareResponse struct {
|
||||||
|
|
||||||
// proxy endpoint
|
// frontend proxy endpoint
|
||||||
ProxyEndpoint string `json:"proxyEndpoint,omitempty"`
|
FrontendProxyEndpoint string `json:"frontendProxyEndpoint,omitempty"`
|
||||||
|
|
||||||
// svc name
|
// svc name
|
||||||
SvcName string `json:"svcName,omitempty"`
|
SvcName string `json:"svcName,omitempty"`
|
||||||
|
@ -564,9 +564,30 @@ func init() {
|
|||||||
"$ref": "#/definitions/authUser"
|
"$ref": "#/definitions/authUser"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"endpoint": {
|
"backendMode": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"proxy",
|
||||||
|
"web",
|
||||||
|
"dav"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"backendProxyEndpoint": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"frontendSelection": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"shareMode": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"public",
|
||||||
|
"private"
|
||||||
|
]
|
||||||
|
},
|
||||||
"zId": {
|
"zId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@ -575,7 +596,7 @@ func init() {
|
|||||||
"shareResponse": {
|
"shareResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"proxyEndpoint": {
|
"frontendProxyEndpoint": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"svcName": {
|
"svcName": {
|
||||||
@ -1169,9 +1190,30 @@ func init() {
|
|||||||
"$ref": "#/definitions/authUser"
|
"$ref": "#/definitions/authUser"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"endpoint": {
|
"backendMode": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"proxy",
|
||||||
|
"web",
|
||||||
|
"dav"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"backendProxyEndpoint": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"frontendSelection": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"shareMode": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"public",
|
||||||
|
"private"
|
||||||
|
]
|
||||||
|
},
|
||||||
"zId": {
|
"zId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@ -1180,7 +1222,7 @@ func init() {
|
|||||||
"shareResponse": {
|
"shareResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"proxyEndpoint": {
|
"frontendProxyEndpoint": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"svcName": {
|
"svcName": {
|
||||||
|
@ -364,7 +364,17 @@ definitions:
|
|||||||
properties:
|
properties:
|
||||||
zId:
|
zId:
|
||||||
type: string
|
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
|
type: string
|
||||||
authScheme:
|
authScheme:
|
||||||
type: string
|
type: string
|
||||||
@ -375,7 +385,7 @@ definitions:
|
|||||||
shareResponse:
|
shareResponse:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
proxyEndpoint:
|
frontendProxyEndpoint:
|
||||||
type: string
|
type: string
|
||||||
svcName:
|
svcName:
|
||||||
type: string
|
type: string
|
||||||
|
@ -110,7 +110,10 @@
|
|||||||
* @memberof module:types
|
* @memberof module:types
|
||||||
*
|
*
|
||||||
* @property {string} zId
|
* @property {string} zId
|
||||||
* @property {string} endpoint
|
* @property {string} shareMode
|
||||||
|
* @property {string[]} frontendSelection
|
||||||
|
* @property {string} backendMode
|
||||||
|
* @property {string} backendProxyEndpoint
|
||||||
* @property {string} authScheme
|
* @property {string} authScheme
|
||||||
* @property {module:types.authUser[]} authUsers
|
* @property {module:types.authUser[]} authUsers
|
||||||
*/
|
*/
|
||||||
@ -119,7 +122,7 @@
|
|||||||
* @typedef shareResponse
|
* @typedef shareResponse
|
||||||
* @memberof module:types
|
* @memberof module:types
|
||||||
*
|
*
|
||||||
* @property {string} proxyEndpoint
|
* @property {string} frontendProxyEndpoint
|
||||||
* @property {string} svcName
|
* @property {string} svcName
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user