Allow uploading secrets encoded with base64

This commit is contained in:
cuigh 2018-05-02 17:50:10 +08:00
parent da07ba60fc
commit 07d2c4bc3b
3 changed files with 13 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package docker
import ( import (
"context" "context"
"encoding/base64"
"sort" "sort"
"github.com/cuigh/swirl/misc" "github.com/cuigh/swirl/misc"
@ -39,7 +40,14 @@ func SecretCreate(info *model.ConfigCreateInfo) error {
return mgr.Do(func(ctx context.Context, cli *client.Client) (err error) { return mgr.Do(func(ctx context.Context, cli *client.Client) (err error) {
spec := swarm.SecretSpec{} spec := swarm.SecretSpec{}
spec.Name = info.Name spec.Name = info.Name
if info.Base64 {
spec.Data, err = base64.StdEncoding.DecodeString(info.Data)
if err != nil {
return
}
} else {
spec.Data = []byte(info.Data) spec.Data = []byte(info.Data)
}
spec.Labels = info.Labels.ToMap() spec.Labels = info.Labels.ToMap()
if info.Template.Name != "" { if info.Template.Name != "" {
spec.Templating = &swarm.Driver{ spec.Templating = &swarm.Driver{

View File

@ -563,6 +563,7 @@ type ConfigCreateInfo struct {
Data string `json:"data"` Data string `json:"data"`
Labels Options `json:"labels"` Labels Options `json:"labels"`
Template Driver `json:"template"` Template Driver `json:"template"`
Base64 bool `json:"base64"`
} }
type ConfigUpdateInfo struct { type ConfigUpdateInfo struct {

View File

@ -31,6 +31,9 @@
<textarea name="data" class="textarea" rows="12" placeholder="Secret file content" data-v-rule="native" required></textarea> <textarea name="data" class="textarea" rows="12" placeholder="Secret file content" data-v-rule="native" required></textarea>
</div> </div>
</div> </div>
<div class="field">
{{ yield switch(id="cb-base64", name="base64", label="Base64 encoded") }}
</div>
<div class="field"> <div class="field">
<label class="label">{{ i18n("field.label") }}</label> <label class="label">{{ i18n("field.label") }}</label>
{{ yield options(name="label") }} {{ yield options(name="label") }}