mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 08:59:31 -05:00
Rename to actorID
This commit is contained in:
parent
5e111f14ef
commit
235ed7cd1e
3 changed files with 12 additions and 13 deletions
|
@ -6,8 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Name ActorId ?
|
type ActorID struct {
|
||||||
type ActorData struct {
|
|
||||||
schema string
|
schema string
|
||||||
userId string
|
userId string
|
||||||
path string
|
path string
|
||||||
|
@ -16,7 +15,7 @@ type ActorData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Align validation-api to example from dda-devops-build
|
// TODO: Align validation-api to example from dda-devops-build
|
||||||
func (a ActorData) ValidateActorData() error {
|
func (a ActorID) ValidateActorID() error {
|
||||||
|
|
||||||
if a.schema == "" || a.host == "" {
|
if a.schema == "" || a.host == "" {
|
||||||
return fmt.Errorf("the actor ID was not valid: Invalid Schema or Host")
|
return fmt.Errorf("the actor ID was not valid: Invalid Schema or Host")
|
||||||
|
@ -30,18 +29,18 @@ func (a ActorData) ValidateActorData() error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseActorData(actor string) (ActorData, error) {
|
func ParseActorID(actor string) (ActorID, error) {
|
||||||
u, err := url.Parse(actor)
|
u, err := url.Parse(actor)
|
||||||
|
|
||||||
// check if userID IRI is well formed url
|
// check if userID IRI is well formed url
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ActorData{}, fmt.Errorf("the actor ID was not a valid IRI: %v", err)
|
return ActorID{}, fmt.Errorf("the actor ID was not a valid IRI: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pathWithUserID := strings.Split(u.Path, "/")
|
pathWithUserID := strings.Split(u.Path, "/")
|
||||||
userId := pathWithUserID[len(pathWithUserID)-1]
|
userId := pathWithUserID[len(pathWithUserID)-1]
|
||||||
|
|
||||||
return ActorData{
|
return ActorID{
|
||||||
schema: u.Scheme,
|
schema: u.Scheme,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
host: u.Host,
|
host: u.Host,
|
||||||
|
|
|
@ -10,17 +10,17 @@ import (
|
||||||
func Test_ActorParser(t *testing.T) {
|
func Test_ActorParser(t *testing.T) {
|
||||||
type testPair struct {
|
type testPair struct {
|
||||||
item string
|
item string
|
||||||
want ActorData
|
want ActorID
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := map[string]testPair{
|
tests := map[string]testPair{
|
||||||
"empty": {
|
"empty": {
|
||||||
item: "",
|
item: "",
|
||||||
want: ActorData{},
|
want: ActorID{},
|
||||||
},
|
},
|
||||||
"withValidActorID": {
|
"withValidActorID": {
|
||||||
item: "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1",
|
item: "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1",
|
||||||
want: ActorData{
|
want: ActorID{
|
||||||
schema: "https",
|
schema: "https",
|
||||||
userId: "1",
|
userId: "1",
|
||||||
path: "/api/v1/activitypub/user-id/1",
|
path: "/api/v1/activitypub/user-id/1",
|
||||||
|
@ -30,7 +30,7 @@ func Test_ActorParser(t *testing.T) {
|
||||||
},
|
},
|
||||||
"withInvalidActorID": {
|
"withInvalidActorID": {
|
||||||
item: "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
item: "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
||||||
want: ActorData{
|
want: ActorID{
|
||||||
schema: "https",
|
schema: "https",
|
||||||
userId: "1",
|
userId: "1",
|
||||||
path: "/api/v1/activitypub/user-id/1",
|
path: "/api/v1/activitypub/user-id/1",
|
||||||
|
@ -42,7 +42,7 @@ func Test_ActorParser(t *testing.T) {
|
||||||
|
|
||||||
for name, _ := range tests {
|
for name, _ := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
_, err := ParseActorData(tests[name].item)
|
_, err := ParseActorID(tests[name].item)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("parseActor() error = \"%v\"", err)
|
t.Errorf("parseActor() error = \"%v\"", err)
|
||||||
|
|
|
@ -88,7 +88,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
// assume actor is: "actor": "https://codeberg.org/api/v1/activitypub/user-id/12345" - NB: This might be actually the ID? Maybe check vocabulary.
|
// assume actor is: "actor": "https://codeberg.org/api/v1/activitypub/user-id/12345" - NB: This might be actually the ID? Maybe check vocabulary.
|
||||||
// TODO: validate input in front of parsing.
|
// TODO: validate input in front of parsing.
|
||||||
// parse actor
|
// parse actor
|
||||||
actor, err := activitypub.ParseActorData(opt.Actor.GetID().String())
|
actor, err := activitypub.ParseActorID(opt.Actor.GetID().String())
|
||||||
|
|
||||||
// Is the actor IRI well formed?
|
// Is the actor IRI well formed?
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,7 +96,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the ActorData Struct valid?
|
// Is the ActorData Struct valid?
|
||||||
err = actor.ValidateActorData()
|
err = actor.ValidateActorID()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
Loading…
Reference in a new issue