blob: a74369d27c9721c06e1a069b2e88a1f4827b2a26 [file] [log] [blame]
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +04001package main
2
3import (
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +04004 "log"
5 "os"
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +04006
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +04007 "github.com/spf13/cobra"
8
9 "github.com/giolekva/pcloud/core/installer"
10 "github.com/giolekva/pcloud/core/installer/soft"
Giorgi Lekveishvilib4a9c982023-06-22 15:17:02 +040011 "github.com/giolekva/pcloud/core/installer/welcome"
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040012)
13
14var envManagerFlags struct {
15 repoIP string
16 repoPort int
17 sshKey string
18 port int
19}
20
21func envManagerCmd() *cobra.Command {
22 cmd := &cobra.Command{
23 Use: "envmanager",
24 RunE: envManagerCmdRun,
25 }
26 cmd.Flags().StringVar(
27 &envManagerFlags.repoIP,
28 "repo-ip",
29 "",
30 "",
31 )
32 cmd.Flags().IntVar(
33 &envManagerFlags.repoPort,
34 "repo-port",
35 22,
36 "",
37 )
38 cmd.Flags().StringVar(
39 &envManagerFlags.sshKey,
40 "ssh-key",
41 "",
42 "",
43 )
44 cmd.Flags().IntVar(
45 &envManagerFlags.port,
46 "port",
47 8080,
48 "",
49 )
50 return cmd
51}
52
53func envManagerCmdRun(cmd *cobra.Command, args []string) error {
54 sshKey, err := os.ReadFile(envManagerFlags.sshKey)
55 if err != nil {
56 return err
57 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040058 ss, err := soft.NewClient(envManagerFlags.repoIP, envManagerFlags.repoPort, sshKey, log.Default())
59 if err != nil {
60 return err
61 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040062 repo, err := ss.GetRepo("pcloud")
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040063 if err != nil {
64 return err
65 }
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040066 repoIO := installer.NewRepoIO(repo, ss.Signer)
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040067 nsCreator, err := newNSCreator()
68 if err != nil {
69 return err
70 }
Giorgi Lekveishvilib4a9c982023-06-22 15:17:02 +040071 s := welcome.NewEnvServer(
72 envManagerFlags.port,
73 ss,
74 repoIO,
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040075 nsCreator,
Giorgi Lekveishvilib4a9c982023-06-22 15:17:02 +040076 )
77 s.Start()
Giorgi Lekveishvili0ccd1482023-06-21 15:02:24 +040078 return nil
79}