Sfoglia il codice sorgente

Add command for generating secrets

tags/v2.0.0-rc1
9seconds 5 anni fa
parent
commit
6f0b0e0c32
4 ha cambiato i file con 49 aggiunte e 4 eliminazioni
  1. 17
    0
      cli_generate_secret.go
  2. 1
    0
      go.mod
  3. 4
    0
      go.sum
  4. 27
    4
      main.go

+ 17
- 0
cli_generate_secret.go Vedi File

@@ -0,0 +1,17 @@
1
+package main
2
+
3
+import (
4
+	"fmt"
5
+
6
+	"github.com/9seconds/mtg/v2/mtglib"
7
+)
8
+
9
+func runGenerateSecret(cli *CLI) {
10
+	secret := mtglib.GenerateSecret(cli.GenerateSecret.HostName)
11
+
12
+	if cli.GenerateSecret.Hex {
13
+		fmt.Println(secret.EE())
14
+	} else {
15
+		fmt.Println(secret.Base64())
16
+	}
17
+}

+ 1
- 0
go.mod Vedi File

@@ -3,6 +3,7 @@ module github.com/9seconds/mtg/v2
3 3
 go 1.16
4 4
 
5 5
 require (
6
+	github.com/alecthomas/kong v0.2.16
6 7
 	github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15
7 8
 	github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
8 9
 	github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6

+ 4
- 0
go.sum Vedi File

@@ -1,3 +1,5 @@
1
+github.com/alecthomas/kong v0.2.16 h1:F232CiYSn54Tnl1sJGTeHmx4vJDNLVP2b9yCVMOQwHQ=
2
+github.com/alecthomas/kong v0.2.16/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
1 3
 github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 h1:AUNCr9CiJuwrRYS3XieqF+Z9B9gNxo/eANAJCF2eiN4=
2 4
 github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
3 5
 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
@@ -18,6 +20,7 @@ github.com/mccutchen/go-httpbin v1.1.1 h1:aEws49HEJEyXHLDnshQVswfUlCVoS8g6h9YaDy
18 20
 github.com/mccutchen/go-httpbin v1.1.1/go.mod h1:fhpOYavp5g2K74XDl/ao2y4KvhqVtKlkg1e+0UaQv7I=
19 21
 github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM=
20 22
 github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
23
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
21 24
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
22 25
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
23 26
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -25,6 +28,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
25 28
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
26 29
 github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
27 30
 github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
31
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
28 32
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
29 33
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
30 34
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=

+ 27
- 4
main.go Vedi File

@@ -1,18 +1,41 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"math/rand"
6
-	"os"
7 5
 	"time"
6
+
7
+	"github.com/alecthomas/kong"
8 8
 )
9 9
 
10 10
 var version = "dev" // has to be set by ldflags
11 11
 
12
+type CLI struct {
13
+	GenerateSecret struct {
14
+		HostName string `arg optional help:"Hostname to use for domain fronting. Default is '${domain_front}'." name:"hostname" default:"${domain_front}"`
15
+		Hex      bool   `help:"Print secret in hex encoding."`
16
+	} `cmd help:"Generate new proxy secret."`
17
+	Access struct {
18
+		ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"`
19
+	} `cmd help:"Print access information."`
20
+	Run struct {
21
+		ConfigPath string `arg required type:"existingfile" help:"Path to the configuration file." name:"config-path"`
22
+	} `cmd help:"Run proxy."`
23
+}
24
+
12 25
 func main() {
13 26
 	rand.Seed(time.Now().UTC().UnixNano())
14 27
 
15
-	f, _ := os.Open("example.config.toml")
28
+	cli := &CLI{}
29
+	ctx := kong.Parse(cli, kong.Vars{
30
+		"domain_front": "amazonaws.com",
31
+		"config_path":  "/etc/mtg.toml",
32
+	})
16 33
 
17
-	fmt.Println(parseConfig(f))
34
+	switch ctx.Command() {
35
+	case "generate-secret":
36
+		runGenerateSecret(cli)
37
+	case "access":
38
+	case "run":
39
+		panic("not implemented yet")
40
+	}
18 41
 }

Loading…
Annulla
Salva