mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
* Remove pop from models for now
* Remove rdbms storage from pkg/storage
* Completely remove pop
* Some improvements to tests
- Not sourcing from cmd/proxy/.env, because that doesn't export any variables
- Removing mysql support (I feel like 1 database is enough)
- Pruning networks on teardown
I'm happy to split these changes up into separate PRs - it's the end of the day for me so I wanted to get everything in 😄
* update to point to test instance
* Update databasy.yml for travis??
* Remove database.yml
* Do not use db migrations and creation
* Remove pop dependency from cdn
* add schema for olympus assuming cdn driver is part of olympus
* Move CI/CD and test scripts to point pop to olympus
* Update database.yml and keep it only for olympus
* Add migrations to travis
* Add debug logs to see what travis is doing
* Update travis to use olympus database.yml
* Moarrrr logs to see where travis is pointint the db towards
* Change env to test
* Use test as the default environment if not specified otherwise
* Check if test new rdbms storage succeeds
* Try to see which connection string rdbms test suite is using on travis
* Update db tags for cdn driver
* create db by using travis go_env
* Remove sql from database config as it is removed from docker-compose
* Remove extra logs that I missed
* Add newline
* remove models.go and test file from proxy
* removing extraneous network prune from Makefile
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package actions
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/gomods/athens/pkg/config/env"
|
|
"github.com/gomods/athens/pkg/storage"
|
|
"github.com/gomods/athens/pkg/storage/fs"
|
|
"github.com/gomods/athens/pkg/storage/gcp"
|
|
"github.com/gomods/athens/pkg/storage/mem"
|
|
"github.com/gomods/athens/pkg/storage/minio"
|
|
"github.com/gomods/athens/pkg/storage/mongo"
|
|
"github.com/spf13/afero"
|
|
)
|
|
|
|
// GetStorage returns storage backend based on env configuration
|
|
func GetStorage() (storage.Backend, error) {
|
|
storageType := env.StorageTypeWithDefault("memory")
|
|
var storageRoot string
|
|
var err error
|
|
|
|
switch storageType {
|
|
case "memory":
|
|
return mem.NewStorage()
|
|
case "mongo":
|
|
connectionString, err := env.MongoConnectionString()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
certPath := env.MongoCertPath()
|
|
return mongo.NewStorageWithCert(connectionString, certPath)
|
|
case "disk":
|
|
storageRoot, err = env.DiskRoot()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s, err := fs.NewStorage(storageRoot, afero.NewOsFs())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not create new storage from os fs (%s)", err)
|
|
}
|
|
return s, nil
|
|
case "minio":
|
|
endpoint, err := env.MinioEndpoint()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
accessKeyID, err := env.MinioAccessKeyID()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
secretAccessKey, err := env.MinioSecretAccessKey()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
bucketName := env.MinioBucketNameWithDefault("gomods")
|
|
useSSL := true
|
|
if useSSLVar := env.MinioSSLWithDefault("yes"); strings.ToLower(useSSLVar) == "no" {
|
|
useSSL = false
|
|
}
|
|
return minio.NewStorage(endpoint, accessKeyID, secretAccessKey, bucketName, useSSL)
|
|
case "gcp":
|
|
return gcp.New(context.Background())
|
|
default:
|
|
return nil, fmt.Errorf("storage type %s is unknown", storageType)
|
|
}
|
|
}
|