Skip to content

Commit ed6b84b

Browse files
author
Jyny Chen
committed
change description and rm util
1 parent 2d7414b commit ed6b84b

File tree

14 files changed

+71
-90
lines changed

14 files changed

+71
-90
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Outliner
2-
**CLI tool for Auto setup and deploy outline VPN**
2+
**CLI tool for auto setup Outline VPN server**
33

44
[![asciicast](https://asciinema.org/a/laneLnHnXKy1tO2k2f9ETsLyQ.svg)](https://asciinema.org/a/laneLnHnXKy1tO2k2f9ETsLyQ)
55
```
66
$ outliner --help
7-
Auto setup & deploy tool for outline VPN server
7+
CLI tool for auto setup Outline VPN server
88
99
Usage:
1010
outliner [command]

command/create.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/spf13/viper"
66

77
ol "github.com/jyny/outliner/pkg/outliner"
8-
"github.com/jyny/outliner/pkg/util"
98
)
109

1110
func init() {
@@ -26,7 +25,7 @@ var createCmd = &cobra.Command{
2625
Short: "create a Server",
2726
Long: `create a Server`,
2827
PreRun: func(cmd *cobra.Command, args []string) {
29-
util.PrintCreateInstanceStart()
28+
printCreateInstanceStart()
3029
},
3130
Run: func(cmd *cobra.Command, args []string) {
3231
inst, err := cloud.CreateInstance(ol.Instance{
@@ -42,19 +41,19 @@ var createCmd = &cobra.Command{
4241
if err != nil {
4342
panic(err)
4443
}
45-
util.PrintCreateInstanceWait()
44+
printCreateInstanceWait()
4645
err = cloud.WaitInstance(inst)
4746
if err != nil {
4847
panic(err)
4948
}
50-
util.PrintCreateInstanceDone()
51-
util.PrintInstancesTable([]ol.Instance{inst})
49+
printCreateInstanceDone()
50+
printInstancesTable([]ol.Instance{inst})
5251
viper.Set("deploy_ip", inst.IPv4)
5352
},
5453
PostRun: func(cmd *cobra.Command, args []string) {
55-
if util.ContinueInteractive() {
54+
if continueInteractive() {
5655
deployCmd.PreRun(deployCmd, []string{})
57-
util.Waitforawhile()
56+
waitforawhile()
5857
deployCmd.Run(deployCmd, []string{})
5958
deployCmd.PostRun(deployCmd, []string{})
6059
}

command/deploy.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package command
33
import (
44
"github.com/spf13/cobra"
55
"github.com/spf13/viper"
6-
7-
"github.com/jyny/outliner/pkg/util"
86
)
97

108
func init() {
@@ -19,20 +17,20 @@ var deployCmd = &cobra.Command{
1917
Short: "deploy outliner to Server",
2018
Long: `deploy outliner to Server`,
2119
PreRun: func(cmd *cobra.Command, args []string) {
22-
util.PrintDeployInstanceStart()
20+
printDeployInstanceStart()
2321
},
2422
Run: func(cmd *cobra.Command, args []string) {
2523
ip := viper.GetString("deploy_ip")
2624
err := deployer.DeployService(ip)
2725
if err != nil {
2826
panic(err)
2927
}
30-
util.PrintDeployInstanceWait()
28+
printDeployInstanceWait()
3129
err = deployer.WaitService(ip)
3230
if err != nil {
3331
panic(err)
3432
}
35-
util.PrintDeployInstanceDone()
33+
printDeployInstanceDone()
3634
viper.Set("inspect_ip", ip)
3735

3836
},

command/destroy.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package command
33
import (
44
"github.com/spf13/cobra"
55
"github.com/spf13/viper"
6-
"log"
7-
8-
"github.com/jyny/outliner/pkg/util"
96
)
107

118
func init() {
@@ -20,17 +17,17 @@ var destroyCmd = &cobra.Command{
2017
Short: "destroy a Server",
2118
Long: `destroy a Server`,
2219
PreRun: func(cmd *cobra.Command, args []string) {
23-
util.PrintDestroyInstanceStart()
20+
printDestroyInstanceStart()
2421
},
2522
Run: func(cmd *cobra.Command, args []string) {
2623
id := viper.GetString("destroy_id")
27-
log.Println(id)
24+
printDestroyInstanceID(id)
2825
err := cloud.DestroyInstance(id)
2926
if err != nil {
3027
panic(err)
3128
}
3229
},
3330
PostRun: func(cmd *cobra.Command, args []string) {
34-
util.PrintDestroyInstanceDone()
31+
printDestroyInstanceDone()
3532
},
3633
}

command/inspect.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/spf13/viper"
66

77
ol "github.com/jyny/outliner/pkg/outliner"
8-
"github.com/jyny/outliner/pkg/util"
98
)
109

1110
func init() {
@@ -23,7 +22,7 @@ var inspectCmd = &cobra.Command{
2322
ip := viper.GetString("inspect_ip")
2423
inst, err := cloud.InspectInstanceByIP(ip)
2524
if err == nil {
26-
util.PrintInstancesTable([]ol.Instance{inst})
25+
printInstancesTable([]ol.Instance{inst})
2726
}
2827
},
2928
Run: func(cmd *cobra.Command, args []string) {
@@ -32,7 +31,7 @@ var inspectCmd = &cobra.Command{
3231
if err != nil {
3332
panic(err)
3433
}
35-
util.PrintAPICertTable(apicert)
36-
util.PrintAPICertJSON(apicert)
34+
printAPICertTable(apicert)
35+
printAPICertJSON(apicert)
3736
},
3837
}

command/list.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package command
22

33
import (
44
"github.com/spf13/cobra"
5-
6-
"github.com/jyny/outliner/pkg/util"
75
)
86

97
func init() {
@@ -40,7 +38,7 @@ var instCmd = &cobra.Command{
4038
if err != nil {
4139
panic(err)
4240
}
43-
util.PrintInstancesTable(insts)
41+
printInstancesTable(insts)
4442
},
4543
}
4644

@@ -53,7 +51,7 @@ var regineCmd = &cobra.Command{
5351
if err != nil {
5452
panic(err)
5553
}
56-
util.PrintRegionsTable(regs)
54+
printRegionsTable(regs)
5755
},
5856
}
5957

@@ -66,7 +64,7 @@ var specCmd = &cobra.Command{
6664
if err != nil {
6765
panic(err)
6866
}
69-
util.PrintSpecsTable(specs)
67+
printSpecsTable(specs)
7068
},
7169
}
7270

@@ -79,6 +77,6 @@ var providerCmd = &cobra.Command{
7977
if err != nil {
8078
panic(err)
8179
}
82-
util.PrintProvidersTable(pvdrs)
80+
printProvidersTable(pvdrs)
8381
},
8482
}

pkg/util/printer.go command/printer.go

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package util
1+
package command
22

33
import (
44
"encoding/json"
@@ -12,7 +12,7 @@ import (
1212
ol "github.com/jyny/outliner/pkg/outliner"
1313
)
1414

15-
func PrintRegionsTable(in map[string][]ol.Region) {
15+
func printRegionsTable(in map[string][]ol.Region) {
1616
var data [][]string
1717
for pname, p := range in {
1818
for _, r := range p {
@@ -35,7 +35,7 @@ func PrintRegionsTable(in map[string][]ol.Region) {
3535
table.Render()
3636
}
3737

38-
func PrintSpecsTable(in map[string][]ol.Spec) {
38+
func printSpecsTable(in map[string][]ol.Spec) {
3939
var data [][]string
4040
for pname, p := range in {
4141
for _, s := range p {
@@ -60,7 +60,7 @@ func PrintSpecsTable(in map[string][]ol.Spec) {
6060
table.Render()
6161
}
6262

63-
func PrintProvidersTable(in [][]string) {
63+
func printProvidersTable(in [][]string) {
6464
var data [][]string
6565
for _, p := range in {
6666
data = append(data, []string{
@@ -79,7 +79,7 @@ func PrintProvidersTable(in [][]string) {
7979
table.Render()
8080
}
8181

82-
func PrintInstancesTable(in []ol.Instance) {
82+
func printInstancesTable(in []ol.Instance) {
8383
var data [][]string
8484
for _, i := range in {
8585
data = append(data, []string{
@@ -104,7 +104,7 @@ func PrintInstancesTable(in []ol.Instance) {
104104
table.Render()
105105
}
106106

107-
func PrintAPICertTable(in ol.APICert) {
107+
func printAPICertTable(in ol.APICert) {
108108
var data [][]string
109109
data = append(data, []string{
110110
in.APIurl,
@@ -121,7 +121,7 @@ func PrintAPICertTable(in ol.APICert) {
121121
table.Render()
122122
}
123123

124-
func PrintAPICertJSON(in ol.APICert) {
124+
func printAPICertJSON(in ol.APICert) {
125125
b, err := json.Marshal(in)
126126
if err != nil {
127127
log.Println(err)
@@ -137,38 +137,42 @@ func PrintAPICertJSON(in ol.APICert) {
137137
fmt.Println()
138138
}
139139

140-
func PrintCreateInstanceStart() {
140+
func printCreateInstanceStart() {
141141
log.Println("[Creating Server]")
142142
}
143143

144-
func PrintCreateInstanceWait() {
144+
func printCreateInstanceWait() {
145145
log.Println("[Wait Server to startup]")
146146
}
147147

148-
func PrintCreateInstanceDone() {
148+
func printCreateInstanceDone() {
149149
log.Println("[Server Created]")
150150
}
151151

152-
func PrintDestroyInstanceStart() {
152+
func printDestroyInstanceStart() {
153153
log.Println("[Destroying Server]")
154154
}
155155

156-
func PrintDestroyInstanceDone() {
156+
func printDestroyInstanceID(id string) {
157+
log.Println("[Destroying]", id)
158+
}
159+
160+
func printDestroyInstanceDone() {
157161
log.Println("[Server Destroid]")
158162
}
159163

160-
func PrintDeployInstanceStart() {
164+
func printDeployInstanceStart() {
161165
log.Println("[Deploying Server]")
162166
}
163167

164-
func PrintDeployInstanceWait() {
168+
func printDeployInstanceWait() {
165169
log.Println("[Wait deployment to completed]")
166170
}
167171

168-
func PrintDeployInstanceDone() {
172+
func printDeployInstanceDone() {
169173
log.Println("[Server Deployed]")
170174
}
171175

172-
func PrintVersion(v string) {
176+
func printVersion(v string) {
173177
fmt.Println(v)
174178
}
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
package util
1+
package command
22

33
import (
44
"fmt"
5+
"time"
56

67
"github.com/Songmu/prompter"
78
)
89

9-
func ContinueInteractive() bool {
10+
func continueInteractive() bool {
1011
fmt.Println("The next step is to deploy.")
1112
fmt.Println("Deploy outliner VPN to server just create.")
1213
fmt.Println("You can continue to auto deploy or Do it your self.")
1314
fmt.Println("This is same as `./outliner deploy -i {SERVER_IP}`.")
1415
return prompter.YN("Do you want to continue to Auto Deploying", true)
1516
}
17+
18+
func waitforawhile() {
19+
time.Sleep(15 * time.Second)
20+
}

command/root.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package command
22

33
import (
4+
"errors"
45
"os/user"
56
"path/filepath"
67

78
"github.com/spf13/cobra"
89
"github.com/spf13/viper"
910

1011
ol "github.com/jyny/outliner/pkg/outliner"
11-
"github.com/jyny/outliner/pkg/util"
1212

1313
// deployer agnet
1414
"github.com/jyny/outliner/pkg/deployer/ssh"
@@ -30,8 +30,8 @@ var deployer = ol.NewDeployer()
3030
// RootCmd commands
3131
var RootCmd = &cobra.Command{
3232
Use: "outliner",
33-
Short: "Auto setup & deploy tool for outline VPN server",
34-
Long: "Auto setup & deploy tool for outline VPN server",
33+
Short: "CLI tool for auto setup Outline VPN server",
34+
Long: "CLI tool for auto setup Outline VPN server",
3535
}
3636

3737
// Execute entry of commandline
@@ -79,7 +79,7 @@ func initOutliner() {
7979

8080
// Activate & register cloud providers
8181
err := cloud.RegisterProvider(
82-
util.Validater,
82+
validater,
8383
linode.Activator{},
8484
//vultr.Activator{},
8585
//digitalocean.Activator{},
@@ -88,3 +88,13 @@ func initOutliner() {
8888
panic(err)
8989
}
9090
}
91+
92+
func validater(actvr ol.Activator) (ol.Provider, error) {
93+
for _, tokenName := range actvr.ListTokenName() {
94+
token := viper.GetString(tokenName)
95+
if actvr.VerifyToken(token) {
96+
return actvr.GenProvider(token), nil
97+
}
98+
}
99+
return nil, errors.New("invalid tokens")
100+
}

command/version.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package command
22

33
import (
44
"github.com/spf13/cobra"
5-
6-
"github.com/jyny/outliner/pkg/util"
75
)
86

97
func init() {
@@ -15,6 +13,6 @@ var versionCmd = &cobra.Command{
1513
Short: "show outliner version",
1614
Long: `show outliner version`,
1715
Run: func(cmd *cobra.Command, args []string) {
18-
util.PrintVersion(version)
16+
printVersion(version)
1917
},
2018
}

0 commit comments

Comments
 (0)