Skip to content
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

Allow to disable swagger #2093

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
1 change: 1 addition & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/30-administration/10-server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_...`
Expand Down
1 change: 1 addition & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var Config = struct {
Migrations struct {
AllowLong bool
}
EnableSwagger bool
// Open bool
// Orgs map[string]struct{}
// Admins map[string]struct{}
Expand Down
4 changes: 3 additions & 1 deletion server/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 8 additions & 6 deletions server/web/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }};
`
14 changes: 12 additions & 2 deletions web/src/components/layout/header/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions web/src/compositions/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
WOODPECKER_CSRF: string | undefined;
WOODPECKER_FORGE: string | undefined;
WOODPECKER_ROOT_URL: string | undefined;
WOODPECKER_ENABLE_SWAGGER: boolean | undefined;
}
}

Expand All @@ -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,
});
3 changes: 3 additions & 0 deletions web/src/views/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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>();
Expand Down