1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

Allow to disable swagger (#2093)

https://github.com/woodpecker-ci/woodpecker/issues/1944
This commit is contained in:
qwerty287 2023-08-03 02:42:30 +02:00 committed by GitHub
parent f06e0acdc6
commit 1a7f7a9427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 9 deletions

View File

@ -272,6 +272,11 @@ var flags = []cli.Flag{
Name: "migrations-allow-long",
Value: false,
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_ENABLE_SWAGGER"},
Name: "enable-swagger",
Value: true,
},
//
// resource limit parameters
//

View File

@ -364,6 +364,7 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
server.Config.Pipeline.Volumes = c.StringSlice("volume")
server.Config.Pipeline.Privileged = c.StringSlice("escalate")
server.Config.Server.Migrations.AllowLong = c.Bool("migrations-allow-long")
server.Config.Server.EnableSwagger = c.Bool("enable-swagger")
// prometheus
server.Config.Prometheus.AuthToken = c.String("prometheus-auth-token")

View File

@ -535,6 +535,11 @@ Server URL path prefix (used for statics loading when having a url path prefix),
Example: `WOODPECKER_ROOT_URL=/woodpecker`
### `WOODPECKER_ENABLE_SWAGGER`
> Default: true
Enable the Swagger UI for API documentation.
---
### `WOODPECKER_GITHUB_...`

View File

@ -73,6 +73,7 @@ var Config = struct {
Migrations struct {
AllowLong bool
}
EnableSwagger bool
// Open bool
// Orgs map[string]struct{}
// Admins map[string]struct{}

View File

@ -69,7 +69,9 @@ func Load(noRouteHandler http.HandlerFunc, middleware ...gin.HandlerFunc) http.H
e.GET("/healthz", api.Health)
apiRoutes(e)
setupSwaggerConfigAndRoutes(e)
if server.Config.Server.EnableSwagger {
setupSwaggerConfigAndRoutes(e)
}
return e
}

View File

@ -40,12 +40,13 @@ func Config(c *gin.Context) {
}
configData := map[string]interface{}{
"user": user,
"csrf": csrf,
"docs": server.Config.Server.Docs,
"version": version.String(),
"forge": server.Config.Services.Forge.Name(),
"root_url": server.Config.Server.RootURL,
"user": user,
"csrf": csrf,
"docs": server.Config.Server.Docs,
"version": version.String(),
"forge": server.Config.Services.Forge.Name(),
"root_url": server.Config.Server.RootURL,
"enable_swagger": server.Config.Server.EnableSwagger,
}
// default func map with json parser.
@ -75,4 +76,5 @@ window.WOODPECKER_VERSION = "{{ .version }}";
window.WOODPECKER_DOCS = "{{ .docs }}";
window.WOODPECKER_FORGE = "{{ .forge }}";
window.WOODPECKER_ROOT_URL = "{{ .root_url }}";
window.WOODPECKER_ENABLE_SWAGGER = {{ .enable_swagger }};
`

View File

@ -18,7 +18,9 @@
<!-- Docs Link -->
<a :href="docsUrl" target="_blank" class="navbar-link navbar-clickable hidden md:flex">{{ $t('docs') }}</a>
<!-- API Link -->
<a :href="apiUrl" target="_blank" class="navbar-link navbar-clickable hidden md:flex">{{ $t('api') }}</a>
<a v-if="enableSwagger" :href="apiUrl" target="_blank" class="navbar-link navbar-clickable hidden md:flex">{{
$t('api')
}}</a>
</div>
<!-- Right Icons Box -->
<div class="flex ml-auto -m-1.5 items-center space-x-2">
@ -82,7 +84,15 @@ export default defineComponent({
const version = config.version?.startsWith('next') ? 'next' : config.version;
return { darkMode, user: authentication.user, doLogin, docsUrl, version, apiUrl };
return {
darkMode,
user: authentication.user,
doLogin,
docsUrl,
version,
apiUrl,
enableSwagger: config.enableSwagger,
};
},
});
</script>

View File

@ -8,6 +8,7 @@ declare global {
WOODPECKER_CSRF: string | undefined;
WOODPECKER_FORGE: string | undefined;
WOODPECKER_ROOT_URL: string | undefined;
WOODPECKER_ENABLE_SWAGGER: boolean | undefined;
}
}
@ -18,4 +19,5 @@ export default () => ({
csrf: window.WOODPECKER_CSRF || null,
forge: window.WOODPECKER_FORGE || null,
rootURL: window.WOODPECKER_ROOT_URL || null,
enableSwagger: window.WOODPECKER_ENABLE_SWAGGER || false,
});

View File

@ -22,6 +22,7 @@
<div class="flex items-center">
<h2 class="text-lg text-wp-text-100">{{ $t('user.api_usage') }}</h2>
<a
v-if="enableSwagger"
:href="`${address}/swagger/index.html`"
target="_blank"
class="ml-4 text-wp-link-100 hover:text-wp-link-200"
@ -56,9 +57,11 @@ import Button from '~/components/atomic/Button.vue';
import SelectField from '~/components/form/SelectField.vue';
import Scaffold from '~/components/layout/scaffold/Scaffold.vue';
import useApiClient from '~/compositions/useApiClient';
import useConfig from '~/compositions/useConfig';
import { setI18nLanguage } from '~/compositions/useI18n';
const { t, locale } = useI18n();
const { enableSwagger } = useConfig();
const apiClient = useApiClient();
const token = ref<string | undefined>();