mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 08:42:32 -05:00
Implement generic validation on ActorID
This commit is contained in:
parent
7b5d13a625
commit
d205c50a43
1 changed files with 15 additions and 4 deletions
|
@ -7,6 +7,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Validatable interface {
|
type Validatable interface {
|
||||||
|
validate_is_not_nil() error
|
||||||
|
validate_is_not_empty() error
|
||||||
Validate() error
|
Validate() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,15 +20,24 @@ type ActorID struct {
|
||||||
port string // optional
|
port string // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a ActorID) validate_is_not_empty(str string, field string) error {
|
||||||
|
|
||||||
|
if str != "" {
|
||||||
|
return fmt.Errorf("field %v was empty", field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Align validation-api to example from dda-devops-build
|
// TODO: Align validation-api to example from dda-devops-build
|
||||||
func (a ActorID) Validate() error {
|
func (a ActorID) Validate() error {
|
||||||
|
|
||||||
if a.schema == "" {
|
if err := a.validate_is_not_empty(a.schema, "schema"); err != nil {
|
||||||
return fmt.Errorf("the actor ID was not valid: Invalid Schema")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.host == "" {
|
if err := a.validate_is_not_empty(a.host, "host"); err != nil {
|
||||||
return fmt.Errorf("the actor ID was not valid: Invalid Host")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(a.path, "api/v1/activitypub/user-id") {
|
if !strings.Contains(a.path, "api/v1/activitypub/user-id") {
|
||||||
|
|
Loading…
Reference in a new issue