-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add nodeinfo endpoint for federation purposes #16953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
839abc0
add nodeinfo endpoint for federation purposes
techknowlogick 2be2bd4
update nodeinfo to include info about registration
techknowlogick 6f9eb31
Merge branch 'main' into nodeinfo
techknowlogick 2fe9880
Merge branch 'main' into nodeinfo
techknowlogick d8ec8d0
Merge branch 'main' into nodeinfo
techknowlogick b89041a
Merge branch 'main' into nodeinfo
techknowlogick 13dc173
Merge branch 'main' into nodeinfo
techknowlogick f5b9258
Merge branch 'main' into nodeinfo
techknowlogick 2bd8afb
Merge branch 'main' into nodeinfo
techknowlogick f1d9eba
Merge branch 'main' into nodeinfo
techknowlogick d2a4be3
Merge branch 'main' into nodeinfo
techknowlogick 47f3a67
Merge remote-tracking branch 'upstream/main' into nodeinfo
techknowlogick 6c3f0c2
add federation toggle switch
techknowlogick 18e6b63
Merge branch 'master' into nodeinfo
6543 92ca357
fix import
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package setting | ||
|
||
import "code.gitea.io/gitea/modules/log" | ||
|
||
// Federation settings | ||
var ( | ||
Federation = struct { | ||
Enabled bool | ||
}{ | ||
Enabled: true, | ||
} | ||
) | ||
|
||
func newFederationService() { | ||
if err := Cfg.Section("federation").MapTo(&Federation); err != nil { | ||
log.Fatal("Failed to map Federation settings: %v", err) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package structs | ||
|
||
// NodeInfo contains standardized way of exposing metadata about a server running one of the distributed social networks | ||
type NodeInfo struct { | ||
Version string `json:"version"` | ||
Software NodeInfoSoftware `json:"software"` | ||
Protocols []string `json:"protocols"` | ||
Services NodeInfoServices `json:"services"` | ||
OpenRegistrations bool `json:"openRegistrations"` | ||
Usage NodeInfoUsage `json:"usage"` | ||
Metadata struct{} `json:"metadata"` | ||
} | ||
|
||
// NodeInfoSoftware contains Metadata about server software in use | ||
type NodeInfoSoftware struct { | ||
Name string `json:"name"` | ||
Version string `json:"version"` | ||
Repository string `json:"repository"` | ||
Homepage string `json:"homepage"` | ||
} | ||
|
||
// NodeInfoServices contains the third party sites this server can connect to via their application API | ||
type NodeInfoServices struct { | ||
Inbound []string `json:"inbound"` | ||
Outbound []string `json:"outbound"` | ||
} | ||
|
||
// NodeInfoUsage contains usage statistics for this server | ||
type NodeInfoUsage struct { | ||
Users NodeInfoUsageUsers `json:"users"` | ||
LocalPosts int `json:"localPosts,omitempty"` | ||
LocalComments int `json:"localComments,omitempty"` | ||
} | ||
|
||
// NodeInfoUsageUsers contains statistics about the users of this server | ||
type NodeInfoUsageUsers struct { | ||
Total int `json:"total,omitempty"` | ||
ActiveHalfyear int `json:"activeHalfyear,omitempty"` | ||
ActiveMonth int `json:"activeMonth,omitempty"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package misc | ||
|
||
import ( | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/structs" | ||
) | ||
|
||
// NodeInfo returns the NodeInfo for the Gitea instance to allow for federation | ||
func NodeInfo(ctx *context.APIContext) { | ||
// swagger:operation GET /nodeinfo miscellaneous getNodeInfo | ||
// --- | ||
// summary: Returns the nodeinfo of the Gitea application | ||
// produces: | ||
// - application/json | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/NodeInfo" | ||
|
||
nodeInfo := &structs.NodeInfo{ | ||
Version: "2.1", | ||
Software: structs.NodeInfoSoftware{ | ||
Name: "gitea", | ||
Version: setting.AppVer, | ||
Repository: "https://github.com/go-gitea/gitea.git", | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Homepage: "https://gitea.io/", | ||
}, | ||
Protocols: []string{"activitypub"}, | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Services: structs.NodeInfoServices{ | ||
Inbound: []string{}, | ||
Outbound: []string{}, | ||
}, | ||
OpenRegistrations: setting.Service.ShowRegistrationButton, | ||
Usage: structs.NodeInfoUsage{ | ||
Users: structs.NodeInfoUsageUsers{}, | ||
}, | ||
} | ||
ctx.JSON(http.StatusOK, nodeInfo) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package swagger | ||
|
||
import ( | ||
api "code.gitea.io/gitea/modules/structs" | ||
) | ||
|
||
// NodeInfo | ||
// swagger:response NodeInfo | ||
type swaggerResponseNodeInfo struct { | ||
// in:body | ||
Body api.NodeInfo `json:"body"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package web | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/setting" | ||
) | ||
|
||
type nodeInfoLinks struct { | ||
Links []nodeInfoLink `json:"links"` | ||
} | ||
|
||
type nodeInfoLink struct { | ||
Href string `json:"href"` | ||
Rel string `json:"rel"` | ||
} | ||
|
||
// NodeInfoLinks returns links to the node info endpoint | ||
func NodeInfoLinks(ctx *context.Context) { | ||
nodeinfolinks := &nodeInfoLinks{ | ||
Links: []nodeInfoLink{{ | ||
fmt.Sprintf("%sapi/v1/nodeinfo", setting.AppURL), | ||
"http://nodeinfo.diaspora.software/ns/schema/2.1", | ||
}}, | ||
} | ||
ctx.JSON(http.StatusOK, nodeinfolinks) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.