Skip to content

Commit

Permalink
bugfix: Fix error in force flag for secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
clintjedwards committed Apr 17, 2023
1 parent 53ff652 commit 5ac35a7
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 13 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Also github integration:
- Expand the CLI up command to actually walk the user through the deployment using watch. Right now it just starts the deployment and walks away.
- When a user runs up, should we compare their config to known configs and reject
registration if it's the same?
- In the CLI as the user a question with a prompt like ?

### Scheduler

Expand Down Expand Up @@ -145,8 +146,7 @@ There are several useful things we can do with the concept of extensions:

### On the floor

- Global secret force replace does not work, probably should just change to and update.
- In the CLI as the user a question with a prompt like ?
- Force for both objects and secrets need to be checked. Some layers of the process does not respect it.

- Github Extension:
- Because things are handled at the current abstraction layer for users who just want to throw code and have it work it can be difficult. Users who operate within Gofer will have to do at least some thought about repositories downloads, possibly caching, transferring between containers, etc. These are all things that some CI/CD systems give for free. The managing of large git repos is the biggest pain point here.
Expand Down
5 changes: 4 additions & 1 deletion go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,12 @@ cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT
cloud.google.com/go/workflows v1.10.0/go.mod h1:fZ8LmRmZQWacon9UCX1r/g/DfAXx5VcPALq2CxzdePw=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0=
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -492,6 +493,7 @@ github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZX
github.com/opencontainers/image-spec v1.1.0-rc1 h1:lfG+OTa7V8PD3PKvkocSG9KAcA9MANqJn53m31Fvwkc=
github.com/opencontainers/image-spec v1.1.0-rc1/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8=
github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down Expand Up @@ -902,6 +904,7 @@ google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBt
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
2 changes: 2 additions & 0 deletions internal/api/secretStoreHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/clintjedwards/gofer/internal/secretStore"
"github.com/clintjedwards/gofer/internal/storage"
proto "github.com/clintjedwards/gofer/proto/go"
"github.com/rs/zerolog/log"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -252,6 +253,7 @@ func (api *API) PutGlobalSecret(ctx context.Context, request *proto.PutGlobalSec
status.Error(codes.AlreadyExists, "key already exists")
}

log.Error().Err(err).Msg("could not insert global key into database")
return &proto.PutGlobalSecretResponse{},
status.Error(codes.Internal, "could not insert key")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/pipeline/extension/extensionSub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ You can find the current extensions your Gofer instances supports by using the '
Usually extensions will require some type of configuration for each pipeline subscribed. You can pass this configuration
by using the '--setting' flag.
For example, the "interval" trigger requires the subscribing pipeline to specify which interval it would like to be
run on. The parameter is called "every". So one might subscribe to the interval trigger like so:
For example, the "interval" extension requires the subscribing pipeline to specify which interval it would like to be
run on. The parameter is called "every". So one might subscribe to the interval extension like so:
ex. gofer pipeline extend simple interval every_5_seconds -s every="5s"
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/pipeline/pipelineExtend.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ You can find the current extensions your Gofer instances supports by using the '
Usually extensions will require some type of configuration for each pipeline subscribed. You can pass this configuration
by using the '--setting' flag.
For example, the "interval" trigger requires the subscribing pipeline to specify which interval it would like to be
run on. The parameter is called "every". So one might subscribe to the interval trigger like so:
For example, the "interval" extension requires the subscribing pipeline to specify which interval it would like to be
run on. The parameter is called "every". So one might subscribe to the interval extension like so:
ex. gofer pipeline extend simple interval every_5_seconds -s every="5s"
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/run/runList.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func formatTable(data [][]string, color bool) string {
tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString)

table.SetHeader([]string{"ID", "Started", "Ended", "Duration", "State", "Status", "Triggered By"})
table.SetHeader([]string{"ID", "Started", "Ended", "Duration", "State", "Status", "Started By"})
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetHeaderLine(true)
Expand Down
7 changes: 7 additions & 0 deletions internal/objectStore/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func (store *Store) PutObject(key string, content []byte, force bool) error {
_, err := qb.Insert("objects").Columns("key", "value").Values(key, content).RunWith(store).Exec()
if err != nil {
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
if force {
_, err = qb.Update("objects").Set("value", content).Where("key", key).RunWith(store).Exec()
if err != nil {
return fmt.Errorf("database error occurred: %v; %w", err, objectStore.ErrInternal)
}
return nil
}
return objectStore.ErrEntityExists
}

Expand Down
8 changes: 8 additions & 0 deletions internal/secretStore/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ func (store *Store) PutSecret(key string, content string, force bool) error {
_, err = qb.Insert("secrets").Columns("key", "value").Values(key, encryptedSecret).RunWith(store).Exec()
if err != nil {
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
if force {
_, err = qb.Update("secrets").Set("value", encryptedSecret).
Where("key", key).RunWith(store).Exec()
if err != nil {
return fmt.Errorf("database error occurred: %v; %w", err, secretStore.ErrInternal)
}
return nil
}
return secretStore.ErrEntityExists
}

Expand Down
4 changes: 2 additions & 2 deletions internal/storage/secretStoreGlobalKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (db *DB) InsertSecretStoreGlobalKey(conn Queryable, secretKey *SecretStoreG
return ErrEntityExists
}

// We should update the key's created if the flag for force was passed down.
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
_, err = qb.Update("secret_store_pipeline_keys").Set("created", secretKey.Created).RunWith(conn).Exec()
_, err = qb.Update("secret_store_global_keys").Set("namespaces", secretKey.Namespaces).
Where("key", secretKey.Key).RunWith(conn).Exec()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion proto/go/gofer_transport.pb.go

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

2 changes: 1 addition & 1 deletion proto/gofer_transport.proto
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ message PutGlobalSecretRequest {
string key = 1;
string content = 2;
repeated string namespaces = 3;
bool force = 4; // Overwrites an already existing value.
bool force = 4; // Overwrites already existing values.
}
message PutGlobalSecretResponse {
// The number of bytes uploaded.
Expand Down
2 changes: 1 addition & 1 deletion proto/rust/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ pub struct PutGlobalSecretRequest {
pub content: ::prost::alloc::string::String,
#[prost(string, repeated, tag="3")]
pub namespaces: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Overwrites an already existing value.
/// Overwrites already existing values.
#[prost(bool, tag="4")]
pub force: bool,
}
Expand Down

0 comments on commit 5ac35a7

Please sign in to comment.