-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (71 loc) · 2.23 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
87
88
89
package main
import (
"context"
"fmt"
"log"
"github.com/gin-gonic/gin"
"github.com/kelseyhightower/envconfig"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
)
const _projectName = "bus"
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
var cfg config
if err := envconfig.Process("", &cfg); err != nil {
return fmt.Errorf("read config: %w", err)
}
if err := installPulumiPlugins(context.TODO()); err != nil {
return fmt.Errorf("installing pulumi plugins: %w", err)
}
project := auto.Project(workspace.Project{
Name: tokens.PackageName(_projectName),
Runtime: workspace.NewProjectRuntimeInfo("go", nil),
Backend: &workspace.ProjectBackend{
URL: cfg.BackendURL,
},
})
workDir := auto.WorkDir(".")
router := gin.Default()
api := router.Group("/api")
{
api.POST("/environments", createEnvironment(cfg, project, workDir))
api.GET("/environments", listEnvironment(cfg, project, workDir))
api.GET("/environments/history/:name", historyEnvironment(cfg, project, workDir))
api.GET("/environments/export/:name", exportEnvironment(cfg, project, workDir))
api.GET("/environments/:name", getEnvironment(cfg, project, workDir))
api.POST("/environments/preview/:name", previewEnvironment(cfg, project, workDir))
api.POST("/environments/refresh/:name", refreshEnvironment(cfg, project, workDir))
api.POST("/environments/import/:name", importEnvironment(cfg, project, workDir))
api.PUT("/environments/:name", updateEnvironment(cfg, project, workDir))
api.DELETE("/environments/:name", deleteEnvironment(cfg, project, workDir))
}
if err := router.Run(fmt.Sprintf(":%d", cfg.Port)); err != nil {
return err
}
return nil
}
func installPulumiPlugins(ctx context.Context) error {
w, err := auto.NewLocalWorkspace(ctx)
if err != nil {
return err
}
if err := w.InstallPlugin(ctx, "aws", "v4.9.0"); err != nil {
return err
}
if err := w.InstallPlugin(ctx, "github", "v4.2.0"); err != nil {
return err
}
if err := w.InstallPlugin(ctx, "random", "v4.2.0"); err != nil {
return err
}
if err := w.InstallPlugin(ctx, "cloudamqp", "v3.1.0"); err != nil {
return err
}
return nil
}