Example #1
0
func (lc *LaunchConfig) load(s3c *s3.Client, bucket, prefix, key string) error {
	resp, err := s3c.Get(bucket, prefix+"/"+key)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	buf := &bytes.Buffer{}
	_, err = buf.ReadFrom(resp.Body)
	if err != nil {
		return err
	}

	switch resp.StatusCode {
	case 200:
		// ignore
	case 404:
		return ErrorLaunchConfigNotFound
	default:
		return fmt.Errorf("failed to request container config with key %q from s3: [%d] %s", key, resp.StatusCode, buf.String())
	}

	rawHash := md5.Sum(buf.Bytes())
	lc.hash = hex.EncodeToString(rawHash[:])

	return json.Unmarshal(buf.Bytes(), lc)
}
Example #2
0
func (lc *LaunchConfig) save(s3client *s3.Client, bucket, prefix string) error {
	buf := bytes.NewBuffer(nil)
	err := json.NewEncoder(buf).Encode(lc)
	if err != nil {
		return err
	}

	rawHash := md5.Sum(buf.Bytes())
	lc.hash = hex.EncodeToString(rawHash[:])
	key := fmt.Sprintf("%s/container.%s.json", prefix, lc.hash)
	return s3client.Put(bucket, key, buf.Bytes(), nil)
}