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"). 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 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 # 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. `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)) sendAPIResponse(w, r, err, "", getRespStatus(err))
return 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) { func deleteAdmin(w http.ResponseWriter, r *http.Request) {

View file

@ -2,7 +2,7 @@ openapi: 3.0.3
info: info:
title: SFTPGo title: SFTPGo
description: SFTPGo REST API description: SFTPGo REST API
version: 2.4.0 version: 2.4.1
servers: servers:
- url: /api/v2 - url: /api/v2
@ -327,7 +327,7 @@ paths:
example: reset example: reset
requestBody: requestBody:
required: true 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: content:
application/json: application/json:
schema: schema:
@ -723,7 +723,7 @@ paths:
schema: schema:
$ref : '#/components/schemas/ApiResponse' $ref : '#/components/schemas/ApiResponse'
example: example:
message: "User updated" message: "Admin updated"
400: 400:
$ref: '#/components/responses/BadRequest' $ref: '#/components/responses/BadRequest'
401: 401:
@ -756,7 +756,7 @@ paths:
schema: schema:
$ref : '#/components/schemas/ApiResponse' $ref : '#/components/schemas/ApiResponse'
example: example:
message: "User deleted" message: "Admin deleted"
400: 400:
$ref: '#/components/responses/BadRequest' $ref: '#/components/responses/BadRequest'
401: 401:
@ -1688,7 +1688,7 @@ components:
description: connection time as unix timestamp in milliseconds description: connection time as unix timestamp in milliseconds
command: command:
type: string type: string
description: SSH/FTP command or WebDAV method description: Last SSH/FTP command or WebDAV method
last_activity: last_activity:
type: integer type: integer
format: int64 format: int64
@ -1795,13 +1795,16 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/SSHBinding' $ref: '#/components/schemas/SSHBinding'
nullable: true
host_keys: host_keys:
type: array type: array
items: items:
$ref: '#/components/schemas/SSHHostKey' $ref: '#/components/schemas/SSHHostKey'
nullable: true
ssh_commands: ssh_commands:
type: string type: array
description: accepted SSH commands comma separated items:
type: string
FTPPassivePortRange: FTPPassivePortRange:
type: object type: object
properties: properties:
@ -1818,6 +1821,7 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/FTPDBinding' $ref: '#/components/schemas/FTPDBinding'
nullable: true
passive_port_range: passive_port_range:
$ref: '#/components/schemas/FTPPassivePortRange' $ref: '#/components/schemas/FTPPassivePortRange'
WebDAVServiceStatus: WebDAVServiceStatus:
@ -1829,6 +1833,7 @@ components:
type: array type: array
items: items:
$ref: '#/components/schemas/WebDAVBinding' $ref: '#/components/schemas/WebDAVBinding'
nullable: true
DataProviderStatus: DataProviderStatus:
type: object type: object
properties: properties:

View file

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

View file

@ -4,6 +4,7 @@
package sftpd package sftpd
import ( import (
"strings"
"time" "time"
) )
@ -39,10 +40,15 @@ type HostKey struct {
type ServiceStatus struct { type ServiceStatus struct {
IsActive bool `json:"is_active"` IsActive bool `json:"is_active"`
Bindings []Binding `json:"bindings"` Bindings []Binding `json:"bindings"`
SSHCommands string `json:"ssh_commands"` SSHCommands []string `json:"ssh_commands"`
HostKeys []HostKey `json:"host_keys"` 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 // GetStatus returns the server status
func GetStatus() ServiceStatus { func GetStatus() ServiceStatus {
return serviceStatus return serviceStatus

View file

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

View file

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