Skip to content

Commit 390adf4

Browse files
committed
Changed api endpoint
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 73aed44 commit 390adf4

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

cmd/root.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var (
2828
Long: ``,
2929
Args: cobra.MinimumNArgs(1),
3030
Run: func(cmd *cobra.Command, args []string) {
31-
t := &tunnel.Tunnel{
31+
c := &tunnel.Config{
3232
Host: "labstack.me:22",
3333
RemoteHost: "0.0.0.0",
3434
RemotePort: 80,
@@ -41,40 +41,40 @@ var (
4141
log.Fatalf("Failed to find api key in the config")
4242
}
4343

44-
// Find tunnel
44+
// Find config
4545
res, err := resty.R().
4646
SetAuthToken(key).
4747
SetHeader("Content-Type", "application/json").
48-
SetResult(t).
48+
SetResult(c).
4949
SetError(e).
5050
SetHeader("User-Agent", "labstack/tunnel").
51-
Get(fmt.Sprintf("https://api.labstack.com/tunnels/%s", name))
51+
Get(fmt.Sprintf("https://api.labstack.com/tunnel/configs/%s", name))
5252
if err != nil {
5353
log.Fatalf("Failed to the find tunnel: %v", err)
5454
} else if res.StatusCode() != http.StatusOK {
5555
log.Fatalf("Failed to the find tunnel: %s", e.Message)
5656
}
57-
if t.Protocol == "tcp" {
57+
if c.Protocol == "tcp" {
5858
tcp = true
59-
} else if t.Protocol == "tls" {
59+
} else if c.Protocol == "tls" {
6060
tls = true
6161
}
6262

6363
user = fmt.Sprintf("key=%s,name=%s", key, name)
64-
t.Host += ":22"
64+
c.Host += ":22"
6565
} else if tls {
6666
user = "tls=true"
6767
}
6868

69-
t.User = user
70-
t.TargetHost, t.TargetPort, err = util.SplitHostPort(args[0])
69+
c.User = user
70+
c.TargetHost, c.TargetPort, err = util.SplitHostPort(args[0])
7171
if err != nil {
7272
log.Fatalf("Failed to parse target address: %v", err)
7373
}
7474
if tcp || tls {
75-
t.RemotePort = 0
75+
c.RemotePort = 0
7676
}
77-
t.Create()
77+
tunnel.Create(c)
7878
},
7979
}
8080
)
@@ -91,7 +91,7 @@ func Execute() {
9191
func init() {
9292
cobra.OnInitialize(initConfig)
9393
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")
94+
rootCmd.PersistentFlags().StringVarP(&name, "name", "n", "", "config name from the dashboard")
9595
rootCmd.PersistentFlags().BoolVarP(&tcp, "tcp", "", false, "tcp tunnel")
9696
rootCmd.PersistentFlags().BoolVarP(&tls, "tls", "", false, "tls tunnel")
9797
}

tunnel.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
type (
18-
Tunnel struct {
18+
Config struct {
1919
Protocol string `json:"protocol"`
2020
Subdomain string `json:"subdomain"`
2121
Domain string `json:"domain"`
@@ -39,19 +39,19 @@ var (
3939
hostBytes = []byte("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDoSLknvlFrFzroOlh1cqvcIFelHO+Wvj1UZ/p3J9bgsJGiKfh3DmBqEw1DOEwpHJz4zuV375TyjGuHuGZ4I4xztnwauhFplfEvriVHQkIDs6UnGwJVr15XUQX04r0i6mLbJs5KqIZTZuZ9ZGOj7ZWnaA7C07nPHGrERKV2Fm67rPvT6/qFikdWUbCt7KshbzdwwfxUohmv+NI7vw2X6vPU8pDaNEY7vS3YgwD/WlvQx+WDF2+iwLVW8OWWjFuQso6Eg1BSLygfPNhAHoiOWjDkijc8U9LYkUn7qsDCnvJxCoTTNmdECukeHfzrUjTSw72KZoM5KCRV78Wrctai1Qn6yRQz9BOSguxewLfzHtnT43/MLdwFXirJ/Ajquve2NAtYmyGCq5HcvpDAyi7lQ0nFBnrWv5zU3YxrISIpjovVyJjfPx8SCRlYZwVeUq6N2yAxCzJxbElZPtaTSoXBIFtoas2NXnCWPgenBa/2bbLQqfgbN8VQ9RaUISKNuYDIn4+eO72+RxF9THzZeV17pnhTVK88XU4asHot1gXwAt4vEhSjdUBC9KUIkfukI6F4JFxtvuO96octRahdV1Qg0vF+D0+SPy2HxqjgZWgPE2Xh/NmuIXwbE0wkymR2wrgj8Hd4C92keo2NBRh9dD7D2negnVYaYsC+3k/si5HNuCHnHQ== tunnel@labstack.com")
4040
)
4141

42-
func (t *Tunnel) Create() {
42+
func Create(c *Config) {
4343
hostKey, _, _, _, err := ssh.ParseAuthorizedKey(hostBytes)
4444
if err != nil {
4545
log.Fatalf("Failed to parse host key: %v", err)
4646
}
4747
config := &ssh.ClientConfig{
48-
User: t.User,
48+
User: c.User,
4949
Auth: []ssh.AuthMethod{
5050
ssh.Password("password"),
5151
},
5252
HostKeyCallback: ssh.FixedHostKey(hostKey),
5353
BannerCallback: func(message string) error {
54-
if !t.HideBanner {
54+
if !c.HideBanner {
5555
fmt.Print(message)
5656
}
5757
return nil
@@ -72,8 +72,8 @@ func (t *Tunnel) Create() {
7272
}
7373
connReq := &http.Request{
7474
Method: "CONNECT",
75-
URL: &url.URL{Path: t.Host},
76-
Host: t.Host,
75+
URL: &url.URL{Path: c.Host},
76+
Host: c.Host,
7777
Header: make(http.Header),
7878
}
7979
if proxyURL.User != nil {
@@ -88,13 +88,13 @@ func (t *Tunnel) Create() {
8888
}
8989
defer resp.Body.Close()
9090

91-
c, chans, reqs, err := ssh.NewClientConn(tcp, t.Host, config)
91+
conn, chans, reqs, err := ssh.NewClientConn(tcp, c.Host, config)
9292
if err != nil {
9393
log.Fatalf("Cannot open new session: %v", err)
9494
}
95-
client = ssh.NewClient(c, chans, reqs)
95+
client = ssh.NewClient(conn, chans, reqs)
9696
} else {
97-
client, err = ssh.Dial("tcp", t.Host, config)
97+
client, err = ssh.Dial("tcp", c.Host, config)
9898
}
9999
if err != nil {
100100
log.Fatalf("Failed to connect: %v", err)
@@ -120,7 +120,7 @@ func (t *Tunnel) Create() {
120120
}()
121121

122122
// Remote listener
123-
ln, err := client.Listen("tcp", fmt.Sprintf("%s:%d", t.RemoteHost, t.RemotePort))
123+
ln, err := client.Listen("tcp", fmt.Sprintf("%s:%d", c.RemoteHost, c.RemotePort))
124124
if err != nil {
125125
log.Fatalf("Failed to listen on remote host %v", err)
126126
}
@@ -138,7 +138,7 @@ func (t *Tunnel) Create() {
138138
defer in.Close()
139139

140140
// Target connection
141-
out, err := net.Dial("tcp", fmt.Sprintf("%s:%d", t.TargetHost, t.TargetPort))
141+
out, err := net.Dial("tcp", fmt.Sprintf("%s:%d", c.TargetHost, c.TargetPort))
142142
if err != nil {
143143
log.Printf("Failed to connect to target %v", err)
144144
return

0 commit comments

Comments
 (0)