Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/v2/V2_docs.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/api/v2/V2_swagger.json

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions docs/api/v2/V2_swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,30 @@ components:
description: Zone is the name of the zone where the host is located.
type: string
type: object
body.HostVerboseRead:
properties:
deactivatedUntil:
type: string
displayName:
type: string
enabled:
type: boolean
ip:
type: string
lastSeenAt:
type: string
name:
type: string
port:
type: integer
registeredAt:
type: string
schedulable:
type: boolean
zone:
description: Zone is the name of the zone where the host is located.
type: string
type: object
body.HttpProxyCreate:
properties:
customDomain:
Expand Down Expand Up @@ -2437,6 +2461,36 @@ paths:
summary: List Hosts
tags:
- Host
/v2/hosts/verbose:
get:
description: List Hosts verbose
responses:
"200":
content:
application/json:
schema:
items:
$ref: '#/components/schemas/body.HostVerboseRead'
type: array
description: OK
"403":
content:
application/json:
schema:
$ref: '#/components/schemas/sys.ErrorResponse'
description: Forbidden
"500":
content:
application/json:
schema:
$ref: '#/components/schemas/sys.ErrorResponse'
description: Internal Server Error
security:
- ApiKeyAuth: []
- KeycloakOAuth: []
summary: List Hosts verbose
tags:
- Host
/v2/jobs:
get:
description: List jobs
Expand Down
13 changes: 13 additions & 0 deletions dto/v2/body/host.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package body

import "time"

type HostRead struct {
HostBase `json:",inline" tstype:",extends"`
}

type HostVerboseRead struct {
HostBase `json:",inline" tstype:",extends"`
IP string `json:"ip"`
Port int `json:"port"`
Enabled bool `json:"enabled"`
Schedulable bool `json:"schedulable"`
DeactivatedUntil *time.Time `json:"deactivatedUntil,omitempty"`
LastSeenAt time.Time `json:"lastSeenAt"`
RegisteredAt time.Time `json:"registeredAt"`
}

type HostBase struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Expand Down
9 changes: 9 additions & 0 deletions export/types/v2/body/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ export interface GpuLeaseDeleted {

export interface HostRead extends HostBase {
}
export interface HostVerboseRead extends HostBase {
ip: string;
port: number /* int */;
enabled: boolean;
schedulable: boolean;
deactivatedUntil?: string;
lastSeenAt: string;
registeredAt: string;
}
export interface HostBase {
name: string;
displayName: string;
Expand Down
18 changes: 17 additions & 1 deletion models/model/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package model

import (
"fmt"
"github.com/kthcloud/go-deploy/dto/v2/body"
"time"

"github.com/kthcloud/go-deploy/dto/v2/body"
)

type Host struct {
Expand Down Expand Up @@ -38,6 +39,21 @@ func (host *Host) ToDTO() body.HostRead {
},
}
}
func (host *Host) ToVerboseDTO() body.HostVerboseRead {
return body.HostVerboseRead{
HostBase: body.HostBase{
Name: host.Name,
DisplayName: host.DisplayName,
Zone: host.Zone,
},
IP: host.IP,
Port: host.Port,
Enabled: host.Enabled,
Schedulable: host.Schedulable,
DeactivatedUntil: host.DeactivatedUntil,
RegisteredAt: host.RegisteredAt,
}
}
func NewHostByParams(params *body.HostRegisterParams) *Host {
return &Host{
Name: params.Name,
Expand Down
36 changes: 35 additions & 1 deletion routers/api/v2/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,45 @@ func ListHosts(c *gin.Context) {
if err != nil {
context.ServerError(err, fmt.Errorf("failed to get host info"))
}

dtoHosts := make([]body.HostRead, 0)
for _, host := range hostInfo {
dtoHosts = append(dtoHosts, host.ToDTO())
}
context.JSONResponse(200, dtoHosts)
}

// VerboseListHosts
// @Summary List Hosts verbose
// @Description List Hosts verbose
// @Tags Host
// @Produce json
// @Security ApiKeyAuth
// @Security KeycloakOAuth
// @Success 200 {array} body.HostVerboseRead
// @Failure 403 {object} sys.ErrorResponse
// @Failure 500 {object} sys.ErrorResponse
// @Router /v2/hosts/verbose [get]
func VerboseListHosts(c *gin.Context) {
context := sys.NewContext(c)

auth, err := WithAuth(&context)
if err != nil {
context.ServerError(err, ErrAuthInfoNotAvailable)
return
}

if (auth != nil && !auth.User.IsAdmin) || auth == nil {
context.Forbidden("Not permitted to request verbose host information")
return
}

hostInfo, err := service.V2().System().ListHosts()
if err != nil {
context.ServerError(err, fmt.Errorf("failed to get host info"))
}
dtoHosts := make([]body.HostVerboseRead, 0)
for _, host := range hostInfo {
dtoHosts = append(dtoHosts, host.ToVerboseDTO())
}
context.JSONResponse(200, dtoHosts)
}
11 changes: 9 additions & 2 deletions routers/routes/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package routes
import v2 "github.com/kthcloud/go-deploy/routers/api/v2"

const (
HostsPath = "/v2/hosts"
HostPath = "/v2/hosts/:hostId"
HostsPath = "/v2/hosts"
HostsPathVerbose = "/v2/hosts/verbose"
HostPath = "/v2/hosts/:hostId"
)

type HostRoutingGroup struct{ RoutingGroupBase }
Expand All @@ -18,3 +19,9 @@ func (group *HostRoutingGroup) PublicRoutes() []Route {
{Method: "GET", Pattern: HostsPath, HandlerFunc: v2.ListHosts},
}
}

func (group *HostRoutingGroup) PrivateRoutes() []Route {
return []Route{
{Method: "GET", Pattern: HostsPathVerbose, HandlerFunc: v2.VerboseListHosts},
}
}
Loading