blob: 32d5c4281d60b11cf89217ef9fcabfa116b3614d [file] [log] [blame]
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04001package main
2
3import (
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04004 "os"
5
giof8843412024-05-22 16:38:05 +04006 "github.com/giolekva/pcloud/core/installer"
gio59946282024-10-07 12:55:51 +04007 "github.com/giolekva/pcloud/core/installer/server/welcome"
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +04008 "github.com/giolekva/pcloud/core/installer/soft"
Giorgi Lekveishvili83b72192024-03-11 18:36:14 +04009 "github.com/spf13/cobra"
10 "golang.org/x/crypto/ssh"
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040011)
12
13var welcomeFlags struct {
gio2728e402024-08-01 18:14:21 +040014 repo string
15 sshKey string
16 port int
17 createAccountAddr string
18 loginAddr string
19 membershipsAddr string
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040020}
21
22func welcomeCmd() *cobra.Command {
23 cmd := &cobra.Command{
24 Use: "welcome",
25 RunE: welcomeCmdRun,
26 }
27 cmd.Flags().StringVar(
28 &welcomeFlags.repo,
29 "repo-addr",
30 "",
31 "",
32 )
33 cmd.Flags().StringVar(
34 &welcomeFlags.sshKey,
35 "ssh-key",
36 "",
37 "",
38 )
39 cmd.Flags().IntVar(
40 &welcomeFlags.port,
41 "port",
42 8080,
43 "",
44 )
Giorgi Lekveishvilic89b9002023-12-21 13:09:26 +040045 cmd.Flags().StringVar(
46 &welcomeFlags.createAccountAddr,
47 "create-account-addr",
48 "",
49 "",
50 )
Giorgi Lekveishvili83b72192024-03-11 18:36:14 +040051 cmd.Flags().StringVar(
52 &welcomeFlags.loginAddr,
53 "login-addr",
54 "",
55 "",
56 )
Giorgi Lekveishvilid542b732024-03-25 18:17:39 +040057 cmd.Flags().StringVar(
gio2728e402024-08-01 18:14:21 +040058 &welcomeFlags.membershipsAddr,
59 "memberships-addr",
Giorgi Lekveishvilid542b732024-03-25 18:17:39 +040060 "",
61 "",
62 )
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040063 return cmd
64}
65
66func welcomeCmdRun(cmd *cobra.Command, args []string) error {
67 sshKey, err := os.ReadFile(welcomeFlags.sshKey)
68 if err != nil {
69 return err
70 }
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040071 signer, err := ssh.ParsePrivateKey(sshKey)
72 if err != nil {
73 return err
74 }
75 addr, err := soft.ParseRepositoryAddress(welcomeFlags.repo)
76 if err != nil {
77 return err
78 }
Giorgi Lekveishvili57dffb32023-08-07 15:45:43 +040079 repo, err := soft.CloneRepository(addr, signer)
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040080 if err != nil {
81 return err
82 }
gioe72b54f2024-04-22 10:44:41 +040083 repoIO, err := soft.NewRepoIO(repo, signer)
gio3af43942024-04-16 08:13:50 +040084 if err != nil {
85 return err
86 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040087 nsCreator, err := newNSCreator()
88 if err != nil {
89 return err
90 }
giodd213152024-09-27 11:26:59 +020091 s, err := welcome.NewServer(
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040092 welcomeFlags.port,
gio3af43942024-04-16 08:13:50 +040093 repoIO,
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040094 nsCreator,
giof8843412024-05-22 16:38:05 +040095 installer.NewGitHelmFetcher(),
Giorgi Lekveishvilic89b9002023-12-21 13:09:26 +040096 welcomeFlags.createAccountAddr,
Giorgi Lekveishvili83b72192024-03-11 18:36:14 +040097 welcomeFlags.loginAddr,
gio2728e402024-08-01 18:14:21 +040098 welcomeFlags.membershipsAddr,
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040099 )
giodd213152024-09-27 11:26:59 +0200100 if err != nil {
101 return err
102 }
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +0400103 s.Start()
104 return nil
105}