Skip to content

Commit

Permalink
Merge branch 'main' into import-yaml-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps authored Sep 25, 2023
2 parents c05f96f + be807aa commit bb1523e
Show file tree
Hide file tree
Showing 53 changed files with 1,438 additions and 596 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DavidAnson/markdownlint-cli2-action@v12
- uses: DavidAnson/markdownlint-cli2-action@v13
with:
config: .markdownlint.yaml
globs: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ jobs:
cmd: yq -i '.app.env = "Nightly"' stackhawk.yml

- name: Run HawkScan
uses: stackhawk/[email protected].1
uses: stackhawk/[email protected].2
with:
apiKey: ${{ secrets.HAWK_API_KEY }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.27.2](https://github.com/flipt-io/flipt/releases/tag/v1.27.2) - 2023-09-21

### Fixed

- `security`: dont marshal secrets to JSON

## [v1.27.1](https://github.com/flipt-io/flipt/releases/tag/v1.27.1) - 2023-09-18

### Added
Expand Down
67 changes: 14 additions & 53 deletions DEPRECATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,71 +54,32 @@ Enabling OpenTelemetry tracing with the Jaeger expoerter via `tracing.jaeger` is
backend: jaeger
```

### ui.enabled

> since [v1.17.0](https://github.com/flipt-io/flipt/releases/tag/v1.17.0)
An upcoming release will enable the UI always and this option will be removed.
There will be a new version of Flipt (headless) that will run Flipt without the UI and only include the API.

### db.migrations.path and db.migrations_path

> since [v1.14.0](https://github.com/flipt-io/flipt/releases/tag/v1.14.0)
These options are no longer considered during Flipt execution.
Database migrations are embedded directly within the Flipt binary.

### API ListFlagRequest, ListSegmentRequest, ListRuleRequest offset

> since [v1.13.0](https://github.com/flipt-io/flipt/releases/tag/v1.13.0)
`offset` has been deprecated in favor of `page_token`/`next_page_token` for `ListFlagRequest`, `ListSegmentRequest` and `ListRuleRequest`. See: [#936](https://github.com/flipt-io/flipt/issues/936).

### cache.memory.enabled

> since [v1.10.0](https://github.com/flipt-io/flipt/releases/tag/v1.10.0)
Enabling in-memory cache via `cache.memory` is deprecated in favor of setting the `cache.backend` to `memory` and `cache.enabled` to `true`.

=== Before

``` yaml
cache:
memory:
enabled: true
```

=== After

``` yaml
cache:
enabled: true
backend: memory
```
## Expired Deprecation Notices

### cache.memory.expiration
The following options were deprecated in the past and were already removed.

> since [v1.10.0](https://github.com/flipt-io/flipt/releases/tag/v1.10.0)
### ui.enabled

Setting cache expiration via `cache.memory` is deprecated in favor of setting the `cache.backend` to `memory` and `cache.ttl` to the desired duration.
> deprecated in [v1.17.0](https://github.com/flipt-io/flipt/releases/tag/v1.17.0)
> removed in [v1.28.0](https://github.com/flipt-io/flipt/releases/tag/v1.28.0)
=== Before
### db.migrations.path and db.migrations_path

``` yaml
cache:
memory:
expiration: 1m
```
> deprecated in [v1.14.0](https://github.com/flipt-io/flipt/releases/tag/v1.14.0)
> removed in [v1.28.0](https://github.com/flipt-io/flipt/releases/tag/v1.28.0)
=== After
### cache.memory.enabled

``` yaml
cache:
enabled: true
backend: memory
ttl: 1m
```
> deprecated in [v1.10.0](https://github.com/flipt-io/flipt/releases/tag/v1.10.0)
> removed in [v1.28.0](https://github.com/flipt-io/flipt/releases/tag/v1.28.0)
## Expired Deprecation Notices
### cache.memory.expiration

The following options were deprecated in the past and were already removed.
> deprecated in [v1.10.0](https://github.com/flipt-io/flipt/releases/tag/v1.10.0)
> removed in [v1.28.0](https://github.com/flipt-io/flipt/releases/tag/v1.28.0)
38 changes: 12 additions & 26 deletions build/testing/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testing
import (
"context"
"fmt"
"os"
"strings"

"dagger.io/dagger"
Expand All @@ -11,9 +12,14 @@ import (
func CLI(ctx context.Context, client *dagger.Client, container *dagger.Container) error {
{
container := container.Pipeline("flipt --help")
expected, err := os.ReadFile("build/testing/testdata/cli.txt")
if err != nil {
return err
}

if _, err := assertExec(ctx, container, flipt("--help"),
fails,
stdout(equals(expectedFliptHelp))); err != nil {
stdout(equals(expected))); err != nil {
return err
}
}
Expand All @@ -34,21 +40,21 @@ func CLI(ctx context.Context, client *dagger.Client, container *dagger.Container
container := container.Pipeline("flipt --config")
if _, err := assertExec(ctx, container, flipt("foo"),
fails,
stderr(equals(`Error: unknown command "foo" for "flipt"
stderr(contains(`unknown command "foo" for "flipt"
Run 'flipt --help' for usage.`))); err != nil {
return err
}

if _, err := assertExec(ctx, container, flipt("--config", "/foo/bar.yml"),
fails,
stdout(contains(`loading configuration {"error": "loading configuration: open /foo/bar.yml: no such file or directory", "config_path": "/foo/bar.yml"}`)),
stderr(contains("loading configuration: open /foo/bar.yml: no such file or directory")),
); err != nil {
return err
}

