示例#1
0
func (sdir *sqlStorageDirectory) NewRegistration(registration types.Registration) (i.StorageRegistration, error) {
	export, err := registration.Export(sdir.storage.lastPassword())

	_, err = sdir.storage.db.Exec(
		"INSERT INTO registration (directory_id, name, location, jsonPem, keyPem) VALUES ($1, $2, $3, $4, $5)",
		sdir.id, export.Name, export.Location, export.JsonPem, export.SigningKeyPem)

	if nil != err {
		return nil, err
	}

	return sdir.LoadRegistration(registration.Name)
}
示例#2
0
func (storage *sqlStorage) saveRegistration(id int64, directory_id int64, reg types.Registration) error {
	export, err := reg.Export(storage.lastPassword())
	if nil != err {
		return err
	}

	_, err = storage.db.Exec(
		`UPDATE registration SET
			directory_id = $1, name = $2, location = $3,
			jsonPem = $4, keyPem = $5
		WHERE id = $6`,
		directory_id,
		export.Name, export.Location, export.JsonPem, export.SigningKeyPem,
		id)

	return err
}