add private mode for units
This commit is contained in:
parent
fdaa0e8650
commit
2f943c6242
@ -19,3 +19,4 @@ Ie: how long to let command react on SIGTERM signal.
|
|||||||
* `workdir` (optional, string) - working directory for the worker. if empty - temporary one will be generated automatically.
|
* `workdir` (optional, string) - working directory for the worker. if empty - temporary one will be generated automatically.
|
||||||
* `authorization` (optional, [Authorization](authorization.md)) - request authorization
|
* `authorization` (optional, [Authorization](authorization.md)) - request authorization
|
||||||
* `cron` (optional,[Cron](cron.md)) - scheduled requests
|
* `cron` (optional,[Cron](cron.md)) - scheduled requests
|
||||||
|
* `private` (optional, bool) - do not expose over API, could be used for cron-only jobs
|
File diff suppressed because one or more lines are too long
@ -27,6 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Unit struct {
|
type Unit struct {
|
||||||
|
Private bool `yaml:"private,omitempty"` // private unit - do not expose over API, could useful for cron-only tasks
|
||||||
Interval time.Duration `yaml:"interval,omitempty"` // interval between attempts
|
Interval time.Duration `yaml:"interval,omitempty"` // interval between attempts
|
||||||
Attempts int `yaml:"attempts,omitempty"` // maximum number of attempts
|
Attempts int `yaml:"attempts,omitempty"` // maximum number of attempts
|
||||||
Workers int `yaml:"workers,omitempty"` // concurrency level - number of parallel requests
|
Workers int `yaml:"workers,omitempty"` // concurrency level - number of parallel requests
|
||||||
@ -192,9 +193,13 @@ func Handler(units []Unit, workers []*worker.Worker) http.Handler {
|
|||||||
|
|
||||||
func Attach(router gin.IRouter, units []Unit, workers []*worker.Worker) {
|
func Attach(router gin.IRouter, units []Unit, workers []*worker.Worker) {
|
||||||
for i, unit := range units {
|
for i, unit := range units {
|
||||||
|
if !unit.Private {
|
||||||
group := router.Group(unit.Path())
|
group := router.Group(unit.Path())
|
||||||
group.Use(unit.enableAuthorization())
|
group.Use(unit.enableAuthorization())
|
||||||
api.Expose(group, workers[i])
|
api.Expose(group, workers[i])
|
||||||
|
} else {
|
||||||
|
log.Println("do not expose unit", unit.Name(), "because it's private")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,10 +34,19 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">Unit {{.Unit.Name}}</h5>
|
<h5 class="card-title">
|
||||||
|
{{if .Unit.Private}}<span title="not exposed over API">🏠</span>
|
||||||
|
{{else if .Unit.Secured}}<span title="with authorization">🛡️</span>
|
||||||
|
{{end}}
|
||||||
|
{{.Unit.Name}}
|
||||||
|
</h5>
|
||||||
<h6 class="card-subtitle mb-2 text-muted">Configuration</h6>
|
<h6 class="card-subtitle mb-2 text-muted">Configuration</h6>
|
||||||
<div class="card-text">
|
<div class="card-text">
|
||||||
<dl class="row">
|
<dl class="row">
|
||||||
|
{{- if .Unit.Private}}
|
||||||
|
<dt class="col-sm-3">Private</dt>
|
||||||
|
<dd class="col-sm-9"><b>yes</b><i> - not exposed over API</i></dd>
|
||||||
|
{{- else}}
|
||||||
<dt class="col-sm-3">API endpoint</dt>
|
<dt class="col-sm-3">API endpoint</dt>
|
||||||
<dd class="col-sm-9">
|
<dd class="col-sm-9">
|
||||||
<code>
|
<code>
|
||||||
@ -45,6 +54,7 @@
|
|||||||
<script>document.write((new URL("../../../api/{{.Unit.Name}}/", window.location).href))</script>
|
<script>document.write((new URL("../../../api/{{.Unit.Name}}/", window.location).href))</script>
|
||||||
</code>
|
</code>
|
||||||
</dd>
|
</dd>
|
||||||
|
{{- end}}
|
||||||
<dt class="col-sm-3">Mode</dt>
|
<dt class="col-sm-3">Mode</dt>
|
||||||
<dd class="col-sm-9">{{.Unit.Mode}}</dd>
|
<dd class="col-sm-9">{{.Unit.Mode}}</dd>
|
||||||
<dt class="col-sm-3">Concurrency</dt>
|
<dt class="col-sm-3">Concurrency</dt>
|
||||||
|
@ -49,8 +49,10 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{{range .Units}}
|
{{range .Units}}
|
||||||
<tr>
|
<tr>
|
||||||
<td title="secured">
|
<td>
|
||||||
{{if .Secured}}🛡️{{end}}
|
{{if .Private}}<span title="not exposed over API">🏠</span>
|
||||||
|
{{else if .Secured}}<span title="with authorization">🛡️</span>
|
||||||
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{.Name}}/">{{.Name}}</a>
|
<a href="{{.Name}}/">{{.Name}}</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user