Ejemplo n.º 1
0
func (s *Stacker) BuildMachine(ctx context.Context, bm *BaseMachine) (Machine, error) {
	if err := modelhelper.BsonDecode(bm.Meta, object.ToAddr(bm.Metadata)); err != nil {
		return nil, err
	}

	if v, ok := bm.Metadata.(stack.Validator); ok {
		if err := v.Valid(); err != nil {
			return nil, err
		}
	}

	if err := s.FetchCredData(bm); err != nil {
		return nil, err
	}

	s.Log.Debug("credential: %# v, bootstrap: %# v", bm.Credential, bm.Bootstrap)

	m, err := s.Provider.Machine(bm)
	if err != nil {
		return nil, err
	}

	bm.machine = m

	return m, nil
}
Ejemplo n.º 2
0
func (s *Stacker) FetchCredData(bm *BaseMachine) error {
	credentials := make(map[string]interface{})

	if bm.Bootstrap != nil {
		credentials[bm.Machine.Credential] = object.Inline(bm.Credential, bm.Bootstrap)
	} else {
		credentials[bm.Machine.Credential] = object.ToAddr(bm.Credential)
	}

	return s.CredStore.Fetch(bm.Username(), credentials)
}