mirror of
https://github.com/minio/minio.git
synced 2025-11-09 05:34:56 -05:00
Enhance config restore to carry previous set content as well (#8483)
This PR brings support for `history` list to list in the following agreed format ``` ~ mc admin config history list -n 2 myminio RestoreId: df0ebb1e-69b0-4043-b9dd-ab54508f2897 Date: Mon, 04 Nov 2019 17:27:27 GMT region name="us-east-1" state="on" region name="us-east-1" state="on" region name="us-east-1" state="on" region name="us-east-1" state="on" RestoreId: ecc6873a-0ed3-41f9-b03e-a2a1bab48b5f Date: Mon, 04 Nov 2019 17:28:23 GMT region name=us-east-1 state=off ``` This PR also moves the help templating and coloring to fully `mc` side instead than `madmin` API.
This commit is contained in:
committed by
kannappanr
parent
26ed9e81b1
commit
1e457dda7e
@@ -23,6 +23,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/minio/minio/cmd/config"
|
||||
@@ -236,7 +237,7 @@ func (a adminAPIHandlers) ClearConfigHistoryKVHandler(w http.ResponseWriter, r *
|
||||
return
|
||||
}
|
||||
if restoreID == "all" {
|
||||
chEntries, err := listServerConfigHistory(ctx, objectAPI)
|
||||
chEntries, err := listServerConfigHistory(ctx, objectAPI, false, -1)
|
||||
if err != nil {
|
||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||
return
|
||||
@@ -323,7 +324,14 @@ func (a adminAPIHandlers) ListConfigHistoryKVHandler(w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
|
||||
chEntries, err := listServerConfigHistory(ctx, objectAPI)
|
||||
vars := mux.Vars(r)
|
||||
count, err := strconv.Atoi(vars["count"])
|
||||
if err != nil {
|
||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||
return
|
||||
}
|
||||
|
||||
chEntries, err := listServerConfigHistory(ctx, objectAPI, true, count)
|
||||
if err != nil {
|
||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||
return
|
||||
@@ -335,7 +343,14 @@ func (a adminAPIHandlers) ListConfigHistoryKVHandler(w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessResponseJSON(w, data)
|
||||
password := globalActiveCred.SecretKey
|
||||
econfigData, err := madmin.EncryptData(password, data)
|
||||
if err != nil {
|
||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessResponseJSON(w, econfigData)
|
||||
}
|
||||
|
||||
// HelpConfigKVHandler - GET /minio/admin/v2/help-config-kv?subSys={subSys}&key={key}
|
||||
|
||||
@@ -81,7 +81,7 @@ func registerAdminRouter(router *mux.Router, enableConfigOps, enableIAMOps bool)
|
||||
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix + "/set-config-kv").HandlerFunc(httpTraceHdrs(adminAPI.SetConfigKVHandler))
|
||||
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix + "/del-config-kv").HandlerFunc(httpTraceHdrs(adminAPI.DelConfigKVHandler))
|
||||
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/help-config-kv").HandlerFunc(httpTraceAll(adminAPI.HelpConfigKVHandler)).Queries("subSys", "{subSys:.*}", "key", "{key:.*}")
|
||||
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/list-config-history-kv").HandlerFunc(httpTraceAll(adminAPI.ListConfigHistoryKVHandler))
|
||||
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/list-config-history-kv").HandlerFunc(httpTraceAll(adminAPI.ListConfigHistoryKVHandler)).Queries("count", "{count:[0-9]+}")
|
||||
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix+"/clear-config-history-kv").HandlerFunc(httpTraceHdrs(adminAPI.ClearConfigHistoryKVHandler)).Queries("restoreId", "{restoreId:.*}")
|
||||
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/restore-config-history-kv").HandlerFunc(httpTraceHdrs(adminAPI.RestoreConfigHistoryKVHandler)).Queries("restoreId", "{restoreId:.*}")
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import (
|
||||
const (
|
||||
minioConfigPrefix = "config"
|
||||
|
||||
kvPrefix = ".kv"
|
||||
|
||||
// Captures all the previous SetKV operations and allows rollback.
|
||||
minioConfigHistoryPrefix = minioConfigPrefix + "/history"
|
||||
|
||||
@@ -44,7 +46,9 @@ const (
|
||||
minioConfigBackupFile = minioConfigFile + ".backup"
|
||||
)
|
||||
|
||||
func listServerConfigHistory(ctx context.Context, objAPI ObjectLayer) ([]madmin.ConfigHistoryEntry, error) {
|
||||
func listServerConfigHistory(ctx context.Context, objAPI ObjectLayer, withData bool, count int) (
|
||||
[]madmin.ConfigHistoryEntry, error) {
|
||||
|
||||
var configHistory []madmin.ConfigHistoryEntry
|
||||
|
||||
// List all kvs
|
||||
@@ -55,10 +59,28 @@ func listServerConfigHistory(ctx context.Context, objAPI ObjectLayer) ([]madmin.
|
||||
return nil, err
|
||||
}
|
||||
for _, obj := range res.Objects {
|
||||
configHistory = append(configHistory, madmin.ConfigHistoryEntry{
|
||||
RestoreID: path.Base(obj.Name),
|
||||
cfgEntry := madmin.ConfigHistoryEntry{
|
||||
RestoreID: strings.TrimSuffix(path.Base(obj.Name), kvPrefix),
|
||||
CreateTime: obj.ModTime, // ModTime is createTime for config history entries.
|
||||
})
|
||||
}
|
||||
if withData {
|
||||
data, err := readConfig(ctx, objAPI, obj.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if globalConfigEncrypted {
|
||||
data, err = madmin.DecryptData(globalActiveCred.String(), bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
cfgEntry.Data = string(data)
|
||||
}
|
||||
configHistory = append(configHistory, cfgEntry)
|
||||
count--
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !res.IsTruncated {
|
||||
// We are done here
|
||||
@@ -73,12 +95,12 @@ func listServerConfigHistory(ctx context.Context, objAPI ObjectLayer) ([]madmin.
|
||||
}
|
||||
|
||||
func delServerConfigHistory(ctx context.Context, objAPI ObjectLayer, uuidKV string) error {
|
||||
historyFile := pathJoin(minioConfigHistoryPrefix, uuidKV)
|
||||
historyFile := pathJoin(minioConfigHistoryPrefix, uuidKV+kvPrefix)
|
||||
return objAPI.DeleteObject(ctx, minioMetaBucket, historyFile)
|
||||
}
|
||||
|
||||
func readServerConfigHistory(ctx context.Context, objAPI ObjectLayer, uuidKV string) ([]byte, error) {
|
||||
historyFile := pathJoin(minioConfigHistoryPrefix, uuidKV)
|
||||
historyFile := pathJoin(minioConfigHistoryPrefix, uuidKV+kvPrefix)
|
||||
data, err := readConfig(ctx, objAPI, historyFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -92,7 +114,7 @@ func readServerConfigHistory(ctx context.Context, objAPI ObjectLayer, uuidKV str
|
||||
}
|
||||
|
||||
func saveServerConfigHistory(ctx context.Context, objAPI ObjectLayer, kv []byte) error {
|
||||
uuidKV := mustGetUUID() + ".kv"
|
||||
uuidKV := mustGetUUID() + kvPrefix
|
||||
historyFile := pathJoin(minioConfigHistoryPrefix, uuidKV)
|
||||
|
||||
var err error
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/minio/minio-go/pkg/set"
|
||||
"github.com/minio/minio/pkg/auth"
|
||||
"github.com/minio/minio/pkg/env"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
// Error config error type
|
||||
@@ -41,7 +42,7 @@ func (e Error) Error() string {
|
||||
|
||||
// Default keys
|
||||
const (
|
||||
Default = `_`
|
||||
Default = madmin.Default
|
||||
State = "state"
|
||||
Comment = "comment"
|
||||
|
||||
@@ -133,13 +134,13 @@ var SubSystemsSingleTargets = set.CreateStringSet([]string{
|
||||
|
||||
// Constant separators
|
||||
const (
|
||||
SubSystemSeparator = `:`
|
||||
KvSeparator = `=`
|
||||
KvSpaceSeparator = ` `
|
||||
KvComment = `#`
|
||||
KvNewline = "\n"
|
||||
KvDoubleQuote = `"`
|
||||
KvSingleQuote = `'`
|
||||
SubSystemSeparator = madmin.SubSystemSeparator
|
||||
KvSeparator = madmin.KvSeparator
|
||||
KvSpaceSeparator = madmin.KvSpaceSeparator
|
||||
KvComment = madmin.KvComment
|
||||
KvNewline = madmin.KvNewline
|
||||
KvDoubleQuote = madmin.KvDoubleQuote
|
||||
KvSingleQuote = madmin.KvSingleQuote
|
||||
|
||||
// Env prefix used for all envs in MinIO
|
||||
EnvPrefix = "MINIO_"
|
||||
|
||||
Reference in New Issue
Block a user