Address comments part 2

* OpenAPI Mock spec path adjusted
* Dropbox FileMetadata reflection refactored
* NaturalNumber type added
This commit is contained in:
MaxJa4 2023-08-23 19:25:52 +02:00
parent c304b4f52b
commit 5147753a79
5 changed files with 34 additions and 38 deletions

View File

@ -10,6 +10,7 @@ import (
"io/ioutil"
"os"
"regexp"
"strconv"
"time"
)
@ -75,7 +76,7 @@ type Config struct {
DropboxAppKey string `split_words:"true"`
DropboxAppSecret string `split_words:"true"`
DropboxRemotePath string `split_words:"true"`
DropboxConcurrencyLevel int `split_words:"true" default:"6"`
DropboxConcurrencyLevel NaturalNumber `split_words:"true" default:"6"`
}
func (c *Config) resolveSecret(envVar string, secretPath string) (string, error) {
@ -141,3 +142,21 @@ func (r *RegexpDecoder) Decode(v string) error {
*r = RegexpDecoder{Re: re}
return nil
}
type NaturalNumber int
func (n *NaturalNumber) Decode(v string) error {
asInt, err := strconv.Atoi(v)
if err != nil {
return fmt.Errorf("config: error converting %s to int", v)
}
if asInt <= 0 {
return fmt.Errorf("config: expected a natural number, got %d", asInt)
}
*n = NaturalNumber(asInt)
return nil
}
func (n *NaturalNumber) Int() int {
return int(*n)
}

View File

@ -227,7 +227,7 @@ func newScript() (*script, error) {
AppKey: s.c.DropboxAppKey,
AppSecret: s.c.DropboxAppSecret,
RemotePath: s.c.DropboxRemotePath,
ConcurrencyLevel: s.c.DropboxConcurrencyLevel,
ConcurrencyLevel: s.c.DropboxConcurrencyLevel.Int(),
}
dropboxBackend, err := dropbox.NewStorageBackend(dropboxConfig, logFunc)
if err != nil {

View File

@ -8,7 +8,6 @@ import (
"os"
"path"
"path/filepath"
"reflect"
"strings"
"sync"
"time"
@ -233,17 +232,18 @@ func (b *dropboxStorage) Prune(deadline time.Time, pruningPrefix string) (*stora
var matches []*files.FileMetadata
var lenCandidates int
for _, candidate := range entries {
if reflect.Indirect(reflect.ValueOf(candidate)).Type() != reflect.TypeOf(files.FileMetadata{}) {
switch candidate := candidate.(type) {
case *files.FileMetadata:
if !strings.HasPrefix(candidate.Name, pruningPrefix) {
continue
}
lenCandidates++
if candidate.ServerModified.Before(deadline) {
matches = append(matches, candidate)
}
default:
continue
}
candidate := candidate.(*files.FileMetadata)
if !strings.HasPrefix(candidate.Name, pruningPrefix) {
continue
}
lenCandidates++
if candidate.ServerModified.Before(deadline) {
matches = append(matches, candidate)
}
}
stats := &storage.PruneStats{

View File

@ -5,9 +5,11 @@ services:
image: muonsoft/openapi-mock
environment:
OPENAPI_MOCK_USE_EXAMPLES: if_present
OPENAPI_MOCK_SPECIFICATION_URL: https://raw.githubusercontent.com/offen/docker-volume-backup/2ea59a649be79d6cb22b8b5ad29e24377d4ab9d4/test/dropbox/user_v2.yaml
OPENAPI_MOCK_SPECIFICATION_URL: '/etc/openapi/user_v2.yaml'
ports:
- 8080:8080
volumes:
- ./user_v2.yaml:/etc/openapi/user_v2.yaml
backup:
image: offen/docker-volume-backup:${TEST_VERSION:-canary}

View File

@ -1,25 +0,0 @@
# OpenAPI specification options
openapi:
specification_url: '/etc/openapi/user_v2.yaml'
# web server options
http:
cors_enabled: false
port: 8080
response_timeout: 1.0
# application specific options
application:
debug: false
log_format: tty
log_level: info
# options to control generation process
generation:
default_min_float: -1.073741823e+09
default_max_float: 1.073741823e+09
default_min_int: 0
default_max_int: 2147483647
null_probability: 0
suppress_errors: false
use_examples: 'if_present'