Skip to content

Commit

Permalink
replace secret package with github.com/negrel/secrecy
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed Oct 22, 2024
1 parent 179c50e commit d16533a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 136 deletions.
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
packages = {
default = pkgs.buildGoModule {
pname = "prisme";
version = "0.17.0";
version = "0.18.0";
vendorHash =
"sha256-F3ZUU+hixLOOZrDjfHOuxHnopzIdc/9qxR6rMeUbt/0=";
"sha256-BrOVG51qH6J2ucvVr31Z1Qy49QxA4n9MXBeUEZQx6Wo=";

src = ./.;
# Skip go test.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/google/uuid v1.6.0
github.com/google/wire v0.6.0
github.com/negrel/ringo v0.7.0
github.com/negrel/secrecy v0.4.0
github.com/oschwald/maxminddb-golang v1.13.1
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/client_model v0.6.1
Expand Down
70 changes: 21 additions & 49 deletions go.sum

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions pkg/clickhouse/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package clickhouse

import (
"io"
"runtime"
"testing"

"github.com/negrel/secrecy"
"github.com/prismelabs/analytics/pkg/config"
"github.com/prismelabs/analytics/pkg/log"
"github.com/prismelabs/analytics/pkg/secret"
"github.com/stretchr/testify/require"
)

Expand All @@ -18,15 +19,16 @@ func TestClickhouseConnect(t *testing.T) {
TlsEnabled: false,
HostPort: "down.localhost",
Database: "analytics",
User: secret.New("foo"),
Password: secret.New("bar"),
User: secrecy.NewSecretString(secrecy.UnsafeStringToBytes("foo")),
Password: secrecy.NewSecretString(secrecy.UnsafeStringToBytes("bar")),
}

require.Panics(t, func() {
_ = Connect(logger, cfg, 1)
})
})

runtime.GC()
// We're not testing a real connection to postgres in unit tests.
}

Expand All @@ -38,14 +40,16 @@ func TestClickhouseConnectSql(t *testing.T) {
TlsEnabled: false,
HostPort: "down.localhost",
Database: "analytics",
User: secret.New("foo"),
Password: secret.New("bar"),
User: secrecy.NewSecretString(secrecy.UnsafeStringToBytes("foo")),
Password: secrecy.NewSecretString(secrecy.UnsafeStringToBytes("bar")),
}

require.Panics(t, func() {
_ = connectSql(logger, cfg, 1)
})
})

// We're not testing a real connection to postgres in unit tests.
runtime.GC()

// We're not testing a real connection to clickhouse in unit tests.
}
10 changes: 5 additions & 5 deletions pkg/config/clickhouse.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package config

import (
"github.com/prismelabs/analytics/pkg/secret"
"github.com/negrel/secrecy"
)

// Clickhouse connection options.
type Clickhouse struct {
TlsEnabled bool
HostPort string
Database string
User secret.Secret[string]
Password secret.Secret[string]
User secrecy.SecretString
Password secrecy.SecretString
}

// ClickhouseFromEnv loads clickhouse config from environment variables.
Expand All @@ -20,7 +20,7 @@ func ClickhouseFromEnv() Clickhouse {
TlsEnabled: GetEnvOrDefault("PRISME_CLICKHOUSE_TLS", "false") != "false",
HostPort: MustGetEnv("PRISME_CLICKHOUSE_HOSTPORT"),
Database: GetEnvOrDefault("PRISME_CLICKHOUSE_DB", "prisme"),
User: secret.New(MustGetEnv("PRISME_CLICKHOUSE_USER")),
Password: secret.New(MustGetEnv("PRISME_CLICKHOUSE_PASSWORD")),
User: secrecy.NewSecretString(secrecy.UnsafeStringToBytes(MustGetEnv("PRISME_CLICKHOUSE_USER"))),
Password: secrecy.NewSecretString(secrecy.UnsafeStringToBytes(MustGetEnv("PRISME_CLICKHOUSE_PASSWORD"))),
}
}
12 changes: 7 additions & 5 deletions pkg/config/grafana.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package config

import "github.com/prismelabs/analytics/pkg/secret"
import (
"github.com/negrel/secrecy"
)

// Grafana related options.
type Grafana struct {
Url string
User secret.Secret[string]
Password secret.Secret[string]
User secrecy.SecretString
Password secrecy.SecretString
OrgId int64
}

Expand All @@ -15,8 +17,8 @@ type Grafana struct {
func GrafanaFromEnv() Grafana {
return Grafana{
Url: MustGetEnv("PRISME_GRAFANA_URL"),
User: secret.New(MustGetEnv("PRISME_GRAFANA_USER")),
Password: secret.New(MustGetEnv("PRISME_GRAFANA_PASSWORD")),
User: secrecy.NewSecretString(secrecy.UnsafeStringToBytes(MustGetEnv("PRISME_GRAFANA_USER"))),
Password: secrecy.NewSecretString(secrecy.UnsafeStringToBytes(MustGetEnv("PRISME_GRAFANA_PASSWORD"))),
OrgId: ParseIntEnvOrDefault("PRISME_GRAFANA_ORG_ID", 1, 64),
}
}
45 changes: 0 additions & 45 deletions pkg/secret/secret.go

This file was deleted.

24 changes: 0 additions & 24 deletions pkg/secret/secret_test.go

This file was deleted.

0 comments on commit d16533a

Please sign in to comment.