OpenAPI: minor changes

This commit is contained in:
Nicola Murino 2021-01-18 13:24:38 +01:00
parent 778ec9b88f
commit 41a1af863e
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
8 changed files with 27 additions and 12 deletions

View file

@ -41,3 +41,5 @@ You can also restrict administrator access based on the source IP address. If yo
The OpenAPI 3 schema for the exposed API can be found inside the source tree: [openapi.yaml](../httpd/schema/openapi.yaml "OpenAPI 3 specs").
You can generate your own REST client in your preferred programming language, or even bash scripts, using an OpenAPI generator such as [swagger-codegen](https://github.com/swagger-api/swagger-codegen) or [OpenAPI Generator](https://openapi-generator.tech/).
You can also use [Swagger UI](https://github.com/swagger-api/swagger-ui).

View file

@ -1,6 +1,6 @@
# REST API CLI client
:warning: This sample client is deprecated and it will work only with api V1 (SFTPGo <= 1.2.2). You can easily build your own client from the OpenAPI schema.
:warning: This sample client is deprecated and it will work only with API V1 (SFTPGo <= 1.2.2). You can easily build your own client from the [OpenAPI](../../httpd/schema/openapi.yaml) schema or use [Swagger UI](https://github.com/swagger-api/swagger-ui).
`sftpgo_api_cli` is a very simple command line client for `SFTPGo` REST API written in python.

View file

@ -131,7 +131,7 @@ func updateAdmin(w http.ResponseWriter, r *http.Request) {
sendAPIResponse(w, r, err, "", getRespStatus(err))
return
}
sendAPIResponse(w, r, nil, "Update admin", http.StatusOK)
sendAPIResponse(w, r, nil, "Admin updated", http.StatusOK)
}
func deleteAdmin(w http.ResponseWriter, r *http.Request) {

View file

@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: SFTPGo
description: SFTPGo REST API
version: 2.4.0
version: 2.4.1
servers:
- url: /api/v2
@ -327,7 +327,7 @@ paths:
example: reset
requestBody:
required: true
description: The only user mandatory fields are username,used_quota_size and used_quota_files. Please note that if the quota fields are missing they will default to 0
description: The only user mandatory fields are username, used_quota_size and used_quota_files. Please note that if the quota fields are missing they will default to 0
content:
application/json:
schema:
@ -723,7 +723,7 @@ paths:
schema:
$ref : '#/components/schemas/ApiResponse'
example:
message: "User updated"
message: "Admin updated"
400:
$ref: '#/components/responses/BadRequest'
401:
@ -756,7 +756,7 @@ paths:
schema:
$ref : '#/components/schemas/ApiResponse'
example:
message: "User deleted"
message: "Admin deleted"
400:
$ref: '#/components/responses/BadRequest'
401:
@ -1688,7 +1688,7 @@ components:
description: connection time as unix timestamp in milliseconds
command:
type: string
description: SSH/FTP command or WebDAV method
description: Last SSH/FTP command or WebDAV method
last_activity:
type: integer
format: int64
@ -1795,13 +1795,16 @@ components:
type: array
items:
$ref: '#/components/schemas/SSHBinding'
nullable: true
host_keys:
type: array
items:
$ref: '#/components/schemas/SSHHostKey'
nullable: true
ssh_commands:
type: string
description: accepted SSH commands comma separated
type: array
items:
type: string
FTPPassivePortRange:
type: object
properties:
@ -1818,6 +1821,7 @@ components:
type: array
items:
$ref: '#/components/schemas/FTPDBinding'
nullable: true
passive_port_range:
$ref: '#/components/schemas/FTPPassivePortRange'
WebDAVServiceStatus:
@ -1829,6 +1833,7 @@ components:
type: array
items:
$ref: '#/components/schemas/WebDAVBinding'
nullable: true
DataProviderStatus:
type: object
properties:

View file

@ -258,7 +258,7 @@ func (c *Configuration) Initialize(configDir string) error {
}
serviceStatus.IsActive = true
serviceStatus.SSHCommands = strings.Join(c.EnabledSSHCommands, ", ")
serviceStatus.SSHCommands = c.EnabledSSHCommands
return <-exitChannel
}

View file

@ -4,6 +4,7 @@
package sftpd
import (
"strings"
"time"
)
@ -39,10 +40,15 @@ type HostKey struct {
type ServiceStatus struct {
IsActive bool `json:"is_active"`
Bindings []Binding `json:"bindings"`
SSHCommands string `json:"ssh_commands"`
SSHCommands []string `json:"ssh_commands"`
HostKeys []HostKey `json:"host_keys"`
}
// GetSSHCommandsAsString returns enabled SSH commands as comma separated string
func (s ServiceStatus) GetSSHCommandsAsString() string {
return strings.Join(s.SSHCommands, ", ")
}
// GetStatus returns the server status
func GetStatus() ServiceStatus {
return serviceStatus

View file

@ -385,6 +385,8 @@ func TestBasicSFTPHandling(t *testing.T) {
assert.NoError(t, err)
status := sftpd.GetStatus()
assert.True(t, status.IsActive)
sshCommands := status.GetSSHCommandsAsString()
assert.NotEmpty(t, sshCommands)
}
func TestBasicSFTPFsHandling(t *testing.T) {

View file

@ -16,7 +16,7 @@
Address: "{{.GetAddress}}" {{if .HasProxy}}Proxy: ON{{end}}
<br>
{{end}}
Accepted commands: "{{.Status.SSH.SSHCommands}}"
Accepted commands: "{{.Status.SSH.GetSSHCommandsAsString}}"
<br>
{{range .Status.SSH.HostKeys}}
<br>