blob: 64820e635fc2cc1c3b3516de8314ea46a9385599 [file] [log] [blame]
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04001package main
2
3import (
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04004 "os"
5
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +04006 "github.com/giolekva/pcloud/core/installer/soft"
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +04007 "github.com/giolekva/pcloud/core/installer/welcome"
Giorgi Lekveishvili83b72192024-03-11 18:36:14 +04008 "github.com/spf13/cobra"
9 "golang.org/x/crypto/ssh"
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040010)
11
12var welcomeFlags struct {
Giorgi Lekveishvilid542b732024-03-25 18:17:39 +040013 repo string
14 sshKey string
15 port int
16 createAccountAddr string
17 loginAddr string
18 membershipsInitAddr string
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040019}
20
21func welcomeCmd() *cobra.Command {
22 cmd := &cobra.Command{
23 Use: "welcome",
24 RunE: welcomeCmdRun,
25 }
26 cmd.Flags().StringVar(
27 &welcomeFlags.repo,
28 "repo-addr",
29 "",
30 "",
31 )
32 cmd.Flags().StringVar(
33 &welcomeFlags.sshKey,
34 "ssh-key",
35 "",
36 "",
37 )
38 cmd.Flags().IntVar(
39 &welcomeFlags.port,
40 "port",
41 8080,
42 "",
43 )
Giorgi Lekveishvilic89b9002023-12-21 13:09:26 +040044 cmd.Flags().StringVar(
45 &welcomeFlags.createAccountAddr,
46 "create-account-addr",
47 "",
48 "",
49 )
Giorgi Lekveishvili83b72192024-03-11 18:36:14 +040050 cmd.Flags().StringVar(
51 &welcomeFlags.loginAddr,
52 "login-addr",
53 "",
54 "",
55 )
Giorgi Lekveishvilid542b732024-03-25 18:17:39 +040056 cmd.Flags().StringVar(
57 &welcomeFlags.membershipsInitAddr,
58 "memberships-init-addr",
59 "",
60 "",
61 )
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040062 return cmd
63}
64
65func welcomeCmdRun(cmd *cobra.Command, args []string) error {
66 sshKey, err := os.ReadFile(welcomeFlags.sshKey)
67 if err != nil {
68 return err
69 }
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040070 signer, err := ssh.ParsePrivateKey(sshKey)
71 if err != nil {
72 return err
73 }
74 addr, err := soft.ParseRepositoryAddress(welcomeFlags.repo)
75 if err != nil {
76 return err
77 }
Giorgi Lekveishvili57dffb32023-08-07 15:45:43 +040078 repo, err := soft.CloneRepository(addr, signer)
Giorgi Lekveishvili94cda9d2023-07-20 10:16:09 +040079 if err != nil {
80 return err
81 }
gioe72b54f2024-04-22 10:44:41 +040082 repoIO, err := soft.NewRepoIO(repo, signer)
gio3af43942024-04-16 08:13:50 +040083 if err != nil {
84 return err
85 }
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040086 nsCreator, err := newNSCreator()
87 if err != nil {
88 return err
89 }
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040090 s := welcome.NewServer(
91 welcomeFlags.port,
gio3af43942024-04-16 08:13:50 +040092 repoIO,
Giorgi Lekveishvili7fb28bf2023-06-24 19:51:16 +040093 nsCreator,
Giorgi Lekveishvilic89b9002023-12-21 13:09:26 +040094 welcomeFlags.createAccountAddr,
Giorgi Lekveishvili83b72192024-03-11 18:36:14 +040095 welcomeFlags.loginAddr,
Giorgi Lekveishvilid542b732024-03-25 18:17:39 +040096 welcomeFlags.membershipsInitAddr,
Giorgi Lekveishvili12850ee2023-06-22 13:11:17 +040097 )
98 s.Start()
99 return nil
100}