elaboration

This commit is contained in:
Michael Quigley 2022-08-03 14:25:27 -04:00
parent aceb649fa7
commit 2d94591812
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
17 changed files with 250 additions and 26 deletions

View File

@ -1,14 +1,18 @@
package main
import (
"fmt"
httptransport "github.com/go-openapi/runtime/client"
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/identity"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/shirou/gopsutil/v3/host"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
enableCmd.Flags().StringVarP(&enableDescription, "description", "d", "", "Description of this environment")
rootCmd.AddCommand(enableCmd)
}
@ -18,13 +22,23 @@ var enableCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: enable,
}
var enableDescription string
func enable(_ *cobra.Command, args []string) {
token := args[0]
thisHost, err := getHost()
if err != nil {
panic(err)
}
zrok := newZrokClient()
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
req := identity.NewEnableParams()
req.Body = &rest_model_zrok.EnableRequest{
Description: enableDescription,
Host: thisHost,
}
resp, err := zrok.Identity.Enable(req, auth)
if err != nil {
panic(err)
@ -40,3 +54,13 @@ func enable(_ *cobra.Command, args []string) {
}
logrus.Infof("enabled, identity = '%v'", resp.Payload.Identity)
}
func getHost() (string, error) {
info, err := host.Info()
if err != nil {
return "", err
}
thisHost := fmt.Sprintf("%v; %v; %v; %v; %v; %v; %v",
info.Hostname, info.OS, info.Platform, info.PlatformFamily, info.PlatformVersion, info.KernelVersion, info.KernelArch)
return thisHost, nil
}

View File

@ -15,6 +15,10 @@ import (
"syscall"
)
func init() {
rootCmd.AddCommand(httpCmd)
}
var httpCmd = &cobra.Command{
Use: "http <endpoint>",
Short: "Start an http terminator",
@ -44,8 +48,8 @@ func handleHttp(_ *cobra.Command, args []string) {
auth := httptransport.APIKeyAuth("X-TOKEN", "header", token)
req := tunnel.NewTunnelParams()
req.Body = &rest_model_zrok.TunnelRequest{
Endpoint: cfg.EndpointAddress,
Identity: id,
ZitiIdentityID: id,
Endpoint: cfg.EndpointAddress,
}
resp, err := zrok.Tunnel.Tunnel(req, auth)
if err != nil {

View File

@ -13,7 +13,6 @@ func init() {
pfxlog.GlobalInit(logrus.InfoLevel, pfxlog.DefaultOptions().SetTrimPrefix("github.com/openziti-test-kitchen/"))
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
rootCmd.PersistentFlags().StringVarP(&endpoint, "endpoint", "e", "localhost:10888", "zrok endpoint address")
rootCmd.AddCommand(httpCmd)
}
var rootCmd = &cobra.Command{

View File

@ -15,6 +15,7 @@ import (
sdk_config "github.com/openziti/sdk-golang/ziti/config"
"github.com/openziti/sdk-golang/ziti/enroll"
"github.com/sirupsen/logrus"
"strings"
"time"
)
@ -42,7 +43,14 @@ func enableHandler(params identity.EnableParams, principal *rest_model_zrok.Prin
return identity.NewEnableInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
iid, err := str.CreateEnvironment(int(principal.ID), &store.Environment{ZitiIdentityId: ident.Payload.Data.ID}, tx)
addrTokens := strings.Split(params.HTTPRequest.RemoteAddr, ":")
addr := addrTokens[0]
envId, err := str.CreateEnvironment(int(principal.ID), &store.Environment{
Description: params.Body.Description,
Host: params.Body.Host,
Address: addr,
ZitiIdentityId: ident.Payload.Data.ID,
}, tx)
if err != nil {
logrus.Errorf("error storing created identity: %v", err)
_ = tx.Rollback()
@ -52,7 +60,7 @@ func enableHandler(params identity.EnableParams, principal *rest_model_zrok.Prin
logrus.Errorf("error committing: %v", err)
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
logrus.Infof("recorded identity '%v' with id '%v' for '%v'", ident.Payload.Data.ID, iid, principal.Username)
logrus.Infof("recorded identity '%v' with id '%v' for '%v'", ident.Payload.Data.ID, envId, principal.Username)
resp := identity.NewEnableCreated().WithPayload(&rest_model_zrok.EnableResponse{
Identity: ident.Payload.Data.ID,

View File

@ -22,6 +22,9 @@ func listEnvironmentsHandler(_ metadata.ListEnvironmentsParams, principal *rest_
var out rest_model_zrok.Environments
for _, env := range envs {
out = append(out, &rest_model_zrok.Environment{
Description: env.Description,
Host: env.Host,
Address: env.Address,
Active: env.Active,
CreatedAt: env.CreatedAt.String(),
UpdatedAt: env.UpdatedAt.String(),

View File

@ -27,7 +27,7 @@ func tunnelHandler(params tunnel.TunnelParams, principal *rest_model_zrok.Princi
}
defer func() { _ = tx.Rollback() }()
envId := params.Body.Identity
envId := params.Body.ZitiIdentityID
if envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx); err == nil {
found := false
for _, env := range envs {
@ -80,7 +80,10 @@ func tunnelHandler(params tunnel.TunnelParams, principal *rest_model_zrok.Princi
logrus.Infof("allocated service '%v'", svcName)
sid, err := str.CreateService(int(principal.ID), &store.Service{ZitiServiceId: svcId, Endpoint: params.Body.Endpoint}, tx)
sid, err := str.CreateService(int(principal.ID), &store.Service{
ZitiServiceId: svcId,
Endpoint: params.Body.Endpoint,
}, tx)
if err != nil {
logrus.Errorf("error creating service record: %v", err)
_ = tx.Rollback()

2
go.mod
View File

@ -60,7 +60,7 @@ require (
github.com/parallaxsecond/parsec-client-go v0.0.0-20220111122524-cb78842db373 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/shirou/gopsutil/v3 v3.22.6 // indirect
github.com/shirou/gopsutil/v3 v3.22.7 // indirect
github.com/speps/go-hashids v2.0.0+incompatible // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect

2
go.sum
View File

@ -431,6 +431,8 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shirou/gopsutil/v3 v3.22.6 h1:FnHOFOh+cYAM0C30P+zysPISzlknLC5Z1G4EAElznfQ=
github.com/shirou/gopsutil/v3 v3.22.6/go.mod h1:EdIubSnZhbAvBS1yJ7Xi+AShB/hxwLHOMz4MCYz7yMs=
github.com/shirou/gopsutil/v3 v3.22.7 h1:flKnuCMfUUrO+oAvwAd6GKZgnPzr098VA/UJ14nhJd4=
github.com/shirou/gopsutil/v3 v3.22.7/go.mod h1:s648gW4IywYzUfE/KjXxUsqrqx/T2xO5VqOXxONeRfI=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=

View File

@ -14,6 +14,8 @@ import (
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
)
// NewEnableParams creates a new EnableParams object,
@ -58,6 +60,10 @@ func NewEnableParamsWithHTTPClient(client *http.Client) *EnableParams {
Typically these are written to a http.Request.
*/
type EnableParams struct {
// Body.
Body *rest_model_zrok.EnableRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
@ -111,6 +117,17 @@ func (o *EnableParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the enable params
func (o *EnableParams) WithBody(body *rest_model_zrok.EnableRequest) *EnableParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the enable params
func (o *EnableParams) SetBody(body *rest_model_zrok.EnableRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *EnableParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
@ -118,6 +135,11 @@ func (o *EnableParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Regist
return err
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)

View File

@ -0,0 +1,53 @@
// Code generated by go-swagger; DO NOT EDIT.
package rest_model_zrok
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// EnableRequest enable request
//
// swagger:model enableRequest
type EnableRequest struct {
// description
Description string `json:"description,omitempty"`
// host
Host string `json:"host,omitempty"`
}
// Validate validates this enable request
func (m *EnableRequest) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this enable request based on context it is used
func (m *EnableRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *EnableRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *EnableRequest) UnmarshalBinary(b []byte) error {
var res EnableRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@ -20,8 +20,8 @@ type TunnelRequest struct {
// endpoint
Endpoint string `json:"endpoint,omitempty"`
// identity
Identity string `json:"identity,omitempty"`
// ziti identity Id
ZitiIdentityID string `json:"zitiIdentityId,omitempty"`
}
// Validate validates this tunnel request

View File

@ -83,6 +83,15 @@ func init() {
"identity"
],
"operationId": "enable",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/enableRequest"
}
}
],
"responses": {
"201": {
"description": "environment enabled",
@ -278,6 +287,17 @@ func init() {
}
}
},
"enableRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"host": {
"type": "string"
}
}
},
"enableResponse": {
"type": "object",
"properties": {
@ -358,7 +378,7 @@ func init() {
"endpoint": {
"type": "string"
},
"identity": {
"zitiIdentityId": {
"type": "string"
}
}
@ -457,6 +477,15 @@ func init() {
"identity"
],
"operationId": "enable",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/enableRequest"
}
}
],
"responses": {
"201": {
"description": "environment enabled",
@ -652,6 +681,17 @@ func init() {
}
}
},
"enableRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"host": {
"type": "string"
}
}
},
"enableResponse": {
"type": "object",
"properties": {
@ -732,7 +772,7 @@ func init() {
"endpoint": {
"type": "string"
},
"identity": {
"zitiIdentityId": {
"type": "string"
}
}

View File

@ -6,10 +6,15 @@ package identity
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/validate"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
)
// NewEnableParams creates a new EnableParams object
@ -28,6 +33,11 @@ type EnableParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
In: body
*/
Body *rest_model_zrok.EnableRequest
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
@ -39,6 +49,27 @@ func (o *EnableParams) BindRequest(r *http.Request, route *middleware.MatchedRou
o.HTTPRequest = r
if runtime.HasBody(r) {
defer r.Body.Close()
var body rest_model_zrok.EnableRequest
if err := route.Consumer.Consume(r.Body, &body); err != nil {
res = append(res, errors.NewParseError("body", "body", "", err))
} else {
// validate body object
if err := body.Validate(route.Formats); err != nil {
res = append(res, err)
}
ctx := validate.WithOperationRequest(context.Background())
if err := body.ContextValidate(ctx, route.Formats); err != nil {
res = append(res, err)
}
if len(res) == 0 {
o.Body = &body
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}

View File

@ -43,6 +43,11 @@ paths:
security:
- key: []
operationId: enable
parameters:
- name: body
in: body
schema:
$ref: "#/definitions/enableRequest"
responses:
201:
description: environment enabled
@ -165,6 +170,13 @@ definitions:
token:
type: string
enableRequest:
type: object
properties:
description:
type: string
host:
type: string
enableResponse:
type: object
properties:
@ -221,7 +233,7 @@ definitions:
tunnelRequest:
type: object
properties:
identity:
zitiIdentityId:
type: string
endpoint:
type: string

View File

@ -6,6 +6,21 @@ const Environments = (props) => {
const [environments, setEnvironments] = useState([])
const columns = [
{
name: 'Host',
selector: row => row.host,
sortable: true,
},
{
name: 'Address',
selector: row => row.address,
sortable: true,
},
{
name: 'Description',
selector: row => row.description,
sortable: true,
},
{
name: 'Ziti Identity',
selector: row => row.zitiIdentityId,
@ -16,16 +31,6 @@ const Environments = (props) => {
selector: row => row.active ? 'Active' : 'Inactive',
sortable: true,
},
{
name: 'Created At',
selector: row => row.createdAt,
sortable: true,
},
{
name: 'Updated At',
selector: row => row.updatedAt,
sortable: true,
}
]
useEffect(() => {

View File

@ -18,9 +18,18 @@ export function createAccount(options) {
}
/**
* @param {object} options Optional options
* @param {module:types.enableRequest} [options.body]
* @return {Promise<module:types.enableResponse>} environment enabled
*/
export function enable() {
return gateway.request(enableOperation)
export function enable(options) {
if (!options) options = {}
const parameters = {
body: {
body: options.body
}
}
return gateway.request(enableOperation, parameters)
}
/**
@ -46,6 +55,7 @@ const createAccountOperation = {
const enableOperation = {
path: '/enable',
contentTypes: ['application/zrok.v1+json'],
method: 'post',
security: [
{

View File

@ -16,6 +16,14 @@
* @property {string} token
*/
/**
* @typedef enableRequest
* @memberof module:types
*
* @property {string} description
* @property {string} host
*/
/**
* @typedef enableResponse
* @memberof module:types
@ -58,7 +66,7 @@
* @typedef tunnelRequest
* @memberof module:types
*
* @property {string} identity
* @property {string} zitiIdentityId
* @property {string} endpoint
*/