Skip to content

Commit 6045040

Browse files
committed
Updated error messages to be cleaner
1 parent d1e0cbb commit 6045040

4 files changed

Lines changed: 58 additions & 58 deletions

File tree

core/capabilities/vault/capability_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ func TestCapability_CRUD(t *testing.T) {
847847
{
848848
name: "CreateSecrets_Missing_Key",
849849
response: nil,
850-
error: "invalid secret identifier: key cannot be empty",
850+
error: "key cannot be empty",
851851
call: func(t *testing.T, capability *Capability) (*vaulttypes.Response, error) {
852852
req := &vault.CreateSecretsRequest{
853853
RequestId: requestID,
@@ -868,7 +868,7 @@ func TestCapability_CRUD(t *testing.T) {
868868
{
869869
name: "CreateSecrets_Missing_Namespace",
870870
response: nil,
871-
error: "invalid secret identifier: namespace cannot be empty",
871+
error: "namespace cannot be empty",
872872
call: func(t *testing.T, capability *Capability) (*vaulttypes.Response, error) {
873873
req := &vault.CreateSecretsRequest{
874874
RequestId: requestID,
@@ -889,7 +889,7 @@ func TestCapability_CRUD(t *testing.T) {
889889
{
890890
name: "CreateSecrets_Missing_Owner",
891891
response: nil,
892-
error: "invalid secret identifier: owner cannot be empty",
892+
error: "owner cannot be empty",
893893
call: func(t *testing.T, capability *Capability) (*vaulttypes.Response, error) {
894894
req := &vault.CreateSecretsRequest{
895895
RequestId: requestID,
@@ -1037,7 +1037,7 @@ func TestCapability_CRUD(t *testing.T) {
10371037
Payload: []byte("hello world"),
10381038
Format: "protobuf",
10391039
},
1040-
error: "invalid secret identifier: key cannot be empty",
1040+
error: "key cannot be empty",
10411041
call: func(t *testing.T, capability *Capability) (*vaulttypes.Response, error) {
10421042
req := &vault.UpdateSecretsRequest{
10431043
RequestId: requestID,
@@ -1062,7 +1062,7 @@ func TestCapability_CRUD(t *testing.T) {
10621062
Payload: []byte("hello world"),
10631063
Format: "protobuf",
10641064
},
1065-
error: "invalid secret identifier: namespace cannot be empty",
1065+
error: "namespace cannot be empty",
10661066
call: func(t *testing.T, capability *Capability) (*vaulttypes.Response, error) {
10671067
req := &vault.UpdateSecretsRequest{
10681068
RequestId: requestID,
@@ -1087,7 +1087,7 @@ func TestCapability_CRUD(t *testing.T) {
10871087
Payload: []byte("hello world"),
10881088
Format: "protobuf",
10891089
},
1090-
error: "invalid secret identifier: owner cannot be empty",
1090+
error: "owner cannot be empty",
10911091
call: func(t *testing.T, capability *Capability) (*vaulttypes.Response, error) {
10921092
req := &vault.UpdateSecretsRequest{
10931093
RequestId: requestID,

core/capabilities/vault/validator.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,40 +108,40 @@ func (r *RequestValidator) ValidateCiphertextSize(ctx context.Context, owner str
108108

109109
func (r *RequestValidator) ValidateSecretIdentifier(ctx context.Context, idKey string, idOwner string, idNamespace string) error {
110110
if idKey == "" {
111-
return fmt.Errorf("invalid secret identifier: key cannot be empty")
111+
return fmt.Errorf("key cannot be empty")
112112
}
113113
if idOwner == "" {
114-
return fmt.Errorf("invalid secret identifier: owner cannot be empty")
114+
return fmt.Errorf("owner cannot be empty")
115115
}
116116
if idNamespace == "" {
117-
return fmt.Errorf("invalid secret identifier: namespace cannot be empty")
117+
return fmt.Errorf("namespace cannot be empty")
118118
}
119119

120120
if !isValidIDComponent(idKey) || !isValidIDComponent(idOwner) || !isValidIDComponent(idNamespace) {
121-
return fmt.Errorf("invalid secret identifier: key, owner and namespace must only contain alphanumeric characters")
121+
return fmt.Errorf("key, owner and namespace must only contain alphanumeric characters")
122122
}
123123

124124
ctx = contexts.WithCRE(ctx, contexts.CRE{Owner: idOwner})
125125
if err := r.MaxIdentifierOwnerLengthLimiter.Check(ctx, pkgconfig.Size(len(idOwner))); err != nil {
126126
var errBoundLimited limits.ErrorBoundLimited[pkgconfig.Size]
127127
if errors.As(err, &errBoundLimited) {
128-
return fmt.Errorf("invalid secret identifier: owner exceeds maximum length of %s", errBoundLimited.Limit)
128+
return fmt.Errorf("owner exceeds maximum length of %s", errBoundLimited.Limit)
129129
}
130130
return fmt.Errorf("failed to check owner length limit: %w", err)
131131
}
132132

133133
if err := r.MaxIdentifierNamespaceLengthLimiter.Check(ctx, pkgconfig.Size(len(idNamespace))); err != nil {
134134
var errBoundLimited limits.ErrorBoundLimited[pkgconfig.Size]
135135
if errors.As(err, &errBoundLimited) {
136-
return fmt.Errorf("invalid secret identifier: namespace exceeds maximum length of %s", errBoundLimited.Limit)
136+
return fmt.Errorf("namespace exceeds maximum length of %s", errBoundLimited.Limit)
137137
}
138138
return fmt.Errorf("failed to check namespace length limit: %w", err)
139139
}
140140

141141
if err := r.MaxIdentifierKeyLengthLimiter.Check(ctx, pkgconfig.Size(len(idKey))); err != nil {
142142
var errBoundLimited limits.ErrorBoundLimited[pkgconfig.Size]
143143
if errors.As(err, &errBoundLimited) {
144-
return fmt.Errorf("invalid secret identifier: key exceeds maximum length of %s", errBoundLimited.Limit)
144+
return fmt.Errorf("key exceeds maximum length of %s", errBoundLimited.Limit)
145145
}
146146
return fmt.Errorf("failed to check key length limit: %w", err)
147147
}

core/services/ocr2/plugins/vault/plugin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ func (r *ReportingPluginFactory) NewReportingPlugin(ctx context.Context, config
334334
}
335335

336336
validator := vaultcap.NewRequestValidator(
337-
r.cfg.MaxRequestBatchSize,
338-
r.cfg.MaxCiphertextLengthBytes,
339-
r.cfg.MaxIdentifierKeyLengthBytes,
340-
r.cfg.MaxIdentifierOwnerLengthBytes,
341-
r.cfg.MaxIdentifierNamespaceLengthBytes,
337+
cfg.MaxRequestBatchSize,
338+
cfg.MaxCiphertextLengthBytes,
339+
cfg.MaxIdentifierKeyLengthBytes,
340+
cfg.MaxIdentifierOwnerLengthBytes,
341+
cfg.MaxIdentifierNamespaceLengthBytes,
342342
)
343343

344344
return &ReportingPlugin{

0 commit comments

Comments
 (0)