cloudcfg working locally now

This commit is contained in:
Daniel Smith
2014-06-11 18:13:25 -07:00
parent 912ec01856
commit 187f7d2534
4 changed files with 36 additions and 14 deletions

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"strconv"
"time"
@@ -39,7 +40,7 @@ var (
updatePeriod = flag.Duration("u", 60*time.Second, "Update interarrival period")
portSpec = flag.String("p", "", "The port spec, comma-separated list of <external>:<internal>,...")
servicePort = flag.Int("s", -1, "If positive, create and run a corresponding service on this port, only used with 'run'")
authConfig = flag.String("auth", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file. If missing, prompt the user")
authConfig = flag.String("auth", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file. If missing, prompt the user. Only used if doing https.")
json = flag.Bool("json", false, "If true, print raw JSON for responses")
yaml = flag.Bool("yaml", false, "If true, print raw YAML for responses")
)
@@ -61,9 +62,16 @@ func main() {
usage()
}
method := flag.Arg(0)
secure := true
parsedUrl, err := url.Parse(*httpServer)
if err != nil {
log.Fatalf("Unable to parse %v as a URL\n", err)
}
if parsedUrl.Scheme != "" && parsedUrl.Scheme != "https" {
secure = false
}
url := *httpServer + "/api/v1beta1" + flag.Arg(1)
var request *http.Request
var err error
var printer cloudcfg.ResourcePrinter
if *json {
@@ -74,9 +82,12 @@ func main() {
printer = &cloudcfg.HumanReadablePrinter{}
}
auth, err := cloudcfg.LoadAuthInfo(*authConfig)
if err != nil {
log.Fatalf("Error loading auth: %#v", err)
var auth kube_client.AuthInfo
if secure {
auth, err = cloudcfg.LoadAuthInfo(*authConfig)
if err != nil {
log.Fatalf("Error loading auth: %#v", err)
}
}
switch method {
@@ -132,7 +143,11 @@ func main() {
log.Fatalf("Error: %#v", err)
}
var body string
body, err = cloudcfg.DoRequest(request, auth.User, auth.Password)
if secure {
body, err = cloudcfg.DoSecureRequest(request, auth.User, auth.Password)
} else {
body, err = cloudcfg.DoInsecureRequest(request)
}
if err != nil {
log.Fatalf("Error: %#v", err)
}