Skip to content

Commit 3af3011

Browse files
committed
chore: add validate function in policy custom steps
1 parent 0c1e4e5 commit 3af3011

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

core/policy/service.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,23 +397,13 @@ func (s *Service) validatePolicy(ctx context.Context, p *domain.Policy, excluded
397397
}
398398

399399
if p.HasCustomSteps() {
400-
if err := s.validateCustomSteps(p.CustomSteps); err != nil {
401-
return fmt.Errorf("invalid dynamic policy steps data: %w", err)
400+
if err := p.CustomSteps.Validate(); err != nil {
401+
return fmt.Errorf("invalid custom policy steps data: %w", err)
402402
}
403403
}
404404
return nil
405405
}
406406

407-
func (s *Service) validateCustomSteps(customSteps *domain.CustomSteps) error {
408-
if customSteps.Type != "http" {
409-
return fmt.Errorf("invalid custom steps type: %s", customSteps.Type)
410-
}
411-
if customSteps.Config == nil {
412-
return fmt.Errorf("config should not be empty")
413-
}
414-
return nil
415-
}
416-
417407
func (s *Service) validateAppealMetadataSource(ctx context.Context, metadataSource *domain.AppealMetadataSource) error {
418408
if metadataSource.Name == "" {
419409
return fmt.Errorf("name should not be empty")

domain/policy_custom_steps.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,13 @@ func (c *CustomSteps) DecryptConfig(dec Decryptor) error {
4747

4848
return nil
4949
}
50+
51+
func (c *CustomSteps) Validate() error {
52+
if c.Type != "http" {
53+
return fmt.Errorf("invalid custom steps type: %s", c.Type)
54+
}
55+
if c.Config == nil {
56+
return fmt.Errorf("config should not be empty")
57+
}
58+
return nil
59+
}

0 commit comments

Comments
 (0)