Skip to content

Commit

Permalink
OpenAPI: minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Jan 18, 2021
1 parent 778ec9b commit 41a1af8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
2 changes: 2 additions & 0 deletions docs/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion examples/rest-api-cli/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion httpd/api_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 12 additions & 7 deletions httpd/schema/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -723,7 +723,7 @@ paths:
schema:
$ref : '#/components/schemas/ApiResponse'
example:
message: "User updated"
message: "Admin updated"
400:
$ref: '#/components/responses/BadRequest'
401:
Expand Down Expand Up @@ -756,7 +756,7 @@ paths:
schema:
$ref : '#/components/schemas/ApiResponse'
example:
message: "User deleted"
message: "Admin deleted"
400:
$ref: '#/components/responses/BadRequest'
401:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -1818,6 +1821,7 @@ components:
type: array
items:
$ref: '#/components/schemas/FTPDBinding'
nullable: true
passive_port_range:
$ref: '#/components/schemas/FTPPassivePortRange'
WebDAVServiceStatus:
Expand All @@ -1829,6 +1833,7 @@ components:
type: array
items:
$ref: '#/components/schemas/WebDAVBinding'
nullable: true
DataProviderStatus:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion sftpd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion sftpd/sftpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package sftpd

import (
"strings"
"time"
)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sftpd/sftpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h5 class="card-title">SFTP/SSH server</h5>
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>
Expand Down

0 comments on commit 41a1af8

Please sign in to comment.