Skip to content

Commit

Permalink
Reserved domain names
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Apr 15, 2018
1 parent a99cbfe commit fd40cb2
Show file tree
Hide file tree
Showing 629 changed files with 127,319 additions and 185 deletions.
27 changes: 25 additions & 2 deletions Gopkg.lock
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/go-resty/resty"
version = "1.4.0"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 0.1.4
VERSION = 0.2.4

publish:
git tag $(VERSION)
Expand Down
45 changes: 0 additions & 45 deletions cmd/http.go

This file was deleted.

21 changes: 0 additions & 21 deletions cmd/name.go

This file was deleted.

84 changes: 72 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,80 @@ package cmd

import (
"fmt"
"net/http"
"os"

"github.com/go-resty/resty"
"github.com/labstack/gommon/log"
"github.com/labstack/tunnel"
"github.com/labstack/tunnel/util"

"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
err error
configFile string
name string
tcp bool
tls bool
user string
rootCmd = &cobra.Command{
Use: "tunnel",
Short: "Tunnel lets you expose local servers to the internet securely",
Long: ``,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
t := &tunnel.Tunnel{
Host: "labstack.me:22",
RemoteHost: "0.0.0.0",
RemotePort: 80,
}
e := new(tunnel.Error)

if name != "" {
key := viper.GetString("api_key")
if key == "" {
log.Fatalf("Failed to find api key in the config")
}

// Find tunnel
res, err := resty.R().
SetAuthToken(key).
SetHeader("Content-Type", "application/json").
SetResult(t).
SetError(e).
SetHeader("User-Agent", "labstack/tunnel").
Get(fmt.Sprintf("https://api.labstack.com/tunnels/%s", name))
if err != nil {
log.Fatalf("Failed to the find tunnel: %v", err)
} else if res.StatusCode() != http.StatusOK {
log.Fatalf("Failed to the find tunnel: %s", e.Message)
}
if t.Protocol == "tcp" {
tcp = true
} else if t.Protocol == "tls" {
tls = true
}

user = fmt.Sprintf("key=%s,name=%s", key, name)
t.Host += ":22"
} else if tls {
user = "tls=true"
}

t.User = user
t.TargetHost, t.TargetPort, err = util.SplitHostPort(args[0])
if err != nil {
log.Fatalf("Failed to parse target address: %v", err)
}
if tcp || tls {
t.RemotePort = 0
}
t.Create()
},
}
)

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

// initConfig reads in config file and ENV variables if set.
// initConfig reads in config file and ENV variables if set
func initConfig() {
if configFile != "" {
// Use config file from the flag.
// Use config file from the flag
viper.SetConfigFile(configFile)
} else {
// Find home directory.
// Find home directory
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
log.Fatalf("Failed to find the home directory: %v", err)
}

// Search config in home directory with name ".tunnel" (without extension).
// Search config in home directory with name ".tunnel" (without extension)
viper.AddConfigPath(home)
viper.SetConfigName(".tunnel")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
// fmt.Println("Using config file:", viper.ConfigFileUsed())
viper.AutomaticEnv() // Read in environment variables that match
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("Failed to read config: %v", err)
}
}
44 changes: 0 additions & 44 deletions cmd/tcp.go

This file was deleted.

44 changes: 0 additions & 44 deletions cmd/tls.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (
Short: "Print the version of Tunnel",
// Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("0.1.4")
fmt.Println("0.2.4")
},
}
)
Expand Down
Loading

0 comments on commit fd40cb2

Please sign in to comment.