mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
basic service reservation support (#41)
This commit is contained in:
parent
37be8fc4e0
commit
158cc42c07
@ -184,7 +184,7 @@ 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,
|
||||
EnvZID: l.env.ZId,
|
||||
ShareMode: "public",
|
||||
BackendMode: "proxy",
|
||||
BackendProxyEndpoint: fmt.Sprintf("looper#%d", l.id),
|
||||
@ -195,7 +195,7 @@ func (l *looper) startup() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
l.service = tunnelResp.Payload.SvcName
|
||||
l.service = tunnelResp.Payload.SvcToken
|
||||
l.proxyEndpoint = tunnelResp.Payload.FrontendProxyEndpoint
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ func (cmd *sharePrivateCommand) 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,
|
||||
EnvZID: env.ZId,
|
||||
ShareMode: "private",
|
||||
BackendMode: "proxy",
|
||||
BackendProxyEndpoint: cfg.EndpointAddress,
|
||||
@ -110,7 +110,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
cfg.Service = resp.Payload.SvcName
|
||||
cfg.Service = resp.Payload.SvcToken
|
||||
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
@ -138,7 +138,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
}()
|
||||
|
||||
logrus.Infof("share your zrok service; use this command for access: 'zrok access private %v'", resp.Payload.SvcName)
|
||||
logrus.Infof("share your zrok service; use this command for access: 'zrok access private %v'", resp.Payload.SvcToken)
|
||||
|
||||
for {
|
||||
time.Sleep(30 * time.Second)
|
||||
|
@ -102,7 +102,7 @@ func (self *sharePublicCommand) 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,
|
||||
EnvZID: env.ZId,
|
||||
ShareMode: "public",
|
||||
BackendMode: "proxy",
|
||||
BackendProxyEndpoint: cfg.EndpointAddress,
|
||||
@ -128,7 +128,7 @@ func (self *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
cfg.Service = resp.Payload.SvcName
|
||||
cfg.Service = resp.Payload.SvcToken
|
||||
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
@ -22,7 +22,7 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_
|
||||
}
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
envZId := params.Body.ZID
|
||||
envZId := params.Body.EnvZID
|
||||
envId := 0
|
||||
if envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx); err == nil {
|
||||
found := false
|
||||
@ -48,7 +48,7 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_
|
||||
logrus.Error(err)
|
||||
return service.NewShareInternalServerError()
|
||||
}
|
||||
svcName, err := createServiceName()
|
||||
svcToken, err := createServiceToken()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return service.NewShareInternalServerError()
|
||||
@ -58,14 +58,14 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_
|
||||
var frontendEndpoints []string
|
||||
switch params.Body.ShareMode {
|
||||
case "public":
|
||||
svcZId, frontendEndpoints, err = newPublicResourceAllocator().allocate(envZId, svcName, params, edge)
|
||||
svcZId, frontendEndpoints, err = newPublicResourceAllocator().allocate(envZId, svcToken, params, edge)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return service.NewShareInternalServerError()
|
||||
}
|
||||
|
||||
case "private":
|
||||
svcZId, frontendEndpoints, err = newPrivateResourceAllocator().allocate(envZId, svcName, params, edge)
|
||||
svcZId, frontendEndpoints, err = newPrivateResourceAllocator().allocate(envZId, svcToken, params, edge)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return service.NewShareInternalServerError()
|
||||
@ -76,15 +76,20 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_
|
||||
return service.NewShareInternalServerError()
|
||||
}
|
||||
|
||||
logrus.Debugf("allocated service '%v'", svcName)
|
||||
logrus.Debugf("allocated service '%v'", svcToken)
|
||||
|
||||
reserved := false
|
||||
if params.Body.Reserve {
|
||||
reserved = true
|
||||
}
|
||||
sid, err := str.CreateService(envId, &store.Service{
|
||||
ZId: svcZId,
|
||||
Name: svcName,
|
||||
Name: svcToken,
|
||||
ShareMode: params.Body.ShareMode,
|
||||
BackendMode: params.Body.BackendMode,
|
||||
FrontendEndpoint: &frontendEndpoints[0],
|
||||
BackendProxyEndpoint: ¶ms.Body.BackendProxyEndpoint,
|
||||
Reserved: reserved,
|
||||
}, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error creating service record: %v", err)
|
||||
@ -95,10 +100,10 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_
|
||||
logrus.Errorf("error committing service record: %v", err)
|
||||
return service.NewShareInternalServerError()
|
||||
}
|
||||
logrus.Infof("recorded service '%v' with id '%v' for '%v'", svcName, sid, principal.Email)
|
||||
logrus.Infof("recorded service '%v' with id '%v' for '%v'", svcToken, sid, principal.Email)
|
||||
|
||||
return service.NewShareCreated().WithPayload(&rest_model_zrok.ShareResponse{
|
||||
FrontendProxyEndpoint: frontendEndpoints[0],
|
||||
SvcName: svcName,
|
||||
SvcToken: svcToken,
|
||||
})
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func edgeClient() (*rest_management_api_client.ZitiEdgeManagement, error) {
|
||||
return rest_util.NewEdgeManagementClientWithUpdb(cfg.Ziti.Username, cfg.Ziti.Password, cfg.Ziti.ApiEndpoint, caPool)
|
||||
}
|
||||
|
||||
func createServiceName() (string, error) {
|
||||
func createServiceToken() (string, error) {
|
||||
gen, err := nanoid.CustomASCII("abcdefghijklmnopqrstuvwxyz0123456789", 12)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -34,15 +34,18 @@ type ShareRequest struct {
|
||||
// backend proxy endpoint
|
||||
BackendProxyEndpoint string `json:"backendProxyEndpoint,omitempty"`
|
||||
|
||||
// env z Id
|
||||
EnvZID string `json:"envZId,omitempty"`
|
||||
|
||||
// frontend selection
|
||||
FrontendSelection []string `json:"frontendSelection"`
|
||||
|
||||
// reserve
|
||||
Reserve bool `json:"reserve,omitempty"`
|
||||
|
||||
// share mode
|
||||
// Enum: [public private]
|
||||
ShareMode string `json:"shareMode,omitempty"`
|
||||
|
||||
// z Id
|
||||
ZID string `json:"zId,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this share request
|
||||
|
@ -20,8 +20,8 @@ type ShareResponse struct {
|
||||
// frontend proxy endpoint
|
||||
FrontendProxyEndpoint string `json:"frontendProxyEndpoint,omitempty"`
|
||||
|
||||
// svc name
|
||||
SvcName string `json:"svcName,omitempty"`
|
||||
// svc token
|
||||
SvcToken string `json:"svcToken,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this share response
|
||||
|
@ -669,21 +669,24 @@ func init() {
|
||||
"backendProxyEndpoint": {
|
||||
"type": "string"
|
||||
},
|
||||
"envZId": {
|
||||
"type": "string"
|
||||
},
|
||||
"frontendSelection": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"reserve": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"shareMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"public",
|
||||
"private"
|
||||
]
|
||||
},
|
||||
"zId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -693,7 +696,7 @@ func init() {
|
||||
"frontendProxyEndpoint": {
|
||||
"type": "string"
|
||||
},
|
||||
"svcName": {
|
||||
"svcToken": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
@ -1403,21 +1406,24 @@ func init() {
|
||||
"backendProxyEndpoint": {
|
||||
"type": "string"
|
||||
},
|
||||
"envZId": {
|
||||
"type": "string"
|
||||
},
|
||||
"frontendSelection": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"reserve": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"shareMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"public",
|
||||
"private"
|
||||
]
|
||||
},
|
||||
"zId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1427,7 +1433,7 @@ func init() {
|
||||
"frontendProxyEndpoint": {
|
||||
"type": "string"
|
||||
},
|
||||
"svcName": {
|
||||
"svcToken": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
|
@ -323,10 +323,6 @@ definitions:
|
||||
identity:
|
||||
type: string
|
||||
|
||||
environments:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/environment"
|
||||
environment:
|
||||
type: object
|
||||
properties:
|
||||
@ -345,10 +341,16 @@ definitions:
|
||||
updatedAt:
|
||||
type: integer
|
||||
|
||||
environments:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/environment"
|
||||
|
||||
environmentServicesList:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/environmentServices"
|
||||
|
||||
environmentServices:
|
||||
type: object
|
||||
properties:
|
||||
@ -367,6 +369,7 @@ definitions:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
|
||||
loginResponse:
|
||||
type: string
|
||||
|
||||
@ -387,16 +390,13 @@ definitions:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
|
||||
registerResponse:
|
||||
type: object
|
||||
properties:
|
||||
token:
|
||||
type: string
|
||||
|
||||
services:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/service"
|
||||
service:
|
||||
type: object
|
||||
properties:
|
||||
@ -415,6 +415,11 @@ definitions:
|
||||
updatedAt:
|
||||
type: integer
|
||||
|
||||
services:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/service"
|
||||
|
||||
serviceMetrics:
|
||||
type: array
|
||||
items:
|
||||
@ -423,7 +428,7 @@ definitions:
|
||||
shareRequest:
|
||||
type: object
|
||||
properties:
|
||||
zId:
|
||||
envZId:
|
||||
type: string
|
||||
shareMode:
|
||||
type: string
|
||||
@ -443,12 +448,15 @@ definitions:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/authUser"
|
||||
reserve:
|
||||
type: boolean
|
||||
|
||||
shareResponse:
|
||||
type: object
|
||||
properties:
|
||||
frontendProxyEndpoint:
|
||||
type: string
|
||||
svcName:
|
||||
svcToken:
|
||||
type: string
|
||||
|
||||
unaccessRequest:
|
||||
|
@ -124,13 +124,14 @@
|
||||
* @typedef shareRequest
|
||||
* @memberof module:types
|
||||
*
|
||||
* @property {string} zId
|
||||
* @property {string} envZId
|
||||
* @property {string} shareMode
|
||||
* @property {string[]} frontendSelection
|
||||
* @property {string} backendMode
|
||||
* @property {string} backendProxyEndpoint
|
||||
* @property {string} authScheme
|
||||
* @property {module:types.authUser[]} authUsers
|
||||
* @property {boolean} reserve
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -138,7 +139,7 @@
|
||||
* @memberof module:types
|
||||
*
|
||||
* @property {string} frontendProxyEndpoint
|
||||
* @property {string} svcName
|
||||
* @property {string} svcToken
|
||||
*/
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user