diff options
| author | mo khan <mo@mokhan.ca> | 2025-05-02 14:29:41 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-05-02 14:29:41 -0600 |
| commit | c583bcd1473205104a1e1af812ed4976d30c7baa (patch) | |
| tree | 933edf78a4ac8aea55256e42641e56bbb4c58834 /magefiles | |
| parent | 91defaefca47e9cebbe92c6abf33c4423df9bc7d (diff) | |
refactor: remove anything unrelated to the authz daemon
Diffstat (limited to 'magefiles')
| -rw-r--r-- | magefiles/magefile.go | 52 | ||||
| -rw-r--r-- | magefiles/step.go | 147 |
2 files changed, 4 insertions, 195 deletions
diff --git a/magefiles/magefile.go b/magefiles/magefile.go index 71aa3bc8..06dc0251 100644 --- a/magefiles/magefile.go +++ b/magefiles/magefile.go @@ -16,49 +16,10 @@ import ( // If not set, running mage will list available targets var Default = Servers -// Run the Identity Provider -func Idp() error { - env := map[string]string{ - "SCHEME": "http", - "PORT": "8282", - "HOST": "idp.example.com:8080", - } - return sh.RunWithV(env, "ruby", "./bin/idp") -} - -// Run the UI (a.k.a Service Provider) -func UI() error { - env := map[string]string{ - "SCHEME": "http", - "PORT": "8283", - "HOST": "ui.example.com:8080", - "IDP_HOST": "idp.example.com:8080", - } - return sh.RunWithV(env, "ruby", "./bin/ui") -} - -// Run the API Gateway -func Gateway() error { - env := map[string]string{ - "BIND_ADDR": ":8080", - } - return sh.RunWithV(env, "go", "run", "./cmd/gtwy/main.go") -} - -// Run the REST API -func Api() error { - env := map[string]string{ - "SCHEME": "http", - "PORT": "8284", - "HOST": "localhost:8284", - } - return sh.RunWithV(env, "ruby", "./bin/api") -} - // Run the Authzd Service func Authzd() error { env := map[string]string{ - "BIND_ADDR": ":50051", + "BIND_ADDR": ":8080", } return sh.RunWithV(env, "go", "run", "./cmd/authzd/main.go") } @@ -82,13 +43,8 @@ func Protos() error { if err := sh.RunV( "protoc", "--proto_path=./protos", - "--go_out=pkg/rpc", - "--go_opt=paths=source_relative", - "--go-grpc_out=pkg/rpc", - "--go-grpc_opt=paths=source_relative", - "--twirp_out=pkg/rpc", - "--ruby_out=lib/authx/rpc", - "--twirp_ruby_out=lib/authx/rpc", + "--go_out=.", + "--twirp_out=.", file, ); err != nil { return err @@ -100,7 +56,7 @@ func Protos() error { // Run All the servers func Servers(ctx context.Context) { - mg.CtxDeps(ctx, (Step{}).Server, Nats, Idp, UI, Api, Authzd, Gateway) + mg.CtxDeps(ctx, Nats, Authzd) } // Run the end to end tests diff --git a/magefiles/step.go b/magefiles/step.go deleted file mode 100644 index 25cf23b0..00000000 --- a/magefiles/step.go +++ /dev/null @@ -1,147 +0,0 @@ -//go:build mage -// +build mage - -package main - -import ( - "context" - "encoding/json" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" - "github.com/magefile/mage/target" - "github.com/xlgmokha/x/pkg/env" - "github.com/xlgmokha/x/pkg/x" -) - -type Step mg.Namespace - -func (s Step) Clean() error { - globs := []string{ - "tmp/step/*/*", - } - for _, item := range globs { - fs, err := filepath.Glob(item) - if err != nil { - return err - } - for _, f := range fs { - if strings.HasSuffix(f, "/.keep") { - continue - } - if err := os.RemoveAll(f); err != nil { - return err - } - } - } - return nil -} - -func (s Step) Setup() { - mg.SerialDeps(s.mkPassword, s.createCA, s.enableACMEProvisioner) -} - -func (s Step) Install() error { - return sh.RunWithV( - s.env(), - "step", - "certificate", - "install", - s.pathPlus("/certs/root_ca.crt"), - ) -} - -func (s Step) Server(ctx context.Context) error { - mg.SerialDeps(s.Setup) - - return sh.RunWithV( - s.env(), - "step-ca", - s.pathPlus("config/ca.json"), - "--password-file="+s.pathPlus("password.txt"), - ) -} - -func (s Step) Provisioners() error { - return sh.RunV("curl", "-k", "-s", "https://localhost:8081/provisioners") -} - -func (s Step) ACME() error { - return sh.RunV("curl", "-k", "-s", "https://localhost:8081/acme/acme/directory") -} - -func (s Step) Status() { - mg.SerialDeps(s.Provisioners, s.ACME) -} - -func (s Step) mkPassword() error { - file := s.passwordFile() - if ok, err := target.Dir(file); err != nil || !ok { - return nil - } - - return os.WriteFile(file, []byte("password"), 0600) -} - -func (s Step) createCA() error { - if ok, err := target.Dir(s.pathPlus("config/ca.json"), s.passwordFile()); err != nil || !ok { - return nil - } - - return sh.RunWithV( - s.env(), - "step", - "ca", - "init", - "--deployment-type=standalone", - "--address=localhost:8081", - "--dns=localhost", - "--dns=*.localhost", - "--name=CA", - "--provisioner=example", - "--provisioner-password-file="+s.passwordFile(), - "--password-file="+s.passwordFile(), - ) -} - -func (s Step) enableACMEProvisioner() error { - bytes, err := ioutil.ReadFile(s.pathPlus("config/ca.json")) - if err != nil { - return err - } - - items := map[string]interface{}{} - if err := json.Unmarshal(bytes, &items); err != nil { - return err - } - - provisioners := items["authority"].(map[string]interface{})["provisioners"].([]interface{}) - if len(provisioners) < 2 { - return sh.RunWithV(s.env(), "step", "ca", "provisioner", "add", "acme", "--type", "ACME") - } - return nil -} - -func (step Step) passwordFile() string { - return step.pathPlus("password.txt") -} - -func (s Step) path() string { - return env.Fetch("STEPPATH", filepath.Join(x.Must(os.Getwd()), "/tmp/step")) -} - -func (s Step) env() map[string]string { - return map[string]string{ - "STEPPATH": s.path(), - "HOST": "localhost", - "PORT": "8081", - } -} - -func (s Step) pathPlus(path string) string { - return filepath.Join(s.path(), path) -} |
