From 165c8d372d8e2fefd7c7f5d2617df79bc05f5023 Mon Sep 17 00:00:00 2001 From: Alex Aizman Date: Fri, 20 Dec 2024 18:21:06 -0500 Subject: [PATCH] [API change] reload (updated) backend creds * part three, prev. commit: 867157b84b6cc Signed-off-by: Alex Aizman --- ais/prxclu.go | 13 +++++++++++++ ais/target.go | 4 ++++ ais/tgtcp.go | 28 ++++++++++++++++++++++++++-- cmn/err.go | 8 ++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/ais/prxclu.go b/ais/prxclu.go index 6cdbdb2d2f..991213dc61 100644 --- a/ais/prxclu.go +++ b/ais/prxclu.go @@ -1053,6 +1053,19 @@ func (p *proxy) cluputMsg(w http.ResponseWriter, r *http.Request) { p.xstop(w, r, msg) case apc.ActReloadBackendCreds: + if msg.Name != "" { + normp := apc.NormalizeProvider(msg.Name) + if !apc.IsCloudProvider(normp) { + p.writeErrf(w, r, "cannot reload %q creds: not a Cloud provider", msg.Name) + return + } + config := cmn.GCO.Get() + if config.Backend.Get(normp) == nil { + p.writeErr(w, r, &cmn.ErrMissingBackend{Provider: msg.Name}) + return + } + msg.Name = normp + } p.reloadCreds(w, r, msg) // internal diff --git a/ais/target.go b/ais/target.go index 362db00233..e77a3e1ede 100644 --- a/ais/target.go +++ b/ais/target.go @@ -154,6 +154,10 @@ func (t *target) initBuiltTagged(tstats *stats.Trunner, config *cmn.Config) erro case err == nil && !configured: disabled = append(disabled, provider) case err != nil && configured: + if !cmn.IsErrInitMissingBackend(err) { + // as is + return fmt.Errorf("%s: failed to initialize [%s] backend, err: %v", t, provider, err) + } notlinked = append(notlinked, provider) case err != nil && !configured: _, ok := err.(*cmn.ErrInitBackend) // error type to indicate a _mock_ backend diff --git a/ais/tgtcp.go b/ais/tgtcp.go index d2e47aec45..7307b5a137 100644 --- a/ais/tgtcp.go +++ b/ais/tgtcp.go @@ -183,10 +183,34 @@ func (t *target) daeputMsg(w http.ResponseWriter, r *http.Request) { errorsOnly := msg.Value.(bool) t.statsT.ResetStats(errorsOnly) case apc.ActReloadBackendCreds: - debug.Assert(msg.Name == "", "reloading specific provider not yet supported") - if err := t.initBuiltTagged(t.statsT.(*stats.Trunner), cmn.GCO.Get()); err != nil { + var ( + tstats = t.statsT.(*stats.Trunner) + provider = msg.Name + ) + if provider == "" { // all + if err := t.initBuiltTagged(t.statsT.(*stats.Trunner), cmn.GCO.Get()); err != nil { + t.writeErr(w, r, err) + } + return + } + + // one + var add core.Backend + switch provider { + case apc.AWS: + add, err = backend.NewAWS(t, tstats) + case apc.GCP: + add, err = backend.NewGCP(t, tstats) + case apc.Azure: + add, err = backend.NewAzure(t, tstats) + case apc.OCI: + add, err = backend.NewOCI(t, tstats) + } + if err != nil { t.writeErr(w, r, err) + return } + t.backend[provider] = add case apc.ActStartMaintenance: if !t.ensureIntraControl(w, r, true /* from primary */) { return diff --git a/cmn/err.go b/cmn/err.go index 9a2af6ce92..cc833b6c84 100644 --- a/cmn/err.go +++ b/cmn/err.go @@ -739,6 +739,14 @@ func (e *ErrMissingBackend) Error() string { return apc.DisplayProvider(e.Provider) + " backend is missing in the cluster configuration" } +func IsErrInitMissingBackend(err error) bool { + _, ok := err.(*ErrInitBackend) + if !ok { + _, ok = err.(*ErrMissingBackend) + } + return ok +} + // ErrETL func NewErrETL(ctx *ETLErrCtx, msg string) *ErrETL {