Skip to content

Commit

Permalink
Fix ssl (#650)
Browse files Browse the repository at this point in the history
* enable ssl, add optional skip ssl verification

* dry up api_url parsing

* further dry up code

* go fmt

* Updated dependencies

github.com/iron-io/functions_go
  • Loading branch information
c0ze committed Sep 28, 2017
1 parent 6b69464 commit 4d2c9dc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

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

23 changes: 7 additions & 16 deletions fn/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,20 @@ package main
import (
"os"

"crypto/tls"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
fnclient "github.com/iron-io/functions_go/client"
"log"
"net/url"
"net/http"
)

func host() string {
apiURL := os.Getenv("API_URL")
if apiURL == "" {
apiURL = "http://localhost:8080"
}

u, err := url.Parse(apiURL)
if err != nil {
log.Fatalln("Couldn't parse API URL:", err)
func apiClient() *fnclient.Functions {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: SSL_SKIP_VERIFY},
}
cl := &http.Client{Transport: tr}

return u.Host
}

func apiClient() *fnclient.Functions {
transport := httptransport.New(host(), "/v1", []string{"http"})
transport := httptransport.NewWithClient(HOST, API_VERSION, []string{SCHEME}, cl)
if os.Getenv("IRON_TOKEN") != "" {
transport.DefaultAuthentication = httptransport.BearerToken(os.Getenv("IRON_TOKEN"))
}
Expand Down
57 changes: 36 additions & 21 deletions fn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
vers "github.com/iron-io/functions/api/version"
functions "github.com/iron-io/functions_go"
"github.com/urfave/cli"
"log"
)

var aliases = map[string]cli.Command{
Expand All @@ -21,6 +22,41 @@ var aliases = map[string]cli.Command{
"call": call(),
}

var API_VERSION = "/v1"
var SSL_SKIP_VERIFY = (os.Getenv("SSL_SKIP_VERIFY") == "true")
var API_URL = "http://localhost:8080"
var SCHEME = "http"
var HOST string
var BASE_PATH string

func getBasePath(version string) string {
u, err := url.Parse(API_URL)
if err != nil {
log.Fatalln("Couldn't parse API URL:", err)
}
HOST = u.Host
SCHEME = u.Scheme
u.Path = version
return u.String()
}

func init() {
if os.Getenv("API_URL") != "" {
API_URL = os.Getenv("API_URL")
}
BASE_PATH = getBasePath(API_VERSION)
}

func main() {
app := newFn()
app.Run(os.Args)
}

func resetBasePath(c *functions.Configuration) error {
c.BasePath = BASE_PATH
return nil
}

func aliasesFn() []cli.Command {
cmds := []cli.Command{}
for alias, cmd := range aliases {
Expand Down Expand Up @@ -120,24 +156,3 @@ func prepareCmdArgsValidation(cmds []cli.Command) {
cmds[i] = cmd
}
}

func main() {
app := newFn()
app.Run(os.Args)
}

func resetBasePath(c *functions.Configuration) error {
apiURL := os.Getenv("API_URL")
if apiURL == "" {
apiURL = "http://localhost:8080"
}

u, err := url.Parse(apiURL)
if err != nil {
return err
}
u.Path = "/v1"
c.BasePath = u.String()

return nil
}
4 changes: 2 additions & 2 deletions fn/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (a *routesCmd) call(c *cli.Context) error {
route := cleanRoutePath(c.Args().Get(1))

u := url.URL{
Scheme: "http",
Host: host(),
Scheme: SCHEME,
Host: HOST,
}
u.Path = path.Join(u.Path, "r", appName, route)
content := stdin()
Expand Down
14 changes: 1 addition & 13 deletions fn/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package main

import (
"fmt"
"net/url"
"os"

vers "github.com/iron-io/functions/api/version"
functions "github.com/iron-io/functions_go"
"github.com/urfave/cli"
Expand All @@ -24,16 +21,7 @@ type versionCmd struct {
}

func (r *versionCmd) version(c *cli.Context) error {
apiURL := os.Getenv("API_URL")
if apiURL == "" {
apiURL = "http://localhost:8080"
}

u, err := url.Parse(apiURL)
if err != nil {
return err
}
r.Configuration.BasePath = u.String()
r.Configuration.BasePath = getBasePath("")

fmt.Println("Client version:", vers.Version)
v, _, err := r.VersionGet()
Expand Down

0 comments on commit 4d2c9dc

Please sign in to comment.