mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 06:03:51 +03:00
Linting
This commit is contained in:
parent
8585edc47a
commit
1e40b814a1
5 changed files with 25 additions and 26 deletions
|
@ -18,7 +18,7 @@ type Validateables interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActorID struct {
|
type ActorID struct {
|
||||||
ID string
|
Id string
|
||||||
Source string
|
Source string
|
||||||
Schema string
|
Schema string
|
||||||
Path string
|
Path string
|
||||||
|
@ -46,7 +46,7 @@ func newActorID(validatedURI *url.URL, source string) (ActorID, error) {
|
||||||
id := pathWithActorID[length-1]
|
id := pathWithActorID[length-1]
|
||||||
|
|
||||||
result := ActorID{}
|
result := ActorID{}
|
||||||
result.ID = id
|
result.Id = id
|
||||||
result.Source = source
|
result.Source = source
|
||||||
result.Schema = validatedURI.Scheme
|
result.Schema = validatedURI.Scheme
|
||||||
result.Host = validatedURI.Hostname()
|
result.Host = validatedURI.Hostname()
|
||||||
|
@ -85,7 +85,7 @@ func NewPersonID(uri string, source string) (PersonID, error) {
|
||||||
return personID, nil
|
return personID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRepositoryId(uri string, source string) (RepositoryID, error) {
|
func NewRepositoryID(uri string, source string) (RepositoryID, error) {
|
||||||
|
|
||||||
if !validation.IsAPIURL(uri) {
|
if !validation.IsAPIURL(uri) {
|
||||||
return RepositoryID{}, fmt.Errorf("uri %s is not a valid repo url on this host %s", uri, setting.AppURL+"api")
|
return RepositoryID{}, fmt.Errorf("uri %s is not a valid repo url on this host %s", uri, setting.AppURL+"api")
|
||||||
|
@ -113,20 +113,20 @@ func NewRepositoryId(uri string, source string) (RepositoryID, error) {
|
||||||
func (id ActorID) AsURI() string {
|
func (id ActorID) AsURI() string {
|
||||||
var result string
|
var result string
|
||||||
if id.Port == "" {
|
if id.Port == "" {
|
||||||
result = fmt.Sprintf("%s://%s/%s/%s", id.Schema, id.Host, id.Path, id.ID)
|
result = fmt.Sprintf("%s://%s/%s/%s", id.Schema, id.Host, id.Path, id.Id)
|
||||||
} else {
|
} else {
|
||||||
result = fmt.Sprintf("%s://%s:%s/%s/%s", id.Schema, id.Host, id.Port, id.Path, id.ID)
|
result = fmt.Sprintf("%s://%s:%s/%s/%s", id.Schema, id.Host, id.Port, id.Path, id.Id)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id PersonID) AsWebfinger() string {
|
func (id PersonID) AsWebfinger() string {
|
||||||
result := fmt.Sprintf("@%s@%s", strings.ToLower(id.ID), strings.ToLower(id.Host))
|
result := fmt.Sprintf("@%s@%s", strings.ToLower(id.Id), strings.ToLower(id.Host))
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id PersonID) AsLoginName() string {
|
func (id PersonID) AsLoginName() string {
|
||||||
result := fmt.Sprintf("%s%s", strings.ToLower(id.ID), id.HostSuffix())
|
result := fmt.Sprintf("%s%s", strings.ToLower(id.Id), id.HostSuffix())
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ func (id PersonID) HostSuffix() string {
|
||||||
|
|
||||||
// Validate collects error strings in a slice and returns this
|
// Validate collects error strings in a slice and returns this
|
||||||
func (id ActorID) Validate() []string {
|
func (id ActorID) Validate() []string {
|
||||||
var result = []string{}
|
var result []string
|
||||||
result = append(result, validation.ValidateNotEmpty(id.ID, "userId")...)
|
result = append(result, validation.ValidateNotEmpty(id.Id, "userId")...)
|
||||||
result = append(result, validation.ValidateNotEmpty(id.Source, "source")...)
|
result = append(result, validation.ValidateNotEmpty(id.Source, "source")...)
|
||||||
result = append(result, validation.ValidateNotEmpty(id.Schema, "schema")...)
|
result = append(result, validation.ValidateNotEmpty(id.Schema, "schema")...)
|
||||||
result = append(result, validation.ValidateNotEmpty(id.Path, "path")...)
|
result = append(result, validation.ValidateNotEmpty(id.Path, "path")...)
|
||||||
|
@ -154,7 +154,7 @@ func (id ActorID) Validate() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id PersonID) Validate() []string {
|
func (id PersonID) Validate() []string {
|
||||||
var result = id.ActorID.Validate()
|
result := id.ActorID.Validate()
|
||||||
switch id.Source {
|
switch id.Source {
|
||||||
case "forgejo", "gitea":
|
case "forgejo", "gitea":
|
||||||
if strings.ToLower(id.Path) != "api/v1/activitypub/user-id" && strings.ToLower(id.Path) != "api/activitypub/user-id" {
|
if strings.ToLower(id.Path) != "api/v1/activitypub/user-id" && strings.ToLower(id.Path) != "api/activitypub/user-id" {
|
||||||
|
@ -165,7 +165,7 @@ func (id PersonID) Validate() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id RepositoryID) Validate() []string {
|
func (id RepositoryID) Validate() []string {
|
||||||
var result = id.ActorID.Validate()
|
result := id.ActorID.Validate()
|
||||||
switch id.Source {
|
switch id.Source {
|
||||||
case "forgejo", "gitea":
|
case "forgejo", "gitea":
|
||||||
if strings.ToLower(id.Path) != "api/v1/activitypub/repository-id" && strings.ToLower(id.Path) != "api/activitypub/repository-id" {
|
if strings.ToLower(id.Path) != "api/v1/activitypub/repository-id" && strings.ToLower(id.Path) != "api/activitypub/repository-id" {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
func TestNewPersonId(t *testing.T) {
|
func TestNewPersonId(t *testing.T) {
|
||||||
expected := PersonID{}
|
expected := PersonID{}
|
||||||
expected.ID = "1"
|
expected.Id = "1"
|
||||||
expected.Source = "forgejo"
|
expected.Source = "forgejo"
|
||||||
expected.Schema = "https"
|
expected.Schema = "https"
|
||||||
expected.Path = "api/v1/activitypub/user-id"
|
expected.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -24,7 +24,7 @@ func TestNewPersonId(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = PersonID{}
|
expected = PersonID{}
|
||||||
expected.ID = "1"
|
expected.Id = "1"
|
||||||
expected.Source = "forgejo"
|
expected.Source = "forgejo"
|
||||||
expected.Schema = "https"
|
expected.Schema = "https"
|
||||||
expected.Path = "api/v1/activitypub/user-id"
|
expected.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -40,14 +40,14 @@ func TestNewPersonId(t *testing.T) {
|
||||||
func TestNewRepositoryId(t *testing.T) {
|
func TestNewRepositoryId(t *testing.T) {
|
||||||
setting.AppURL = "http://localhost:3000/"
|
setting.AppURL = "http://localhost:3000/"
|
||||||
expected := RepositoryID{}
|
expected := RepositoryID{}
|
||||||
expected.ID = "1"
|
expected.Id = "1"
|
||||||
expected.Source = "forgejo"
|
expected.Source = "forgejo"
|
||||||
expected.Schema = "http"
|
expected.Schema = "http"
|
||||||
expected.Path = "api/activitypub/repository-id"
|
expected.Path = "api/activitypub/repository-id"
|
||||||
expected.Host = "localhost"
|
expected.Host = "localhost"
|
||||||
expected.Port = "3000"
|
expected.Port = "3000"
|
||||||
expected.UnvalidatedInput = "http://localhost:3000/api/activitypub/repository-id/1"
|
expected.UnvalidatedInput = "http://localhost:3000/api/activitypub/repository-id/1"
|
||||||
sut, _ := NewRepositoryId("http://localhost:3000/api/activitypub/repository-id/1", "forgejo")
|
sut, _ := NewRepositoryID("http://localhost:3000/api/activitypub/repository-id/1", "forgejo")
|
||||||
if sut != expected {
|
if sut != expected {
|
||||||
t.Errorf("expected: %v\n but was: %v\n", expected, sut)
|
t.Errorf("expected: %v\n but was: %v\n", expected, sut)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func TestActorIdValidation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sut = ActorID{}
|
sut = ActorID{}
|
||||||
sut.ID = "1"
|
sut.Id = "1"
|
||||||
sut.Source = "forgejox"
|
sut.Source = "forgejox"
|
||||||
sut.Schema = "https"
|
sut.Schema = "https"
|
||||||
sut.Path = "api/v1/activitypub/user-id"
|
sut.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -78,7 +78,7 @@ func TestActorIdValidation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sut = ActorID{}
|
sut = ActorID{}
|
||||||
sut.ID = "1"
|
sut.Id = "1"
|
||||||
sut.Source = "forgejo"
|
sut.Source = "forgejo"
|
||||||
sut.Schema = "https"
|
sut.Schema = "https"
|
||||||
sut.Path = "api/v1/activitypub/user-id"
|
sut.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -92,7 +92,7 @@ func TestActorIdValidation(t *testing.T) {
|
||||||
|
|
||||||
func TestPersonIdValidation(t *testing.T) {
|
func TestPersonIdValidation(t *testing.T) {
|
||||||
sut := PersonID{}
|
sut := PersonID{}
|
||||||
sut.ID = "1"
|
sut.Id = "1"
|
||||||
sut.Source = "forgejo"
|
sut.Source = "forgejo"
|
||||||
sut.Schema = "https"
|
sut.Schema = "https"
|
||||||
sut.Path = "path"
|
sut.Path = "path"
|
||||||
|
|
|
@ -36,7 +36,8 @@ type Star struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StarNew initializes a Star type activity
|
// StarNew initializes a Star type activity
|
||||||
func StarNew(id ap.ID, ob ap.ID) *Star { // ToDo: May be used later in creating signed activities
|
// ToDo: May be used later in creating signed activities
|
||||||
|
func StarNew(id ap.ID, ob ap.ID) *Star {
|
||||||
a := ap.ActivityNew(id, StarType, ob)
|
a := ap.ActivityNew(id, StarType, ob)
|
||||||
o := Star{Activity: *a, Source: ForgejoSourceType}
|
o := Star{Activity: *a, Source: ForgejoSourceType}
|
||||||
return &o
|
return &o
|
||||||
|
|
|
@ -62,7 +62,6 @@ func TestNewClientReturnsClient(t *testing.T) {
|
||||||
|
|
||||||
log.Debug("Client: %v\nError: %v", c, err)
|
log.Debug("Client: %v\nError: %v", c, err)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: bring this test to work or delete
|
/* TODO: bring this test to work or delete
|
||||||
|
|
|
@ -97,12 +97,12 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
log.Info("RepositoryInbox: actorId validated: %v", actorID)
|
log.Info("RepositoryInbox: actorId validated: %v", actorID)
|
||||||
// parse objectID (repository)
|
// parse objectID (repository)
|
||||||
objectID, err := forgefed.NewRepositoryId(activity.Object.GetID().String(), string(activity.Source))
|
objectID, err := forgefed.NewRepositoryID(activity.Object.GetID().String(), string(activity.Source))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("Validate objectId", err)
|
ctx.ServerError("Validate objectId", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if objectID.ID != fmt.Sprint(repository.ID) {
|
if objectID.Id != fmt.Sprint(repository.ID) {
|
||||||
ctx.ServerError("Validate objectId", err)
|
ctx.ServerError("Validate objectId", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
|
|
||||||
// TODO: Move this to model.user.search ? or to model.user.externalLoginUser ?
|
// TODO: Move this to model.user.search ? or to model.user.externalLoginUser ?
|
||||||
func SearchUsersByLoginName(loginName string) ([]*user_model.User, error) {
|
func SearchUsersByLoginName(loginName string) ([]*user_model.User, error) {
|
||||||
var actionsUser = user_model.NewActionsUser()
|
actionsUser := user_model.NewActionsUser()
|
||||||
actionsUser.IsAdmin = true
|
actionsUser.IsAdmin = true
|
||||||
|
|
||||||
options := &user_model.SearchUserOptions{
|
options := &user_model.SearchUserOptions{
|
||||||
|
@ -178,13 +178,12 @@ func SearchUsersByLoginName(loginName string) ([]*user_model.User, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return users, nil
|
return users, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: Maybe use externalLoginUser
|
// ToDo: Maybe use externalLoginUser
|
||||||
func createUserFromAP(ctx *context.APIContext, personID forgefed.PersonID) (*user_model.User, error) {
|
func createUserFromAP(ctx *context.APIContext, personID forgefed.PersonID) (*user_model.User, error) {
|
||||||
// ToDo: Do we get a publicKeyId from server, repo or owner or repo?
|
// ToDo: Do we get a publicKeyId from server, repo or owner or repo?
|
||||||
var actionsUser = user_model.NewActionsUser()
|
actionsUser := user_model.NewActionsUser()
|
||||||
client, err := api.NewClient(ctx, actionsUser, "no idea where to get key material.")
|
client, err := api.NewClient(ctx, actionsUser, "no idea where to get key material.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &user_model.User{}, err
|
return &user_model.User{}, err
|
||||||
|
@ -198,7 +197,7 @@ func createUserFromAP(ctx *context.APIContext, personID forgefed.PersonID) (*use
|
||||||
|
|
||||||
// validate response; ToDo: Should we widen the restrictions here?
|
// validate response; ToDo: Should we widen the restrictions here?
|
||||||
if response.StatusCode != 200 {
|
if response.StatusCode != 200 {
|
||||||
err = fmt.Errorf("got non 200 status code for id: %v", personID.ID)
|
err = fmt.Errorf("got non 200 status code for id: %v", personID.Id)
|
||||||
return &user_model.User{}, err
|
return &user_model.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue