Skip to content

Commit

Permalink
move api/_apimeta to api/apimeta
Browse files Browse the repository at this point in the history
  • Loading branch information
mpldr committed Mar 3, 2024
1 parent d2c13a9 commit 648be6c
Show file tree
Hide file tree
Showing 27 changed files with 87 additions and 87 deletions.
8 changes: 4 additions & 4 deletions api/_routers/97-optional-access-token.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/getsentry/sentry-go"
"github.com/sirupsen/logrus"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_auth_cache"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/common/config"
"github.com/t2bot/matrix-media-repo/common/rcontext"
"github.com/t2bot/matrix-media-repo/matrix"
Expand All @@ -19,15 +19,15 @@ func OptionalAccessToken(generator GeneratorWithUserFn) GeneratorFn {
return func(r *http.Request, ctx rcontext.RequestContext) interface{} {
accessToken := util.GetAccessTokenFromRequest(r)
if accessToken == "" {
return generator(r, ctx, _apimeta.UserInfo{
return generator(r, ctx, apimeta.UserInfo{
UserId: "",
AccessToken: "",
IsShared: false,
})
}
if config.Get().SharedSecret.Enabled && accessToken == config.Get().SharedSecret.Token {
ctx = ctx.LogWithFields(logrus.Fields{"sharedSecretAuth": true})
return generator(r, ctx, _apimeta.UserInfo{
return generator(r, ctx, apimeta.UserInfo{
UserId: "@sharedsecret",
AccessToken: accessToken,
IsShared: true,
Expand All @@ -47,7 +47,7 @@ func OptionalAccessToken(generator GeneratorWithUserFn) GeneratorFn {
}

ctx = ctx.LogWithFields(logrus.Fields{"authUserId": userId})
return generator(r, ctx, _apimeta.UserInfo{
return generator(r, ctx, apimeta.UserInfo{
UserId: userId,
AccessToken: accessToken,
IsShared: false,
Expand Down
8 changes: 4 additions & 4 deletions api/_routers/97-require-access-token.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (

"github.com/getsentry/sentry-go"
"github.com/sirupsen/logrus"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_auth_cache"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/common"
"github.com/t2bot/matrix-media-repo/common/config"
"github.com/t2bot/matrix-media-repo/common/rcontext"
"github.com/t2bot/matrix-media-repo/matrix"
"github.com/t2bot/matrix-media-repo/util"
)

type GeneratorWithUserFn = func(r *http.Request, ctx rcontext.RequestContext, user _apimeta.UserInfo) interface{}
type GeneratorWithUserFn = func(r *http.Request, ctx rcontext.RequestContext, user apimeta.UserInfo) interface{}

func RequireAccessToken(generator GeneratorWithUserFn) GeneratorFn {
return func(r *http.Request, ctx rcontext.RequestContext) interface{} {
Expand All @@ -30,7 +30,7 @@ func RequireAccessToken(generator GeneratorWithUserFn) GeneratorFn {
}
if config.Get().SharedSecret.Enabled && accessToken == config.Get().SharedSecret.Token {
ctx = ctx.LogWithFields(logrus.Fields{"sharedSecretAuth": true})
return generator(r, ctx, _apimeta.UserInfo{
return generator(r, ctx, apimeta.UserInfo{
UserId: "@sharedsecret",
AccessToken: accessToken,
IsShared: true,
Expand All @@ -51,7 +51,7 @@ func RequireAccessToken(generator GeneratorWithUserFn) GeneratorFn {
}

ctx = ctx.LogWithFields(logrus.Fields{"authUserId": userId})
return generator(r, ctx, _apimeta.UserInfo{
return generator(r, ctx, apimeta.UserInfo{
UserId: userId,
AccessToken: accessToken,
IsShared: false,
Expand Down
4 changes: 2 additions & 2 deletions api/_routers/97-require-repo-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"net/http"

"github.com/sirupsen/logrus"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/common/rcontext"
"github.com/t2bot/matrix-media-repo/util"
)

func RequireRepoAdmin(generator GeneratorWithUserFn) GeneratorFn {
return func(r *http.Request, ctx rcontext.RequestContext) interface{} {
return RequireAccessToken(func(r *http.Request, ctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
return RequireAccessToken(func(r *http.Request, ctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if user.UserId == "" {
logrus.Error("safety check failed: Repo admin access check received empty user ID")
return _responses.AuthFailed()
Expand Down
2 changes: 1 addition & 1 deletion api/_apimeta/auth.go → api/apimeta/auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package _apimeta
package apimeta

import (
"net/http"
Expand Down
8 changes: 4 additions & 4 deletions api/custom/datastores.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"time"

"github.com/getsentry/sentry-go"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/_routers"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/common/config"
"github.com/t2bot/matrix-media-repo/datastores"
"github.com/t2bot/matrix-media-repo/tasks"
Expand All @@ -24,7 +24,7 @@ type DatastoreMigration struct {
TaskID int `json:"task_id"`
}

func GetDatastores(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func GetDatastores(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
response := make(map[string]interface{})
for _, store := range config.UniqueDatastores() {
uri, err := datastores.GetUri(store)
Expand All @@ -42,7 +42,7 @@ func GetDatastores(r *http.Request, rctx rcontext.RequestContext, user _apimeta.
return &_responses.DoNotCacheResponse{Payload: response}
}

func MigrateBetweenDatastores(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func MigrateBetweenDatastores(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
beforeTsStr := r.URL.Query().Get("before_ts")
beforeTs := time.Now().UnixMilli()
var err error
Expand Down Expand Up @@ -95,7 +95,7 @@ func MigrateBetweenDatastores(r *http.Request, rctx rcontext.RequestContext, use
return &_responses.DoNotCacheResponse{Payload: migration}
}

func GetDatastoreStorageEstimate(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func GetDatastoreStorageEstimate(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
beforeTsStr := r.URL.Query().Get("before_ts")
beforeTs := time.Now().UnixMilli()
var err error
Expand Down
14 changes: 7 additions & 7 deletions api/custom/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strconv"

"github.com/getsentry/sentry-go"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/_routers"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/database"
"github.com/t2bot/matrix-media-repo/datastores"
"github.com/t2bot/matrix-media-repo/tasks"
Expand Down Expand Up @@ -38,7 +38,7 @@ type ExportMetadata struct {
Parts []*ExportPartMetadata `json:"parts"`
}

func ExportUserData(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func ExportUserData(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func ExportUserData(r *http.Request, rctx rcontext.RequestContext, user _apimeta
}}
}

func ExportServerData(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func ExportServerData(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func ExportServerData(r *http.Request, rctx rcontext.RequestContext, user _apime
}}
}

func ViewExport(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func ViewExport(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func ViewExport(r *http.Request, rctx rcontext.RequestContext, user _apimeta.Use
return &_responses.HtmlResponse{HTML: html.String()}
}

func GetExportMetadata(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func GetExportMetadata(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func GetExportMetadata(r *http.Request, rctx rcontext.RequestContext, user _apim
return &_responses.DoNotCacheResponse{Payload: metadata}
}

func DownloadExportPart(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func DownloadExportPart(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func DownloadExportPart(r *http.Request, rctx rcontext.RequestContext, user _api
}
}

func DeleteExport(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func DeleteExport(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down
4 changes: 2 additions & 2 deletions api/custom/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"net/http"

"github.com/getsentry/sentry-go"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/_routers"
"github.com/t2bot/matrix-media-repo/api/apimeta"

"github.com/sirupsen/logrus"
"github.com/t2bot/matrix-media-repo/common/rcontext"
"github.com/t2bot/matrix-media-repo/matrix"
)

func GetFederationInfo(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func GetFederationInfo(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
serverName := _routers.GetParam("serverName", r)

if !_routers.ServerNameRegex.MatchString(serverName) {
Expand Down
4 changes: 2 additions & 2 deletions api/custom/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package custom
import (
"net/http"

"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/common/rcontext"
)

Expand All @@ -13,7 +13,7 @@ type HealthzResponse struct {
Status string `json:"status"`
}

func GetHealthz(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func GetHealthz(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
return &_responses.DoNotCacheResponse{
Payload: &HealthzResponse{
OK: true,
Expand Down
8 changes: 4 additions & 4 deletions api/custom/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"net/http"

"github.com/getsentry/sentry-go"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/_routers"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/common"
"github.com/t2bot/matrix-media-repo/tasks"
"github.com/t2bot/matrix-media-repo/tasks/task_runner"
Expand All @@ -21,7 +21,7 @@ type ImportStarted struct {
TaskID int `json:"task_id"`
}

func StartImport(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func StartImport(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down Expand Up @@ -49,7 +49,7 @@ func StartImport(r *http.Request, rctx rcontext.RequestContext, user _apimeta.Us
}}
}

func AppendToImport(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func AppendToImport(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand All @@ -76,7 +76,7 @@ func AppendToImport(r *http.Request, rctx rcontext.RequestContext, user _apimeta
return &_responses.DoNotCacheResponse{Payload: &_responses.EmptyResponse{}}
}

func StopImport(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func StopImport(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
if !rctx.Config.Archiving.Enabled {
return _responses.BadRequest(errors.New("archiving is not enabled"))
}
Expand Down
8 changes: 4 additions & 4 deletions api/custom/media_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/getsentry/sentry-go"
"github.com/sirupsen/logrus"
"github.com/t2bot/matrix-media-repo/api/_apimeta"
"github.com/t2bot/matrix-media-repo/api/_responses"
"github.com/t2bot/matrix-media-repo/api/_routers"
"github.com/t2bot/matrix-media-repo/api/apimeta"
"github.com/t2bot/matrix-media-repo/common/rcontext"
"github.com/t2bot/matrix-media-repo/database"
"github.com/t2bot/matrix-media-repo/matrix"
Expand All @@ -20,7 +20,7 @@ type Attributes struct {
Purpose database.Purpose `json:"purpose"`
}

func canChangeAttributes(rctx rcontext.RequestContext, r *http.Request, origin string, user _apimeta.UserInfo) bool {
func canChangeAttributes(rctx rcontext.RequestContext, r *http.Request, origin string, user apimeta.UserInfo) bool {
isGlobalAdmin := util.IsGlobalAdmin(user.UserId) || user.IsShared
if isGlobalAdmin {
return true
Expand All @@ -33,7 +33,7 @@ func canChangeAttributes(rctx rcontext.RequestContext, r *http.Request, origin s
return isLocalAdmin
}

func GetAttributes(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func GetAttributes(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
origin := _routers.GetParam("server", r)
mediaId := _routers.GetParam("mediaId", r)

Expand Down Expand Up @@ -79,7 +79,7 @@ func GetAttributes(r *http.Request, rctx rcontext.RequestContext, user _apimeta.
return &_responses.DoNotCacheResponse{Payload: retAttrs}
}

func SetAttributes(r *http.Request, rctx rcontext.RequestContext, user _apimeta.UserInfo) interface{} {
func SetAttributes(r *http.Request, rctx rcontext.RequestContext, user apimeta.UserInfo) interface{} {
origin := _routers.GetParam("server", r)
mediaId := _routers.GetParam("mediaId", r)

Expand Down
Loading

0 comments on commit 648be6c

Please sign in to comment.