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

Add exclude_snapshots query param to export/sqlite #367

Merged
merged 1 commit into from
May 29, 2020
Merged
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
7 changes: 7 additions & 0 deletions docs/api_docs/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,13 @@ paths:
tags:
- export
operationId: getExportSqlite
parameters:
- in: query
name: exclude_snapshots
type: boolean
description: >
export without snapshots data - useful for smaller db without
snapshots
description: >-
Export sqlite3 format of the db dump, which is converted from the main
database.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/checkr/flagr

go 1.12
go 1.14

require (
cloud.google.com/go v0.37.4
Expand Down
12 changes: 7 additions & 5 deletions pkg/handler/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
"github.com/sirupsen/logrus"
)

var exportSQLiteHandler = func(export.GetExportSqliteParams) middleware.Responder {
f, done, err := exportSQLiteFile()
var exportSQLiteHandler = func(p export.GetExportSqliteParams) middleware.Responder {
f, done, err := exportSQLiteFile(p.ExcludeSnapshots)
defer done()
if err != nil {
return export.NewGetExportSqliteDefault(500).WithPayload(ErrorMessage("%s", err))
}
return export.NewGetExportSqliteOK().WithPayload(f)
}

var exportSQLiteFile = func() (file io.ReadCloser, done func(), err error) {
var exportSQLiteFile = func(excludeSnapshots *bool) (file io.ReadCloser, done func(), err error) {
fname := fmt.Sprintf("/tmp/flagr_%d.sqlite", rand.Int31())
done = func() {
os.Remove(fname)
Expand All @@ -37,8 +37,10 @@ var exportSQLiteFile = func() (file io.ReadCloser, done func(), err error) {
if err := exportFlags(tmpDB); err != nil {
return nil, done, err
}
if err := exportFlagSnapshots(tmpDB); err != nil {
return nil, done, err
if excludeSnapshots == nil || !*excludeSnapshots {
if err := exportFlagSnapshots(tmpDB); err != nil {
return nil, done, err
}
}
if err := exportFlagEntityTypes(tmpDB); err != nil {
return nil, done, err
Expand Down
13 changes: 11 additions & 2 deletions pkg/handler/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/checkr/flagr/pkg/entity"
"github.com/checkr/flagr/pkg/util"
"github.com/checkr/flagr/swagger_gen/restapi/operations/export"
"github.com/prashantv/gostub"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -63,8 +64,16 @@ func TestExportSQLiteFile(t *testing.T) {
defer db.Close()
defer gostub.StubFunc(&getDB, db).Reset()

t.Run("happy code path", func(t *testing.T) {
f, done, err := exportSQLiteFile()
t.Run("happy code path and export everything in db", func(t *testing.T) {
f, done, err := exportSQLiteFile(nil)
defer done()

assert.NoError(t, err)
assert.NotNil(t, f)
})

t.Run("happy code path and exclude_snapshots", func(t *testing.T) {
f, done, err := exportSQLiteFile(util.BoolPtr(true))
defer done()

assert.NoError(t, err)
Expand Down
6 changes: 6 additions & 0 deletions swagger/export_sqlite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ get:
tags:
- export
operationId: getExportSqlite
parameters:
- in: query
name: exclude_snapshots
type: boolean
description: >
export without snapshots data - useful for smaller db without snapshots
description: Export sqlite3 format of the db dump, which is converted from the main database.
produces:
- application/octet-stream
Expand Down
16 changes: 16 additions & 0 deletions swagger_gen/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading