Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition from Filestore to S3API as an AWS S3 package #48

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
S3_MOCK=0
AUTH_LEVEL=0 # Options: [0, 1] corresponds to [no FGAC, FGAC].
AUTH_LIMITED_WRITER_ROLE='s3_limited_writer'

DBUSER=user
DBPASS=password
DBHOST=localhost
DBPORT=5432
DBNAME=
15 changes: 15 additions & 0 deletions .example.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"accounts": [
{
"AWS_ACCESS_KEY_ID": "",
"AWS_SECRET_ACCESS_KEY": ""
},
{
"AWS_ACCESS_KEY_ID": "",
"AWS_SECRET_ACCESS_KEY": ""
}
],
"bucket_allow_list": [
"*"
] # "*" for allowing access to all buckets
}
34 changes: 25 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# Environments
*.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
.env
main
.vscode/
.env.json
.data
.env.json
.vscode/settings.json
19 changes: 1 addition & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ The MCAT includes:

### Getting Started

---

- Add a .env file to the root level of this directory with the following structure:

For local:

```
STORE_TYPE='LOCAL'
```

For S3:

```
STORE_TYPE='S3'
AWS_ACCESS_KEY_ID='**************'
AWS_SECRET_ACCESS_KEY='**************'
AWS_DEFAULT_REGION='us-east-1'
S3_BUCKET='******'
```

- Select the stage in `docker-compose.yml` file
Expand Down Expand Up @@ -82,3 +64,4 @@ _For example: `http://mcat-ras:5600/isamodel?definition_file=models/ras/CHURCH H
To view docs goto: http://localhost:5600/swagger/index.html

![](docs/swagger_image.png)
```
43 changes: 20 additions & 23 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package config
import (
"fmt"
"os"
"strconv"

"github.com/USACE/filestore"
"github.com/Dewberry/s3api/blobstore"
"github.com/labstack/gommon/log"
)

type APIConfig struct {
Host string
Port int
FileStore *filestore.FileStore
Bh *blobstore.BlobHandler
DestinationCRS int
}

Expand All @@ -24,34 +26,29 @@ func Init() *APIConfig {
config := new(APIConfig)
config.Host = "" // 0.0.0.0
config.Port = 5600
config.FileStore = FileStoreInit(os.Getenv("STORE_TYPE"))
config.Bh = blobstoreInit()
config.DestinationCRS = 4326
return config
}

// FileStoreInit initializes the filestore object
func FileStoreInit(store string) *filestore.FileStore {

var fs filestore.FileStore
func blobstoreInit() *blobstore.BlobHandler {
var authLvl int
var err error
switch store {
case "LOCAL":
fs, err = filestore.NewFileStore(filestore.BlockFSConfig{})
if err != nil {
panic(err)
}
case "S3":
config := filestore.S3FSConfig{
S3Id: os.Getenv("AWS_ACCESS_KEY_ID"),
S3Key: os.Getenv("AWS_SECRET_ACCESS_KEY"),
S3Region: os.Getenv("AWS_DEFAULT_REGION"),
S3Bucket: os.Getenv("S3_BUCKET"),
}

fs, err = filestore.NewFileStore(config)
authLvlString := os.Getenv("AUTH_LEVEL")
if authLvlString == "" {
authLvl = 0
log.Warn("Fine Grained Access Control disabled")
} else {
authLvl, err = strconv.Atoi(authLvlString)
if err != nil {
panic(err)
log.Fatalf("could not convert AUTH_LEVEL env variable to integer: %v", err)
}
}
return &fs
bh, err := blobstore.NewBlobHandler(".env.json", authLvl)
if err != nil {
errMsg := fmt.Errorf("failed to initialize a blobhandler %s", err.Error())
log.Fatal(errMsg)
}
return bh
}
29 changes: 17 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,45 @@ require (
github.com/go-errors/errors v1.4.1
github.com/jackc/pgx v3.6.2+incompatible
github.com/jmoiron/sqlx v1.3.4
github.com/labstack/echo/v4 v4.3.0
github.com/labstack/echo/v4 v4.11.1
github.com/pzsz/voronoi v0.0.0-20130609164533-4314be88c79f
github.com/swaggo/swag v1.7.0
)

require (
github.com/Dewberry/s3api v0.0.0-20240112165810-9368b22490e0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/aws/aws-sdk-go v1.38.68 // indirect
github.com/aws/aws-sdk-go v1.44.315 // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/spec v0.20.0 // indirect
github.com/go-openapi/swag v0.19.12 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/labstack/gommon v0.3.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
golang.org/x/tools v0.0.0-20201207182000-5679438983bd // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading
Loading