-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
86 lines (69 loc) · 2.52 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/spf13/cobra"
"namespacelabs.dev/foundation/cmd/nspipelines/cmd/github"
"namespacelabs.dev/foundation/cmd/nspipelines/cmd/runs"
workspaceCmd "namespacelabs.dev/foundation/cmd/nspipelines/cmd/workspace"
"namespacelabs.dev/foundation/internal/cli/cmd"
"namespacelabs.dev/foundation/internal/cli/fncobra"
"namespacelabs.dev/foundation/internal/console"
"namespacelabs.dev/foundation/internal/console/tui"
"namespacelabs.dev/foundation/internal/fnapi"
"namespacelabs.dev/foundation/internal/frontend/cuefrontend"
"namespacelabs.dev/foundation/internal/frontend/cuefrontendopaque"
"namespacelabs.dev/foundation/internal/parsing"
"namespacelabs.dev/foundation/internal/providers/aws/ecr"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/tasks"
"namespacelabs.dev/foundation/std/tasks/simplelog"
)
const maxLogLevel = 0
func main() {
root := &cobra.Command{
Use: "nspipelines",
TraverseChildren: true,
}
root.AddCommand(github.NewGithubCmd())
root.AddCommand(workspaceCmd.NewWorkspaceCmd())
root.AddCommand(runs.NewRunsCmd())
root.AddCommand(cmd.NewImagesCmd())
root.AddCommand(newRobotLogin("robot-login"))
ctx := tasks.WithSink(context.Background(), simplelog.NewSink(os.Stderr, maxLogLevel))
ecr.Register()
parsing.ModuleLoader = cuefrontend.ModuleLoader
parsing.MakeFrontend = func(pl parsing.EarlyPackageLoader, env *schema.Environment) parsing.Frontend {
return cuefrontend.NewFrontend(pl, cuefrontendopaque.NewFrontend(env, pl), env)
}
tasks.SetupFlags(root.PersistentFlags())
if err := root.ExecuteContext(ctx); err != nil {
log.Fatal(err)
}
}
func newRobotLogin(use string) *cobra.Command {
robotLogin := &cobra.Command{
Use: use,
Short: "Login as a robot.",
Args: cobra.ExactArgs(1),
Hidden: true,
RunE: fncobra.RunE(func(ctx context.Context, args []string) error {
accessToken, err := tui.AskSecret(ctx, "Which Access Token would you like to use today?", "That would be a Github access token.", "access token")
if err != nil {
return err
}
username, err := fnapi.LoginAsRobotAndStore(ctx, args[0], string(accessToken))
if err != nil {
return err
}
fmt.Fprintf(console.Stdout(ctx), "\nHi %s, you are now logged in, have a nice day.\n", username)
return nil
}),
}
return robotLogin
}