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.
|
||||
* `authorization` (optional, [Authorization](authorization.md)) - request authorization
|
||||
* `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 {
|
||||
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
|
||||
Attempts int `yaml:"attempts,omitempty"` // maximum number of attempts
|
||||
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) {
|
||||
for i, unit := range units {
|
||||
group := router.Group(unit.Path())
|
||||
group.Use(unit.enableAuthorization())
|
||||
api.Expose(group, workers[i])
|
||||
if !unit.Private {
|
||||
group := router.Group(unit.Path())
|
||||
group.Use(unit.enableAuthorization())
|
||||
api.Expose(group, workers[i])
|
||||
} else {
|
||||
log.Println("do not expose unit", unit.Name(), "because it's private")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,17 +34,27 @@
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<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>
|
||||
<div class="card-text">
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">API endpoint</dt>
|
||||
<dd class="col-sm-9">
|
||||
<code>
|
||||
<noscript>JS required to detect API url</noscript>
|
||||
<script>document.write((new URL("../../../api/{{.Unit.Name}}/", window.location).href))</script>
|
||||
</code>
|
||||
</dd>
|
||||
{{- 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>
|
||||
<dd class="col-sm-9">
|
||||
<code>
|
||||
<noscript>JS required to detect API url</noscript>
|
||||
<script>document.write((new URL("../../../api/{{.Unit.Name}}/", window.location).href))</script>
|
||||
</code>
|
||||
</dd>
|
||||
{{- end}}
|
||||
<dt class="col-sm-3">Mode</dt>
|
||||
<dd class="col-sm-9">{{.Unit.Mode}}</dd>
|
||||
<dt class="col-sm-3">Concurrency</dt>
|
||||
@ -166,43 +176,43 @@
|
||||
</div>
|
||||
</div>
|
||||
{{with .CronEntries}}
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<form method="post">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Schedules</h5>
|
||||
<div class="card-text">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-borderless table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Spec</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $index, $entry := .}}
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<form method="post">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Schedules</h5>
|
||||
<div class="card-text">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-borderless table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="cron/{{$index}}">{{$entry.Spec.Label (print "#" $index)}}</a>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{$entry.Spec.Spec}}</code>
|
||||
</td>
|
||||
<th>Name</th>
|
||||
<th>Spec</th>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $index, $entry := .}}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="cron/{{$index}}">{{$entry.Spec.Label (print "#" $index)}}</a>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{$entry.Spec.Spec}}</code>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
<br/>
|
||||
<div class="row">
|
||||
|
@ -49,8 +49,10 @@
|
||||
<tbody>
|
||||
{{range .Units}}
|
||||
<tr>
|
||||
<td title="secured">
|
||||
{{if .Secured}}🛡️{{end}}
|
||||
<td>
|
||||
{{if .Private}}<span title="not exposed over API">🏠</span>
|
||||
{{else if .Secured}}<span title="with authorization">🛡️</span>
|
||||
{{end}}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{.Name}}/">{{.Name}}</a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user