ICU-743/Domain errors internal/kms refactor (#848)
* Domain errors internal/kms refactor * Update changelog * Update internal/host error op * Incorrect error returned in read_writer
This commit is contained in:
1 parent
9de928318d
commit
8151b30ce9
68 files changed
+802
-725
No files matched your search
@@ -22,7 +22,7 @@ import (
|
||||
// Both h.Name and h.Description are optional. If h.Name is set, it must be
|
||||
// unique within h.CatalogId.
|
||||
func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, opt ...Option) (*Host, error) {
|
||||
const op = "static.CreateHost"
|
||||
const op = "static.(Repository).CreateHost"
|
||||
if h == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "nil Host")
|
||||
}
|
||||
@@ -72,7 +72,11 @@ func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, op
|
||||
_, err = r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
||||
func(_ db.Reader, w db.Writer) error {
|
||||
newHost = h.clone()
|
||||
return w.Create(ctx, newHost, db.WithOplog(oplogWrapper, h.oplog(oplog.OpType_OP_TYPE_CREATE)))
|
||||
err := w.Create(ctx, newHost, db.WithOplog(oplogWrapper, h.oplog(oplog.OpType_OP_TYPE_CREATE)))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
@@ -106,7 +110,7 @@ func (r *Repository) CreateHost(ctx context.Context, scopeId string, h *Host, op
|
||||
// An attribute of h will be set to NULL in the database if the attribute
|
||||
// in h is the zero value and it is included in fieldMaskPaths.
|
||||
func (r *Repository) UpdateHost(ctx context.Context, scopeId string, h *Host, version uint32, fieldMaskPaths []string, opt ...Option) (*Host, int, error) {
|
||||
const op = "static.UpdateHost"
|
||||
const op = "static.(Repository).UpdateHost"
|
||||
if h == nil {
|
||||
return nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "nil Host")
|
||||
}
|
||||
@@ -168,7 +172,7 @@ func (r *Repository) UpdateHost(ctx context.Context, scopeId string, h *Host, ve
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
if rowsUpdated > 1 {
|
||||
return errors.E(errors.WithCode(errors.MultipleRecords))
|
||||
return errors.New(errors.MultipleRecords, op, "more than 1 resource would have been updated")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@@ -195,7 +199,7 @@ func (r *Repository) UpdateHost(ctx context.Context, scopeId string, h *Host, ve
|
||||
// LookupHost will look up a host in the repository. If the host is not
|
||||
// found, it will return nil, nil. All options are ignored.
|
||||
func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Option) (*Host, error) {
|
||||
const op = "static.LookupHost"
|
||||
const op = "static.(Repository).LookupHost"
|
||||
if publicId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "no public id")
|
||||
}
|
||||
@@ -213,7 +217,7 @@ func (r *Repository) LookupHost(ctx context.Context, publicId string, opt ...Opt
|
||||
// ListHosts returns a slice of Hosts for the catalogId.
|
||||
// WithLimit is the only option supported.
|
||||
func (r *Repository) ListHosts(ctx context.Context, catalogId string, opt ...Option) ([]*Host, error) {
|
||||
const op = "static.ListHosts"
|
||||
const op = "static.(Repository).ListHosts"
|
||||
if catalogId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "no catalog id")
|
||||
}
|
||||
@@ -235,7 +239,7 @@ func (r *Repository) ListHosts(ctx context.Context, catalogId string, opt ...Opt
|
||||
// returning a count of the number of records deleted. All options are
|
||||
// ignored.
|
||||
func (r *Repository) DeleteHost(ctx context.Context, scopeId string, publicId string, opt ...Option) (int, error) {
|
||||
const op = "static.DeleteHost"
|
||||
const op = "static.(Repository).DeleteHost"
|
||||
if publicId == "" {
|
||||
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "no public id")
|
||||
}
|
||||
@@ -257,7 +261,7 @@ func (r *Repository) DeleteHost(ctx context.Context, scopeId string, publicId st
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
if rowsDeleted > 1 {
|
||||
return errors.E(errors.WithCode(errors.MultipleRecords))
|
||||
return errors.New(errors.MultipleRecords, op, "more than 1 resource would have been deleted")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
//
|
||||
// Both c.CreateTime and c.UpdateTime are ignored.
|
||||
func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...Option) (*HostCatalog, error) {
|
||||
const op = "static.CreateCatalog"
|
||||
const op = "static.(Repository).CreateCatalog"
|
||||
if c == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "nil HostCatalog")
|
||||
}
|
||||
@@ -69,11 +69,15 @@ func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...O
|
||||
db.ExpBackoff{},
|
||||
func(_ db.Reader, w db.Writer) error {
|
||||
newHostCatalog = c.clone()
|
||||
return w.Create(
|
||||
err := w.Create(
|
||||
ctx,
|
||||
newHostCatalog,
|
||||
db.WithOplog(oplogWrapper, metadata),
|
||||
)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
@@ -98,7 +102,7 @@ func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...O
|
||||
// An attribute of c will be set to NULL in the database if the attribute
|
||||
// in c is the zero value and it is included in fieldMask.
|
||||
func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version uint32, fieldMask []string, opt ...Option) (*HostCatalog, int, error) {
|
||||
const op = "static.UpdateCatalog"
|
||||
const op = "static.(Repository).UpdateCatalog"
|
||||
if c == nil {
|
||||
return nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "nil HostCatalog")
|
||||
}
|
||||
@@ -162,7 +166,7 @@ func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
if rowsUpdated > 1 {
|
||||
return errors.E(errors.WithCode(errors.MultipleRecords))
|
||||
return errors.New(errors.MultipleRecords, op, "more than 1 resource would have been updated")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@@ -181,7 +185,7 @@ func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, version
|
||||
// LookupCatalog returns the HostCatalog for id. Returns nil, nil if no
|
||||
// HostCatalog is found for id.
|
||||
func (r *Repository) LookupCatalog(ctx context.Context, id string, opt ...Option) (*HostCatalog, error) {
|
||||
const op = "static.LookupCatalog"
|
||||
const op = "static.(Repository).LookupCatalog"
|
||||
if id == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "no public id")
|
||||
}
|
||||
@@ -198,7 +202,7 @@ func (r *Repository) LookupCatalog(ctx context.Context, id string, opt ...Option
|
||||
|
||||
// ListCatalogs returns a slice of HostCatalogs for the scopeId. WithLimit is the only option supported.
|
||||
func (r *Repository) ListCatalogs(ctx context.Context, scopeId string, opt ...Option) ([]*HostCatalog, error) {
|
||||
const op = "static.ListCatalogs"
|
||||
const op = "static.(Repository).ListCatalogs"
|
||||
if scopeId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "no scope id")
|
||||
}
|
||||
@@ -219,7 +223,7 @@ func (r *Repository) ListCatalogs(ctx context.Context, scopeId string, opt ...Op
|
||||
// DeleteCatalog deletes id from the repository returning a count of the
|
||||
// number of records deleted.
|
||||
func (r *Repository) DeleteCatalog(ctx context.Context, id string, opt ...Option) (int, error) {
|
||||
const op = "static.DeleteCatalog"
|
||||
const op = "static.(Repository).DeleteCatalog"
|
||||
if id == "" {
|
||||
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "no public id")
|
||||
}
|
||||
@@ -260,7 +264,7 @@ func (r *Repository) DeleteCatalog(ctx context.Context, id string, opt ...Option
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
if rowsDeleted > 1 {
|
||||
return errors.E(errors.WithCode(errors.MultipleRecords))
|
||||
return errors.New(errors.MultipleRecords, op, "more than 1 resource would have been deleted")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
// Both s.Name and s.Description are optional. If s.Name is set, it must be
|
||||
// unique within s.CatalogId.
|
||||
func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet, opt ...Option) (*HostSet, error) {
|
||||
const op = "static.CreateSet"
|
||||
const op = "static.(Repository).CreateSet"
|
||||
if s == nil {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "nil HostSet")
|
||||
}
|
||||
@@ -66,7 +66,11 @@ func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet,
|
||||
_, err = r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
||||
func(_ db.Reader, w db.Writer) error {
|
||||
newHostSet = s.clone()
|
||||
return w.Create(ctx, newHostSet, db.WithOplog(oplogWrapper, s.oplog(oplog.OpType_OP_TYPE_CREATE)))
|
||||
err := w.Create(ctx, newHostSet, db.WithOplog(oplogWrapper, s.oplog(oplog.OpType_OP_TYPE_CREATE)))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
@@ -94,7 +98,7 @@ func (r *Repository) CreateSet(ctx context.Context, scopeId string, s *HostSet,
|
||||
// The WithLimit option can be used to limit the number of hosts returned.
|
||||
// All other options are ignored.
|
||||
func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet, version uint32, fieldMaskPaths []string, opt ...Option) (*HostSet, []*Host, int, error) {
|
||||
const op = "static.UpdateSet"
|
||||
const op = "static.(Repository).UpdateSet"
|
||||
if s == nil {
|
||||
return nil, nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "nil HostSet")
|
||||
}
|
||||
@@ -158,7 +162,7 @@ func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet,
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
if rowsUpdated > 1 {
|
||||
return errors.E(errors.WithCode(errors.MultipleRecords))
|
||||
return errors.New(errors.MultipleRecords, op, "more than 1 resource would have been updated")
|
||||
}
|
||||
hosts, err = getHosts(ctx, reader, s.PublicId, limit)
|
||||
if err != nil {
|
||||
@@ -183,7 +187,7 @@ func (r *Repository) UpdateSet(ctx context.Context, scopeId string, s *HostSet,
|
||||
// found, it will return nil, nil, nil. The WithLimit option can be used to
|
||||
// limit the number of hosts returned. All other options are ignored.
|
||||
func (r *Repository) LookupSet(ctx context.Context, publicId string, opt ...Option) (*HostSet, []*Host, error) {
|
||||
const op = "static.LookupSet"
|
||||
const op = "static.(Repository).LookupSet"
|
||||
if publicId == "" {
|
||||
return nil, nil, errors.New(errors.InvalidParameter, op, "no public id")
|
||||
}
|
||||
@@ -226,7 +230,7 @@ func (r *Repository) LookupSet(ctx context.Context, publicId string, opt ...Opti
|
||||
// ListSets returns a slice of HostSets for the catalogId. WithLimit is the
|
||||
// only option supported.
|
||||
func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...Option) ([]*HostSet, error) {
|
||||
const op = "static.ListSets"
|
||||
const op = "static.(Repository).ListSets"
|
||||
if catalogId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "no catalog id")
|
||||
}
|
||||
@@ -248,7 +252,7 @@ func (r *Repository) ListSets(ctx context.Context, catalogId string, opt ...Opti
|
||||
// returning a count of the number of records deleted. All options are
|
||||
// ignored.
|
||||
func (r *Repository) DeleteSet(ctx context.Context, scopeId string, publicId string, opt ...Option) (int, error) {
|
||||
const op = "static.DeleteSet"
|
||||
const op = "static.(Repository).DeleteSet"
|
||||
if publicId == "" {
|
||||
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "no public id")
|
||||
}
|
||||
@@ -273,7 +277,7 @@ func (r *Repository) DeleteSet(ctx context.Context, scopeId string, publicId str
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
if rowsDeleted > 1 {
|
||||
return errors.E(errors.WithCode(errors.MultipleRecords))
|
||||
return errors.New(errors.MultipleRecords, op, "more than 1 resource would have been deleted")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
// the set to be added. The version must match the current version of the
|
||||
// setId in the repository.
|
||||
func (r *Repository) AddSetMembers(ctx context.Context, scopeId string, setId string, version uint32, hostIds []string, opt ...Option) ([]*Host, error) {
|
||||
const op = "static.AddSetMembers"
|
||||
const op = "static.(Repository).AddSetMembers"
|
||||
if scopeId == "" {
|
||||
return nil, errors.New(errors.InvalidParameter, op, "no scope id")
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func updateVersion(ctx context.Context, w db.Writer, wrapper wrapping.Wrapper, m
|
||||
case err != nil:
|
||||
return errors.Wrap(err, op)
|
||||
case rowsUpdated > 1:
|
||||
return errors.E(errors.WithCode(errors.MultipleRecords))
|
||||
return errors.New(errors.MultipleRecords, op, "more than 1 resource would have been updated")
|
||||
}
|
||||
msgs = append(msgs, setMsg)
|
||||
|
||||
@@ -159,7 +159,7 @@ func getHosts(ctx context.Context, reader db.Reader, setId string, limit int) ([
|
||||
// returns the number of hosts deleted from the set. The version must match
|
||||
// the current version of the setId in the repository.
|
||||
func (r *Repository) DeleteSetMembers(ctx context.Context, scopeId string, setId string, version uint32, hostIds []string, opt ...Option) (int, error) {
|
||||
const op = "static.DeleteSetMembers"
|
||||
const op = "static.(Repository).DeleteSetMembers"
|
||||
if scopeId == "" {
|
||||
return db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "no scope id")
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func deleteMembers(ctx context.Context, w db.Writer, members []interface{}) ([]*
|
||||
// set to be added. The version must match the current version of the setId
|
||||
// in the repository. If hostIds is empty, all hosts will be removed setId.
|
||||
func (r *Repository) SetSetMembers(ctx context.Context, scopeId string, setId string, version uint32, hostIds []string, opt ...Option) ([]*Host, int, error) {
|
||||
const op = "static.SetSetMembers"
|
||||
const op = "static.(Repository).SetSetMembers"
|
||||
if scopeId == "" {
|
||||
return nil, db.NoRowsAffected, errors.New(errors.InvalidParameter, op, "no scope id")
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func (r *Repository) SetSetMembers(ctx context.Context, scopeId string, setId st
|
||||
if len(additions) > 0 {
|
||||
createdMsgs, err := createMembers(ctx, w, additions)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, op)
|
||||
}
|
||||
msgs = append(msgs, createdMsgs...)
|
||||
metadata["op-type"] = append(metadata["op-type"], oplog.OpType_OP_TYPE_CREATE.String())
|
||||
@@ -326,7 +326,7 @@ type change struct {
|
||||
}
|
||||
|
||||
func (r *Repository) changes(ctx context.Context, setId string, hostIds []string) ([]*change, error) {
|
||||
const op = "static.changes"
|
||||
const op = "static.(Repository).changes"
|
||||
var inClauseSpots []string
|
||||
// starts at 2 because there is already a $1 in the query
|
||||
for i := 2; i < len(hostIds)+2; i++ {
|
||||
|
||||
Reference in new issue
Block a user