63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"code.gitea.io/sdk/gitea"
|
||
|
"git.lumeweb.com/LumeWeb/gitea-github-proxy/config"
|
||
|
"github.com/gorilla/mux"
|
||
|
"go.uber.org/zap"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
func SetupRoutes(r *mux.Router, cfg *config.Config, db *gorm.DB, logger *zap.Logger) {
|
||
|
|
||
|
r.Use(loggingMiddleware(logger))
|
||
|
|
||
|
setupRouter := r.PathPrefix("/setup").Subrouter()
|
||
|
setupRouter.Use(giteaOauthVerifyMiddleware(cfg))
|
||
|
|
||
|
setupApi := newSetupApi(cfg, logger, newOauth(cfg, logger))
|
||
|
setupRouter.HandleFunc("", setupApi.setupHandler).Methods("GET")
|
||
|
setupRouter.HandleFunc("/callback", setupApi.callbackHandler).Methods("GET")
|
||
|
|
||
|
settingsRouter := r.PathPrefix("/settings").Subrouter()
|
||
|
settingsRouter.Use(giteaOauthVerifyMiddleware(cfg))
|
||
|
settingsRouter.Use(requireAuthMiddleware(cfg))
|
||
|
|
||
|
settingsApi := newSettingsApi(cfg, db, logger)
|
||
|
|
||
|
settingsRouter.HandleFunc("/apps/new", settingsApi.handlerNewApp).Methods("POST")
|
||
|
|
||
|
manifestApi := newManifests(cfg, db, logger)
|
||
|
manifestsRouter := r.PathPrefix("/api/v3/app-manifests").Subrouter()
|
||
|
|
||
|
manifestsRouter.HandleFunc("/{code}/conversions", manifestApi.handlerConversion).Methods("POST")
|
||
|
|
||
|
appApi := newAppApi(cfg, logger)
|
||
|
appRouter := r.PathPrefix("/apps").Subrouter()
|
||
|
|
||
|
appRouter.Use(giteaOauthVerifyMiddleware(cfg))
|
||
|
appRouter.Use(requireAuthMiddleware(cfg))
|
||
|
|
||
|
appRouter.HandleFunc("/{app}/installations/new", appApi.handlerNewAppInstall).Methods("GET")
|
||
|
}
|
||
|
|
||
|
type ClientParams struct {
|
||
|
Config *config.Config
|
||
|
AuthToken string
|
||
|
}
|
||
|
|
||
|
func getClient(params ClientParams) (*gitea.Client, error) {
|
||
|
options := make([]gitea.ClientOption, 0)
|
||
|
|
||
|
if len(params.AuthToken) > 0 {
|
||
|
options = append(options, gitea.SetToken(params.AuthToken))
|
||
|
}
|
||
|
|
||
|
client, err := gitea.NewClient(params.Config.GiteaUrl, options...)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return client, nil
|
||
|
}
|