Skip to content

Commit 37fd3e2

Browse files
authored
fix: sanitize project name consistently (#732)
1 parent c050c2d commit 37fd3e2

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ generate-changelog.sh
4343
letsencrypt/*
4444
result
4545
dist/
46+
letsencrypt/

cert.sh

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22

33
set -euo pipefail
44

5-
docker run -it --rm \
6-
--name certbot \
7-
-e AWS_ACCESS_KEY_ID \
8-
-e AWS_SECRET_ACCESS_KEY \
9-
-e AWS_REGION \
10-
-v $(PWD)/letsencrypt:/etc/letsencrypt \
11-
-v $(PWD)/letsencrypt:/var/lib/letsencrypt \
12-
certbot/dns-route53 certonly -v --dns-route53 --dns-route53-propagation-seconds 60 -d local.db.nhost.run -d local.graphql.nhost.run -d local.hasura.nhost.run -d local.auth.nhost.run -d local.storage.nhost.run -d local.functions.nhost.run -m '[email protected]' --non-interactive --agree-tos --server https://acme-v02.api.letsencrypt.org/directory
5+
certbot certonly \
6+
-v \
7+
--dns-route53 \
8+
--dns-route53-propagation-seconds 60 \
9+
-d local.db.nhost.run \
10+
-d local.graphql.nhost.run \
11+
-d local.hasura.nhost.run \
12+
-d local.auth.nhost.run \
13+
-d local.storage.nhost.run \
14+
-d local.functions.nhost.run \
15+
16+
--non-interactive \
17+
--agree-tos \
18+
--server https://acme-v02.api.letsencrypt.org/directory \
19+
--logs-dir letsencrypt \
20+
--config-dir letsencrypt \
21+
--work-dir letsencrypt
1322

1423
cp letsencrypt/live/local.db.nhost.run/fullchain.pem internal/ssl/.ssl/
1524
cp letsencrypt/live/local.db.nhost.run/privkey.pem internal/ssl/.ssl/
25+
26+
rm -rf letsencrypt

clienv/clienv.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ package clienv
33
import (
44
"io"
55
"os"
6+
"regexp"
7+
"strings"
68

79
"github.com/nhost/cli/nhostclient"
810
"github.com/urfave/cli/v2"
911
)
1012

13+
func sanitizeName(name string) string {
14+
re := regexp.MustCompile(`[^a-z0-9_-]`)
15+
return strings.ToLower(re.ReplaceAllString(name, ""))
16+
}
17+
1118
type CliEnv struct {
1219
stdout io.Writer
1320
stderr io.Writer
@@ -50,7 +57,7 @@ func FromCLI(cCtx *cli.Context) *CliEnv {
5057
cCtx.String(flagNhostFolder),
5158
),
5259
domain: cCtx.String(flagDomain),
53-
projectName: cCtx.String(flagProjectName),
60+
projectName: sanitizeName(cCtx.String(flagProjectName)),
5461
nhclient: nil,
5562
}
5663
}

cmd/dev/up.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func commandUp(cCtx *cli.Context) error {
111111
return Up(
112112
cCtx.Context,
113113
ce,
114-
ce.ProjectName(),
115114
cCtx.Uint(flagHTTPPort),
116115
!cCtx.Bool(flagDisableTLS),
117116
cCtx.Uint(flagPostgresPort),
@@ -175,7 +174,6 @@ func up( //nolint:funlen
175174
ctx context.Context,
176175
ce *clienv.CliEnv,
177176
dc *dockercompose.DockerCompose,
178-
projectName string,
179177
httpPort uint,
180178
useTLS bool,
181179
postgresPort uint,
@@ -199,7 +197,7 @@ func up( //nolint:funlen
199197
ce.Infoln("Setting up Nhost development environment...")
200198
composeFile, err := dockercompose.ComposeFileFromConfig(
201199
cfg,
202-
projectName,
200+
ce.ProjectName(),
203201
httpPort,
204202
useTLS,
205203
postgresPort,
@@ -274,17 +272,16 @@ func printInfo(ce *clienv.CliEnv, httpPort, postgresPort uint, useTLS bool) {
274272
func Up(
275273
ctx context.Context,
276274
ce *clienv.CliEnv,
277-
projectName string,
278275
httpPort uint,
279276
useTLS bool,
280277
postgresPort uint,
281278
applySeeds bool,
282279
ports map[string]uint,
283280
) error {
284-
dc := dockercompose.New(ce.Path.WorkingDir(), ce.Path.DockerCompose(), projectName)
281+
dc := dockercompose.New(ce.Path.WorkingDir(), ce.Path.DockerCompose(), ce.ProjectName())
285282

286283
if err := up(
287-
ctx, ce, dc, projectName, httpPort, useTLS, postgresPort, applySeeds, ports,
284+
ctx, ce, dc, httpPort, useTLS, postgresPort, applySeeds, ports,
288285
); err != nil {
289286
ce.Warnln(err.Error())
290287

dockercompose/dockercompose.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"io/fs"
99
"os"
1010
"os/exec"
11-
"regexp"
12-
"strings"
1311

1412
"github.com/creack/pty"
1513
"gopkg.in/yaml.v3"
@@ -23,16 +21,11 @@ type DockerCompose struct {
2321
projectName string
2422
}
2523

26-
func sanitizeName(name string) string {
27-
re := regexp.MustCompile(`[^a-z0-9_-]`)
28-
return strings.ToLower(re.ReplaceAllString(name, ""))
29-
}
30-
3124
func New(workingDir, filepath, projectName string) *DockerCompose {
3225
return &DockerCompose{
3326
workingDir: workingDir,
3427
filepath: filepath,
35-
projectName: sanitizeName(projectName),
28+
projectName: projectName,
3629
}
3730
}
3831

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
default = pkgs.mkShell {
125125
buildInputs = with pkgs; [
126126
goreleaser
127+
certbot-full
127128
] ++ goCheckDeps ++ buildInputs ++ nativeBuildInputs;
128129
};
129130

0 commit comments

Comments
 (0)