Skip to content

Commit 20c0eda

Browse files
authored
[cherry-pick] Use BasicAuth Keys for reading credentials from secret (#543) (#548)
Signed-off-by: Emruz Hossain <emruz@appscode.com>
1 parent a567dc8 commit 20c0eda

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

Dockerfile.dbg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ LABEL org.opencontainers.image.source https://github.com/stashed/elasticsearch
3535
RUN set -x \
3636
&& apk add --update --no-cache bash ca-certificates curl
3737

38-
RUN npm config set unsafe-perm true \
39-
&& npm install elasticdump@4.1.2 -g
38+
RUN npm install elasticdump@6.62.1 -g
4039

4140
COPY --from=0 restic /bin/restic
4241
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}

Dockerfile.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ LABEL org.opencontainers.image.source https://github.com/stashed/elasticsearch
3535
RUN set -x \
3636
&& apk add --update --no-cache bash ca-certificates curl
3737

38-
RUN npm config set unsafe-perm true \
39-
&& npm install elasticdump@4.1.2 -g
38+
RUN npm install elasticdump@6.62.1 -g
4039

4140
COPY --from=0 /restic /bin/restic
4241
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/spf13/cobra v1.1.1
99
go.bytebuilders.dev/license-verifier/kubernetes v0.5.1
1010
gomodules.xyz/x v0.0.0-20201105065653-91c568df6331
11+
k8s.io/api v0.18.9
1112
k8s.io/apimachinery v0.18.9
1213
k8s.io/client-go v0.18.9
1314
kmodules.xyz/client-go v0.0.0-20210108092221-c3812eb92bd0

pkg/backup.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ import (
3535
license "go.bytebuilders.dev/license-verifier/kubernetes"
3636
"gomodules.xyz/x/flags"
3737
"gomodules.xyz/x/log"
38+
core "k8s.io/api/core/v1"
3839
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3940
"k8s.io/client-go/kubernetes"
4041
"k8s.io/client-go/tools/clientcmd"
42+
meta_util "kmodules.xyz/client-go/meta"
4143
appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
4244
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
4345
v1 "kmodules.xyz/offshoot-api/api/v1"
@@ -215,7 +217,13 @@ func (opt *esOptions) backupElasticsearch(targetRef api_v1beta1.TargetRef) (*res
215217
}
216218

217219
appSVC := appBinding.Spec.ClientConfig.Service
218-
esURL := fmt.Sprintf("%v://%s:%s@%s:%d", appSVC.Scheme, appBindingSecret.Data[ESUser], appBindingSecret.Data[ESPassword], appSVC.Name, appSVC.Port) // TODO: authplugin: none
220+
esURL := fmt.Sprintf("%v://%s:%s@%s:%d",
221+
appSVC.Scheme,
222+
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthUsernameKey, ESUser)),
223+
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthPasswordKey, ESPassword)),
224+
appSVC.Name,
225+
appSVC.Port,
226+
) // TODO: support backup without authentication
219227

220228
// wait for DB ready
221229
waitForDBReady(appBinding.Spec.ClientConfig.Service.Name, appBinding.Spec.ClientConfig.Service.Port, opt.waitTimeout)

pkg/restore.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ import (
3232
license "go.bytebuilders.dev/license-verifier/kubernetes"
3333
"gomodules.xyz/x/flags"
3434
"gomodules.xyz/x/log"
35+
core "k8s.io/api/core/v1"
3536
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3637
"k8s.io/client-go/kubernetes"
3738
"k8s.io/client-go/tools/clientcmd"
39+
meta_util "kmodules.xyz/client-go/meta"
3840
appcatalog "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
3941
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
4042
v1 "kmodules.xyz/offshoot-api/api/v1"
@@ -182,7 +184,13 @@ func (opt *esOptions) restoreElasticsearch(targetRef api_v1beta1.TargetRef) (*re
182184
}
183185

184186
appSVC := appBinding.Spec.ClientConfig.Service
185-
esURL := fmt.Sprintf("%v://%s:%s@%s:%d", appSVC.Scheme, appBindingSecret.Data[ESUser], appBindingSecret.Data[ESPassword], appSVC.Name, appSVC.Port) // TODO: support for authplugin: none
187+
esURL := fmt.Sprintf("%v://%s:%s@%s:%d",
188+
appSVC.Scheme,
189+
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthUsernameKey, ESUser)),
190+
must(meta_util.GetBytesForKeys(appBindingSecret.Data, core.BasicAuthPasswordKey, ESPassword)),
191+
appSVC.Name,
192+
appSVC.Port,
193+
) // TODO: support backup without authentication
186194

187195
// wait for DB ready
188196
waitForDBReady(appBinding.Spec.ClientConfig.Service.Name, appBinding.Spec.ClientConfig.Service.Port, opt.waitTimeout)

pkg/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ func clearDir(dir string) error {
7272
}
7373
return os.MkdirAll(dir, os.ModePerm)
7474
}
75+
76+
func must(v []byte, err error) string {
77+
if err != nil {
78+
panic(err)
79+
}
80+
return string(v)
81+
}

0 commit comments

Comments
 (0)