ham-fisted, manually wired... but working (#967)

This commit is contained in:
Michael Quigley 2025-05-30 12:59:10 -04:00
parent 2cecf14143
commit a7899b3a98
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
11 changed files with 77 additions and 2 deletions

40
controller/agentStatus.go Normal file
View File

@ -0,0 +1,40 @@
package controller
import (
"context"
"github.com/go-openapi/runtime/middleware"
"github.com/openziti/zrok/agent/agentGrpc"
"github.com/openziti/zrok/controller/agentController"
"github.com/openziti/zrok/controller/config"
"github.com/openziti/zrok/rest_model_zrok"
"github.com/openziti/zrok/rest_server_zrok/operations/agent"
"github.com/sirupsen/logrus"
)
type agentStatusHandler struct {
cfg *config.Config
}
func newAgentStatusHandler(cfg *config.Config) *agentStatusHandler {
return &agentStatusHandler{cfg: cfg}
}
func (h *agentStatusHandler) Handle(params agent.AgentStatusParams, principal *rest_model_zrok.Principal) middleware.Responder {
if h.cfg.AgentController != nil {
acli, aconn, err := agentController.NewAgentClient(params.Body.EnvZID, h.cfg.AgentController)
if err != nil {
logrus.Errorf("error creating agent client for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewAgentStatusInternalServerError()
}
defer aconn.Close()
resp, err := acli.Version(context.Background(), &agentGrpc.VersionRequest{})
if err != nil {
logrus.Errorf("error retrieving agent version for '%v' (%v): %v", params.Body.EnvZID, principal.Email, err)
return agent.NewAgentStatusInternalServerError()
}
return agent.NewAgentStatusOK().WithPayload(&agent.AgentStatusOKBody{Version: resp.V})
}
return agent.NewAgentStatusUnauthorized()
}

View File

@ -65,6 +65,7 @@ func Run(inCfg *config.Config) error {
api.AdminListOrganizationsHandler = newListOrganizationsHandler()
api.AdminRemoveOrganizationMemberHandler = newRemoveOrganizationMemberHandler()
api.AdminUpdateFrontendHandler = newUpdateFrontendHandler()
api.AgentAgentStatusHandler = newAgentStatusHandler(cfg)
api.EnvironmentEnableHandler = newEnableHandler()
api.EnvironmentDisableHandler = newDisableHandler()
api.MetadataConfigurationHandler = newConfigurationHandler(cfg)

View File

@ -279,6 +279,9 @@ type AgentStatusOKBody struct {
// shares
Shares []*rest_model_zrok.Share `json:"shares"`
// version
Version string `json:"version,omitempty"`
}
// Validate validates this agent status o k body

View File

@ -219,6 +219,9 @@ func init() {
"items": {
"$ref": "#/definitions/share"
}
},
"version": {
"type": "string"
}
}
}
@ -2577,6 +2580,9 @@ func init() {
"items": {
"$ref": "#/definitions/share"
}
},
"version": {
"type": "string"
}
}
}

View File

@ -119,6 +119,9 @@ type AgentStatusOKBody struct {
// shares
Shares []*rest_model_zrok.Share `json:"shares"`
// version
Version string `json:"version,omitempty"`
}
// Validate validates this agent status o k body

View File

@ -27,6 +27,12 @@ import {
* @interface AgentStatus200Response
*/
export interface AgentStatus200Response {
/**
*
* @type {string}
* @memberof AgentStatus200Response
*/
version?: string;
/**
*
* @type {Array<Share>}
@ -52,6 +58,7 @@ export function AgentStatus200ResponseFromJSONTyped(json: any, ignoreDiscriminat
}
return {
'version': json['version'] == null ? undefined : json['version'],
'shares': json['shares'] == null ? undefined : ((json['shares'] as Array<any>).map(ShareFromJSON)),
};
}
@ -67,6 +74,7 @@ export function AgentStatus200ResponseToJSONTyped(value?: AgentStatus200Response
return {
'version': value['version'],
'shares': value['shares'] == null ? undefined : ((value['shares'] as Array<any>).map(ShareToJSON)),
};
}

View File

@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**version** | **str** | | [optional]
**shares** | [**List[Share]**](Share.md) | | [optional]
## Example

View File

@ -35,6 +35,7 @@ class TestAgentStatus200Response(unittest.TestCase):
model = AgentStatus200Response()
if include_optional:
return AgentStatus200Response(
version = '',
shares = [
zrok_api.models.share.share(
share_token = '',

View File

@ -17,7 +17,7 @@ import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from zrok_api.models.share import Share
from typing import Optional, Set
@ -27,8 +27,9 @@ class AgentStatus200Response(BaseModel):
"""
AgentStatus200Response
""" # noqa: E501
version: Optional[StrictStr] = None
shares: Optional[List[Share]] = None
__properties: ClassVar[List[str]] = ["shares"]
__properties: ClassVar[List[str]] = ["version", "shares"]
model_config = ConfigDict(
populate_by_name=True,
@ -88,6 +89,7 @@ class AgentStatus200Response(BaseModel):
return cls.model_validate(obj)
_obj = cls.model_validate({
"version": obj.get("version"),
"shares": [Share.from_dict(_item) for _item in obj["shares"]] if obj.get("shares") is not None else None
})
return _obj

View File

@ -635,6 +635,8 @@ paths:
description: ok
schema:
properties:
version:
type: string
shares:
type: array
items:

View File

@ -27,6 +27,12 @@ import {
* @interface AgentStatus200Response
*/
export interface AgentStatus200Response {
/**
*
* @type {string}
* @memberof AgentStatus200Response
*/
version?: string;
/**
*
* @type {Array<Share>}
@ -52,6 +58,7 @@ export function AgentStatus200ResponseFromJSONTyped(json: any, ignoreDiscriminat
}
return {
'version': json['version'] == null ? undefined : json['version'],
'shares': json['shares'] == null ? undefined : ((json['shares'] as Array<any>).map(ShareFromJSON)),
};
}
@ -67,6 +74,7 @@ export function AgentStatus200ResponseToJSONTyped(value?: AgentStatus200Response
return {
'version': value['version'],
'shares': value['shares'] == null ? undefined : ((value['shares'] as Array<any>).map(ShareToJSON)),
};
}