if _, err := assertExec(ctx, container, flipt("--config", "/tmp"),
fails,
stdout(contains(`loading configuration: Unsupported Config Type`)),
stderr(contains(`loading configuration: Unsupported Config Type`)),
); err != nil {
return err
}
Expand All @@ -58,7 +64,7 @@ Run 'flipt --help' for usage.`))); err != nil {
container := container.Pipeline("flipt (no config)")
if _, err := assertExec(ctx, container.WithExec([]string{"rm", "/etc/flipt/config/default.yml"}), flipt(),
fails,
stdout(contains(`loading configuration {"error": "loading configuration: open /etc/flipt/config/default.yml: no such file or directory", "config_path": "/etc/flipt/config/default.yml"}`)),
stderr(contains(`loading configuration: open /etc/flipt/config/default.yml: no such file or directory`)),
); err != nil {
return err
}
Expand Down Expand Up @@ -110,7 +116,7 @@ exit $?`,
if _, err = assertExec(ctx, container,
flipt("import", "foo"),
fails,
stdout(contains("opening import file: open foo: no such file or directory")),
stderr(contains("opening import file: open foo: no such file or directory")),
); err != nil {
return err
}
Expand Down Expand Up @@ -213,26 +219,6 @@ exit $?`,
}

const (
expectedFliptHelp = `Flipt is a modern, self-hosted, feature flag solution
Usage:
flipt [flags]
flipt [command]
Available Commands:
export Export flags/segments/rules to file/stdout
help Help about any command
import Import flags/segments/rules from file
migrate Run pending database migrations
validate Validate flipt flag state (.yaml, .yml) files
Flags:
--config string path to config file
-h, --help help for flipt
-v, --version version for flipt
Use "flipt [command] --help" for more information about a command.
`
expectedFliptYAML = `flags:
- key: zUFtS7D0UyMeueYu
name: UAoZRksg94r1iipa
Expand Down
5 changes: 5 additions & 0 deletions build/testing/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,9 +1233,14 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
for _, name := range []string{
"log",
"ui",
"authentication",
"audit",
"cache",
"cors",
"server",
"storage",
"db",
"tracing",
} {
field, ok := configMap[name]
assert.True(t, ok, "Missing %s.", name)
Expand Down
26 changes: 26 additions & 0 deletions build/testing/testdata/cli.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Flipt is a modern, self-hosted, feature flag solution

Usage:
flipt <command> <subcommand> [flags]
flipt [command]

Examples:
$ flipt
$ flipt config init
$ flipt --config /path/to/config.yml migrate


Available Commands:
config Manage Flipt configuration
export Export flags/segments/rules to file/stdout
help Help about any command
import Import flags/segments/rules from file
migrate Run pending database migrations
validate Validate Flipt flag state (.yaml, .yml) files

Flags:
--config string path to config file
-h, --help help for flipt
-v, --version version for flipt

Use "flipt [command] --help" for more information about a command.
88 changes: 88 additions & 0 deletions cmd/flipt/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package main

import (
"bytes"
"os"

"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"go.flipt.io/flipt/internal/config"
"gopkg.in/yaml.v2"
)

type initCommand struct {
force bool
}

func (c *initCommand) run(cmd *cobra.Command, args []string) error {
var (
file string
defaultFile = providedConfigFile
)

if defaultFile == "" {
defaultFile = userConfigFile
}

q := []*survey.Question{
{
Name: "file",
Prompt: &survey.Input{
Message: "Configuration file path:",
Default: defaultFile,
},
Validate: survey.Required,
},
}

if err := survey.Ask(q, &file); err != nil {
return err
}

overwrite := c.force
if !overwrite {
// check if file exists
if _, err := os.Stat(file); err == nil {
// file exists
prompt := &survey.Confirm{
Message: "File exists. Overwrite?",
}
if err := survey.AskOne(prompt, &overwrite); err != nil {
return err
}
}
}

cfg := config.Default()
cfg.Version = config.Version // write version for backward compatibility
out, err := yaml.Marshal(cfg)
if err != nil {
return err
}

var b bytes.Buffer
b.WriteString("# yaml-language-server: $schema=https://raw.githubusercontent.com/flipt-io/flipt/main/config/flipt.schema.json\n\n")
b.Write(out)

return os.WriteFile(file, b.Bytes(), 0600)
}

func newConfigCommand() *cobra.Command {
var configCmd = &cobra.Command{
Use: "config",
Short: "Manage Flipt configuration",
}

initCmd := &initCommand{}

var init = &cobra.Command{
Use: "init",
Short: "Initialize Flipt configuration",
RunE: initCmd.run,
}

init.Flags().BoolVarP(&initCmd.force, "force", "y", false, "Overwrite existing configuration file")

configCmd.AddCommand(init)
return configCmd
}
2 changes: 1 addition & 1 deletion cmd/flipt/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

package main

var defaultCfgPath string
var defaultConfigFile string
2 changes: 1 addition & 1 deletion cmd/flipt/default_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

package main

var defaultCfgPath = "/etc/flipt/config/default.yml"
var defaultConfigFile = "/etc/flipt/config/default.yml"
16 changes: 14 additions & 2 deletions cmd/flipt/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,23 @@ func (c *exportCommand) run(cmd *cobra.Command, _ []string) error {

// Use client when remote address is configured.
if c.address != "" {
return c.export(cmd.Context(), out, fliptClient(logger, c.address, c.token))
client, err := fliptClient(c.address, c.token)
if err != nil {
return err
}
return c.export(cmd.Context(), out, client)
}

// Otherwise, go direct to the DB using Flipt configuration file.
logger, cfg := buildConfig()
logger, cfg, err := buildConfig()
if err != nil {
return err
}

defer func() {
_ = logger.Sync()
}()

server, cleanup, err := fliptServer(logger, cfg)
if err != nil {
return err
Expand Down
Loading

0 comments on commit bb1523e

Please sign in to comment.