Example #1
0
//fetch the request json from riak and parse the json to struct
func (p *Payload) Convert() (*Requests, error) {
	log.Infof("get requests %s", p.Id)
	if p.CatId != "" {
		r := &Requests{
			Id:        p.Id,
			CatId:     p.CatId,
			Action:    p.Action,
			Category:  p.Category,
			CreatedAt: p.CreatedAt,
		}

		log.Debugf("Requests %v", r)
		return r, nil
	} else {
		r := &Requests{}

		ops := ldb.Options{
			TableName:   "requests",
			Pks:         []string{"Id"},
			Ccms:        []string{},
			Hosts:       meta.MC.Scylla,
			Keyspace:    meta.MC.ScyllaKeyspace,
			PksClauses:  map[string]interface{}{"Id": p.Id},
			CcmsClauses: make(map[string]interface{}),
		}
		if err := ldb.Fetchdb(ops, r); err != nil {
			return nil, err
		}

		log.Debugf("Requests %v", r)
		return r, nil
	}
}
Example #2
0
// append user sshkey into authorized_keys file
func (m *Machine) AppendAuthKeys() error {
	c := &SshKeys{}
	ops := ldb.Options{
		TableName:   SSHKEYSBUCKET,
		Pks:         []string{"Name"},
		Ccms:        []string{},
		Hosts:       meta.MC.Scylla,
		Keyspace:    meta.MC.ScyllaKeyspace,
		PksClauses:  map[string]interface{}{"Name": m.SSH.Pub()},
		CcmsClauses: make(map[string]interface{}),
	}
	if err := ldb.Fetchdb(ops, c); err != nil {
		return err
	}

	f, err := os.OpenFile(m.SSH.AuthKeysFile(), os.O_APPEND|os.O_WRONLY, 0600)
	if err != nil {
		return err
	}

	defer f.Close()

	if _, err = f.WriteString(c.Publickey); err != nil {
		return err
	}
	return nil
}
Example #3
0
func getBig(id string) (*Ambly, error) {
	a := &Ambly{}
	ops := ldb.Options{
		TableName:   ASSEMBLYBUCKET,
		Pks:         []string{"Id"},
		Ccms:        []string{},
		Hosts:       meta.MC.Scylla,
		Keyspace:    meta.MC.ScyllaKeyspace,
		PksClauses:  map[string]interface{}{"Id": id},
		CcmsClauses: make(map[string]interface{}),
	}
	if err := ldb.Fetchdb(ops, a); err != nil {
		return nil, err
	}
	return a, nil
}
Example #4
0
/**
**fetch the component json from riak and parse the json to struct
**/
func NewComponent(id string) (*Component, error) {
	c := &ComponentTable{Id: id}
	ops := ldb.Options{
		TableName:   COMPBUCKET,
		Pks:         []string{"Id"},
		Ccms:        []string{},
		Hosts:       meta.MC.Scylla,
		Keyspace:    meta.MC.ScyllaKeyspace,
		PksClauses:  map[string]interface{}{"Id": id},
		CcmsClauses: make(map[string]interface{}),
	}
	if err := ldb.Fetchdb(ops, c); err != nil {
		return nil, err
	}
	com, _ := c.dig()
	return &com, nil
}
Example #5
0
//get the assembly and its children (component). we only store the
//componentid, hence you see that we have a components map to cater to that need.
func get(id string) (*Assembly, error) {
	a := &Ambly{}
	ops := ldb.Options{
		TableName:   ASSEMBLYBUCKET,
		Pks:         []string{"Id"},
		Ccms:        []string{},
		Hosts:       meta.MC.Scylla,
		Keyspace:    meta.MC.ScyllaKeyspace,
		Username:    meta.MC.ScyllaUsername,
		Password:    meta.MC.ScyllaPassword,
		PksClauses:  map[string]interface{}{"Id": id},
		CcmsClauses: make(map[string]interface{}),
	}
	if err := ldb.Fetchdb(ops, a); err != nil {
		return nil, err
	}
	asm, _ := a.dig()
	return &asm, nil
}