Beispiel #1
0
// Run runs the git-receive hook. This func is effectively the main for the git-receive hook,
// although it is called from the main in boot.go.
func Run(conf *Config, fs sys.FS, env sys.Env, storageDriver storagedriver.StorageDriver) error {
	log.Debug("Running git hook")

	builderKey, err := builderconf.GetBuilderKey()
	if err != nil {
		return err
	}

	kubeClient, err := client.NewInCluster()
	if err != nil {
		return fmt.Errorf("couldn't reach the api server (%s)", err)
	}

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		oldRev, newRev, refName, err := readLine(line)

		if err != nil {
			return fmt.Errorf("reading STDIN (%s)", err)
		}

		log.Debug("read [%s,%s,%s]", oldRev, newRev, refName)

		// if we're processing a receive-pack on an existing repo, run a build
		if strings.HasPrefix(conf.SSHOriginalCommand, "git-receive-pack") {
			if err := build(conf, storageDriver, kubeClient, fs, env, builderKey, newRev); err != nil {
				return err
			}
		}
	}

	return scanner.Err()
}
Beispiel #2
0
// New creates a new SDK client configured as the builder.
func New(host, port string) (*deis.Client, error) {

	client, err := deis.New(true, fmt.Sprintf("http://%s:%s/", host, port), "")
	if err != nil {
		return client, err
	}
	client.UserAgent = "deis-builder"

	builderKey, err := conf.GetBuilderKey()
	if err != nil {
		return client, err
	}
	client.HooksToken = builderKey

	return client, nil
}
Beispiel #3
0
// UserInfoFromKey makes a request to the controller to get the user info from they given key.
func UserInfoFromKey(key ssh.PublicKey) (*UserInfo, error) {
	fp := fingerprint(key)
	url, err := ControllerURLStr("v2", "hooks", "key", fp)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, err
	}

	builderKey, err := conf.GetBuilderKey()
	if err != nil {
		return nil, err
	}

	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Accept", "application/json")
	req.Header.Add("User-Agent", "deis-builder")
	req.Header.Add("X-Deis-Builder-Auth", builderKey)

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()

	if res.StatusCode != 200 {
		return nil, fmt.Errorf("user has no permissions to push in application")
	}

	ret := &UserInfo{}
	if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
		return nil, err
	}
	ret.Fingerprint = fp
	return ret, nil
}