Skip to content

Commit fd40cb2

Browse files
committed
Reserved domain names
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent a99cbfe commit fd40cb2

File tree

629 files changed

+127319
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

629 files changed

+127319
-185
lines changed

Gopkg.lock

100755100644
Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@
4848
[prune]
4949
go-tests = true
5050
unused-packages = true
51+
52+
[[constraint]]
53+
name = "github.com/go-resty/resty"
54+
version = "1.4.0"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = 0.1.4
1+
VERSION = 0.2.4
22

33
publish:
44
git tag $(VERSION)

cmd/http.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

cmd/name.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

cmd/root.go

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,80 @@ package cmd
22

33
import (
44
"fmt"
5+
"net/http"
56
"os"
67

8+
"github.com/go-resty/resty"
9+
"github.com/labstack/gommon/log"
10+
"github.com/labstack/tunnel"
11+
"github.com/labstack/tunnel/util"
12+
713
"github.com/mitchellh/go-homedir"
814
"github.com/spf13/cobra"
915
"github.com/spf13/viper"
1016
)
1117

1218
var (
19+
err error
1320
configFile string
21+
name string
22+
tcp bool
23+
tls bool
24+
user string
1425
rootCmd = &cobra.Command{
1526
Use: "tunnel",
1627
Short: "Tunnel lets you expose local servers to the internet securely",
1728
Long: ``,
29+
Args: cobra.MinimumNArgs(1),
30+
Run: func(cmd *cobra.Command, args []string) {
31+
t := &tunnel.Tunnel{
32+
Host: "labstack.me:22",
33+
RemoteHost: "0.0.0.0",
34+
RemotePort: 80,
35+
}
36+
e := new(tunnel.Error)
37+
38+
if name != "" {
39+
key := viper.GetString("api_key")
40+
if key == "" {
41+
log.Fatalf("Failed to find api key in the config")
42+
}
43+
44+
// Find tunnel
45+
res, err := resty.R().
46+
SetAuthToken(key).
47+
SetHeader("Content-Type", "application/json").
48+
SetResult(t).
49+
SetError(e).
50+
SetHeader("User-Agent", "labstack/tunnel").
51+
Get(fmt.Sprintf("https://api.labstack.com/tunnels/%s", name))
52+
if err != nil {
53+
log.Fatalf("Failed to the find tunnel: %v", err)
54+
} else if res.StatusCode() != http.StatusOK {
55+
log.Fatalf("Failed to the find tunnel: %s", e.Message)
56+
}
57+
if t.Protocol == "tcp" {
58+
tcp = true
59+
} else if t.Protocol == "tls" {
60+
tls = true
61+
}
62+
63+
user = fmt.Sprintf("key=%s,name=%s", key, name)
64+
t.Host += ":22"
65+
} else if tls {
66+
user = "tls=true"
67+
}
68+
69+
t.User = user
70+
t.TargetHost, t.TargetPort, err = util.SplitHostPort(args[0])
71+
if err != nil {
72+
log.Fatalf("Failed to parse target address: %v", err)
73+
}
74+
if tcp || tls {
75+
t.RemotePort = 0
76+
}
77+
t.Create()
78+
},
1879
}
1980
)
2081

@@ -30,30 +91,29 @@ func Execute() {
3091
func init() {
3192
cobra.OnInitialize(initConfig)
3293
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "config file (default is $HOME/.tunnel.yaml)")
94+
rootCmd.PersistentFlags().StringVarP(&name, "name", "n", "", "tunnel name from the dashboard")
95+
rootCmd.PersistentFlags().BoolVarP(&tcp, "tcp", "", false, "tcp tunnel")
96+
rootCmd.PersistentFlags().BoolVarP(&tls, "tls", "", false, "tls tunnel")
3397
}
3498

35-
// initConfig reads in config file and ENV variables if set.
99+
// initConfig reads in config file and ENV variables if set
36100
func initConfig() {
37101
if configFile != "" {
38-
// Use config file from the flag.
102+
// Use config file from the flag
39103
viper.SetConfigFile(configFile)
40104
} else {
41-
// Find home directory.
105+
// Find home directory
42106
home, err := homedir.Dir()
43107
if err != nil {
44-
fmt.Println(err)
45-
os.Exit(1)
108+
log.Fatalf("Failed to find the home directory: %v", err)
46109
}
47110

48-
// Search config in home directory with name ".tunnel" (without extension).
111+
// Search config in home directory with name ".tunnel" (without extension)
49112
viper.AddConfigPath(home)
50113
viper.SetConfigName(".tunnel")
51114
}
52-
53-
viper.AutomaticEnv() // read in environment variables that match
54-
55-
// If a config file is found, read it in.
56-
if err := viper.ReadInConfig(); err == nil {
57-
// fmt.Println("Using config file:", viper.ConfigFileUsed())
115+
viper.AutomaticEnv() // Read in environment variables that match
116+
if err := viper.ReadInConfig(); err != nil {
117+
log.Fatalf("Failed to read config: %v", err)
58118
}
59119
}

cmd/tcp.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

cmd/tls.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
Short: "Print the version of Tunnel",
1313
// Long: ``,
1414
Run: func(cmd *cobra.Command, args []string) {
15-
fmt.Println("0.1.4")
15+
fmt.Println("0.2.4")
1616
},
1717
}
1818
)

0 commit comments

Comments
 (0)