carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "context"
5 "encoding/json"
6 "flag"
7 "fmt"
8 "log"
9 "net/http"
10 "os"
11)
12
13// systemLegacyRoutesVerb is the line carlos system's usage puts under the
14// legacy-routes assign verb.
15const systemLegacyRoutesVerb = "say which account and app the routes an operator filed by hand belong to"
16
17// runSystemLegacyRoutesVerb is `carlos system legacy-routes assign`
18// (seeded-instances spec §6.4): which account and app the routes an
19// operator filed by hand under the operator account belong to.
20func runSystemLegacyRoutesVerb(rest []string) {
21 if len(rest) == 0 || rest[0] != "assign" {
22 systemUsage()
23 os.Exit(2)
24 }
25 fs := flag.NewFlagSet("system legacy-routes assign", flag.ExitOnError)
26 consoleFlag := consoleOption(fs, "console origin (default: the only logged-in one)")
27 name := fs.String("name", "", "the app name the legacy routes are filed under, in the operator account")
28 to := fs.String("to", "", "the account and app they belong to, as <account>/<app>")
29 fs.Parse(rest[1:])
30 if *name == "" || *to == "" || fs.NArg() != 0 {
31 fs.Usage()
32 os.Exit(2)
33 }
34 sess := requireDeployAPISession(*consoleFlag)
35 printUsing(stdout, sess)
36 status, body, err := sess.postJSON(context.Background(), "/api/cli/system/legacy-routes", map[string]string{"name": *name, "to": *to})
37 if err != nil {
38 log.Fatalf("carlos system legacy-routes assign: %v", err)
39 }
40 if status != http.StatusOK {
41 log.Fatalf("carlos system legacy-routes assign: %v", apiErrorFromBody(status, body))
42 }
43 var out struct {
44 Name string `json:"name"`
45 Account string `json:"account"`
46 App string `json:"app"`
47 }
48 if err := json.Unmarshal(body, &out); err != nil {
49 log.Fatalf("carlos system legacy-routes assign: unreadable response: %v", err)
50 }
51 fmt.Fprintln(stdout, fmt.Sprintf("assigned the legacy routes named %s to %s/%s", out.Name, out.Account, out.App))
52}
53