make serving published repos in api mode configurable

This commit is contained in:
Markus Muellner
2023-03-20 11:55:47 +01:00
committed by Benj Fassbind
parent f74217ed9c
commit 0fdba29d51
6 changed files with 21 additions and 14 deletions
+11 -10
View File
@@ -51,18 +51,19 @@ func Router(c *ctx.AptlyContext) http.Handler {
MetricsCollectorRegistrar.Register(router)
}
router.GET("/repos/:storage/*pkgPath", func(c *gin.Context) {
pkgpath := c.Param("pkgPath")
if c.Config().ServeInAPIMode {
router.GET("/repos/:storage/*pkgPath", func(c *gin.Context) {
pkgpath := c.Param("pkgPath")
storage := c.Param("storage")
if storage == "-" {
storage = ""
}
storage := c.Param("storage")
if storage == "-" {
storage = ""
}
publicPath := context.GetPublishedStorage("filesystem:" + storage).(aptly.FileSystemPublishedStorage).PublicPath()
c.FileFromFS(pkgpath, http.Dir(publicPath))
})
publicPath := context.GetPublishedStorage("filesystem:" + storage).(aptly.FileSystemPublishedStorage).PublicPath()
c.FileFromFS(pkgpath, http.Dir(publicPath))
})
}
api := router.Group("/api")
if context.Flags().Lookup("no-lock").Value.Get().(bool) {
+2 -1
View File
@@ -148,7 +148,8 @@ class BaseTest(object):
"ppaCodename": "",
"enableMetricsEndpoint": True,
"logLevel": "debug",
"logFormat": "default"
"logFormat": "default",
"serveInAPIMode": True
}
configOverride = {}
environmentOverride = {}
+2 -1
View File
@@ -27,5 +27,6 @@
"AsyncAPI": false,
"enableMetricsEndpoint": true,
"logLevel": "debug",
"logFormat": "default"
"logFormat": "default",
"serveInAPIMode": true
}
+2 -1
View File
@@ -27,5 +27,6 @@
"AsyncAPI": false,
"enableMetricsEndpoint": false,
"logLevel": "debug",
"logFormat": "default"
"logFormat": "default",
"serveInAPIMode": false
}
+2
View File
@@ -37,6 +37,7 @@ type ConfigStructure struct { // nolint: maligned
EnableMetricsEndpoint bool `json:"enableMetricsEndpoint"`
LogLevel string `json:"logLevel"`
LogFormat string `json:"logFormat"`
ServeInAPIMode bool `json:"serveInAPIMode"`
}
// FileSystemPublishRoot describes single filesystem publishing entry point
@@ -116,6 +117,7 @@ var Config = ConfigStructure{
EnableMetricsEndpoint: false,
LogLevel: "debug",
LogFormat: "default",
ServeInAPIMode: false,
}
// LoadConfig loads configuration from json file
+2 -1
View File
@@ -136,7 +136,8 @@ func (s *ConfigSuite) TestSaveConfig(c *C) {
" \"AsyncAPI\": false,\n"+
" \"enableMetricsEndpoint\": false,\n"+
" \"logLevel\": \"info\",\n"+
" \"logFormat\": \"json\"\n"+
" \"logFormat\": \"json\",\n"+
" \"serveInAPIMode\": false\n"+
"}")
}