<commit_before>package command

import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"os/exec"
	"os/user"
	"path/filepath"

	"koding/kites/common"
	"koding/kites/kloud/api/vagrantapi"
	"koding/kites/kloud/keycreator"
	puser "koding/kites/kloud/scripts/provisionklient/userdata"
	"koding/kites/kloud/utils/res"

	"github.com/koding/logging"
	"github.com/mitchellh/cli"
	"github.com/satori/go.uuid"
	"golang.org/x/net/context"
)

const latest = "https://s3.amazonaws.com/koding-klient/development/latest-version.txt"

var (
	defaultHost        = os.Getenv("KLOUDCTL_VAGRANT_HOST")
	defaultUsername    string
	defaultPrivateKey  string
	defaultPublicKey   string
	defaultRegisterURL string // tunnel for 127.0.0.1:56790
	defaultKlientURL   string
)

func init() {
	u, err := user.Current()
	if err != nil {
		log.Println("unable to get current user:", err)
		return
	}

	defaultUsername = u.Username
	defaultRegisterURL = fmt.Sprintf("http://guest-klient-%s.ngrok.com/kite", u.Username)

	p, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
	if err != nil {
		log.Println("unable to get git top dir:", err)
		return
	}

	top := string(bytes.TrimSpace(p))

	p, err = ioutil.ReadFile(filepath.Join(top, "certs", "test_kontrol_rsa_private.pem"))
	if err != nil {
		log.Println("unable to read private key:", err)
		return
	}

	defaultPrivateKey = string(p)

	p, err = ioutil.ReadFile(filepath.Join(top, "certs", "test_kontrol_rsa_public.pem"))
	if err != nil {
		log.Println("unable to read private key:", err)
		return
	}

	defaultPublicKey = string(p)

	resp, err := http.Get(latest)
	if err != nil {
		log.Println("unable to get klient latest version:", err)
		return
	}
	if resp.StatusCode != 200 {
		log.Println("unable to get klient latest version:", resp.StatusCode)
		return
	}
	defer resp.Body.Close()

	p, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Println("unable to get klient latest version:", err)<commit_msg>kloudctl: fix pems paths<commit_after>package command

import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"os/exec"
	"os/user"
	"path/filepath"

	"koding/kites/common"
	"koding/kites/kloud/api/vagrantapi"
	"koding/kites/kloud/keycreator"
	puser "koding/kites/kloud/scripts/provisionklient/userdata"
	"koding/kites/kloud/utils/res"

	"github.com/koding/logging"
	"github.com/mitchellh/cli"
	"github.com/satori/go.uuid"
	"golang.org/x/net/context"
)

const latest = "https://s3.amazonaws.com/koding-klient/development/latest-version.txt"

var (
	defaultHost        = os.Getenv("KLOUDCTL_VAGRANT_HOST")
	defaultUsername    string
	defaultPrivateKey  string
	defaultPublicKey   string
	defaultRegisterURL string // tunnel for 127.0.0.1:56790
	defaultKlientURL   string
)

func init() {
	u, err := user.Current()
	if err != nil {
		log.Println("unable to get current user:", err)
		return
	}

	defaultUsername = u.Username
	defaultRegisterURL = fmt.Sprintf("http://guest-klient-%s.ngrok.com/kite", u.Username)

	p, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
	if err != nil {
		log.Println("unable to get git top dir:", err)
		return
	}

	top := string(bytes.TrimSpace(p))

	p, err = ioutil.ReadFile(filepath.Join(top, "vault", "private_keys", "kontrol", "kontrol.pem"))
	if err != nil {
		log.Println("unable to read private key:", err)
		return
	}

	defaultPrivateKey = string(p)

	p, err = ioutil.ReadFile(filepath.Join(top, "vault", "private_keys", "kontrol", "kontrol.pub"))
	if err != nil {
		log.Println("unable to read private key:", err)
		return
	}

	defaultPublicKey = string(p)

	resp, err := http.Get(latest)
	if err != nil {
		log.Println("unable to get klient latest version:", err)
		return
	}
	if resp.StatusCode != 200 {
		log.Println("unable to get klient latest version:", resp.StatusCode)
		return
	}
	defer resp.Body.Close()

	p, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Println("unable to get klient latest version:", err)
{'fraction_non_alphanumeric': 0.15204534253326762, 'fraction_numerical': 0.008378511582060127, 'mean_word_length': 4.061097256857855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5826673', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1577, 'n_words': 320}