Ejemplo n.º 1
0
// LoadFromFile reads an IAM Config from a file (JSON format) on the local filesystem.
func LoadFromFile(filename string) (config Config, err error) {
	var f *os.File
	if f, err = os.Open(filename); err != nil {
		err = fmt.Errorf("failed to load IAM config from file %q: %+v", filename, err)
		return
	}

	defer errorutil.Ignore(f.Close)
	dec := json.NewDecoder(f)
	if err = dec.Decode(&config); err != nil {
		err = fmt.Errorf("invalid IAM JSON: %+v", err)
		return
	}
	if _, err = url.Parse(config.LoginEndpoint); err != nil {
		err = fmt.Errorf("invalid LoginEndpoint URL: %+v", err)
	}
	return
}
Ejemplo n.º 2
0
// Loads state.json from mesos master
func (rg *RecordGenerator) loadFromMaster(ip string, port string) (state.State, error) {
	// REFACTOR: state.json security

	var sj state.State
	u := url.URL{
		Scheme: "http",
		Host:   net.JoinHostPort(ip, port),
		Path:   "/master/state.json",
	}

	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		logging.Error.Println(err)
		return state.State{}, err
	}

	req.Header.Set("Content-Type", "application/json")

	resp, err := rg.httpClient.Do(req)
	if err != nil {
		logging.Error.Println(err)
		return state.State{}, err
	}

	defer errorutil.Ignore(resp.Body.Close)
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		logging.Error.Println(err)
		return state.State{}, err
	}

	err = json.Unmarshal(body, &sj)
	if err != nil {
		logging.Error.Println(err)
		return state.State{}, err
	}

	return sj, nil
}
Ejemplo n.º 3
0
func readCACertFile(caCertFile string) (caPool *x509.CertPool, err error) {
	var f *os.File
	if f, err = os.Open(caCertFile); err != nil {
		err = fmt.Errorf("CACertFile open failed: %v", err)
		return
	}
	defer errorutil.Ignore(f.Close)

	var b []byte
	if b, err = ioutil.ReadAll(f); err != nil {
		err = fmt.Errorf("CACertFile read failed: %v", err)
		return
	}

	pool := x509.NewCertPool()
	if !pool.AppendCertsFromPEM(b) {
		err = fmt.Errorf("CACertFile parsing failed: %v", err)
	} else {
		caPool = pool
	}
	return
}