-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add repositoryServerUserHostname to the kopia repository based functions #2177
Changes from all commits
384a075
81b4ed3
dd0ba4b
0a37b2b
97cc57b
2179439
a3babd4
e5d1d56
716e5fd
5c397a6
9d3701b
8cdc03b
9d68115
b7e381a
c502748
6821550
345c4a5
79bd293
a57695c
ced0ba7
07f5c23
31cbaef
be2460d
4bc81bd
5fb1bd0
92344ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,4 @@ Workflow | |
webhook | ||
Kopia | ||
kopia | ||
hostname |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -38,6 +38,8 @@ const ( | |||||
BackupDataUsingKopiaServerFuncName = "BackupDataUsingKopiaServer" | ||||||
// BackupDataUsingKopiaServerSnapshotTagsArg is the key used for returning snapshot tags | ||||||
BackupDataUsingKopiaServerSnapshotTagsArg = "snapshotTags" | ||||||
// KopiaRepositoryServerUserHostname is the key used for returning the hostname of the user | ||||||
KopiaRepositoryServerUserHostname = "repositoryServerUserHostname" | ||||||
) | ||||||
|
||||||
type backupDataUsingKopiaServerFunc struct{} | ||||||
|
@@ -71,17 +73,19 @@ func (*backupDataUsingKopiaServerFunc) Arguments() []string { | |||||
BackupDataNamespaceArg, | ||||||
BackupDataPodArg, | ||||||
BackupDataUsingKopiaServerSnapshotTagsArg, | ||||||
KopiaRepositoryServerUserHostname, | ||||||
} | ||||||
} | ||||||
|
||||||
func (*backupDataUsingKopiaServerFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]any) (map[string]any, error) { | ||||||
var ( | ||||||
container string | ||||||
err error | ||||||
includePath string | ||||||
namespace string | ||||||
pod string | ||||||
tagsStr string | ||||||
container string | ||||||
err error | ||||||
includePath string | ||||||
namespace string | ||||||
pod string | ||||||
tagsStr string | ||||||
userHostname string | ||||||
) | ||||||
if err = Arg(args, BackupDataContainerArg, &container); err != nil { | ||||||
return nil, err | ||||||
|
@@ -98,6 +102,9 @@ func (*backupDataUsingKopiaServerFunc) Exec(ctx context.Context, tp param.Templa | |||||
if err = OptArg(args, BackupDataUsingKopiaServerSnapshotTagsArg, &tagsStr, ""); err != nil { | ||||||
return nil, err | ||||||
} | ||||||
if err = OptArg(args, KopiaRepositoryServerUserHostname, &userHostname, ""); err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
var tags []string = nil | ||||||
if tagsStr != "" { | ||||||
|
@@ -114,8 +121,7 @@ func (*backupDataUsingKopiaServerFunc) Exec(ctx context.Context, tp param.Templa | |||||
return nil, errors.Wrap(err, "Failed to fetch Kopia API Server Certificate Secret Data from Certificate") | ||||||
} | ||||||
|
||||||
username := tp.RepositoryServer.Username | ||||||
hostname, userAccessPassphrase, err := hostNameAndUserPassPhraseFromRepoServer(userPassphrase) | ||||||
hostname, userAccessPassphrase, err := hostNameAndUserPassPhraseFromRepoServer(userPassphrase, userHostname) | ||||||
if err != nil { | ||||||
return nil, errors.Wrap(err, "Failed to fetch Hostname/User Passphrase from Secret") | ||||||
} | ||||||
|
@@ -134,7 +140,7 @@ func (*backupDataUsingKopiaServerFunc) Exec(ctx context.Context, tp param.Templa | |||||
pod, | ||||||
tp.RepositoryServer.Address, | ||||||
fingerprint, | ||||||
username, | ||||||
tp.RepositoryServer.Username, | ||||||
userAccessPassphrase, | ||||||
tags, | ||||||
) | ||||||
|
@@ -223,24 +229,36 @@ func backupDataUsingKopiaServer( | |||||
return kopiacmd.ParseSnapshotCreateOutput(stdout, stderr) | ||||||
} | ||||||
|
||||||
func hostNameAndUserPassPhraseFromRepoServer(userCreds string) (string, string, error) { | ||||||
func hostNameAndUserPassPhraseFromRepoServer(userCreds, hostname string) (string, string, error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, seems good. Will make the changes ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done ! |
||||||
var userAccessMap map[string]string | ||||||
if err := json.Unmarshal([]byte(userCreds), &userAccessMap); err != nil { | ||||||
return "", "", errors.Wrap(err, "Failed to unmarshal User Credentials Data") | ||||||
} | ||||||
|
||||||
var userPassPhrase string | ||||||
var hostName string | ||||||
// Check if hostname provided exists in the User Access Map | ||||||
if hostname != "" { | ||||||
err := checkHostnameExistsInUserAccessMap(userAccessMap, hostname) | ||||||
if err != nil { | ||||||
return "", "", errors.Wrap(err, "Failed to find hostname in the User Access Map") | ||||||
} | ||||||
} | ||||||
|
||||||
// Set First Value of hostname and passphrase from the User Access Map | ||||||
// Or if hostname provided by the user, set the hostname and password for hostname provided | ||||||
var userPassphrase string | ||||||
for key, val := range userAccessMap { | ||||||
hostName = key | ||||||
userPassPhrase = val | ||||||
if hostname == "" || hostname == key { | ||||||
hostname = key | ||||||
userPassphrase = val | ||||||
break | ||||||
} | ||||||
} | ||||||
|
||||||
decodedUserPassPhrase, err := base64.StdEncoding.DecodeString(userPassPhrase) | ||||||
decodedUserPassphrase, err := base64.StdEncoding.DecodeString(userPassphrase) | ||||||
if err != nil { | ||||||
return "", "", errors.Wrap(err, "Failed to Decode User Passphrase") | ||||||
} | ||||||
return hostName, string(decodedUserPassPhrase), nil | ||||||
return hostname, string(decodedUserPassphrase), nil | ||||||
} | ||||||
|
||||||
func userCredentialsAndServerTLS(tp *param.TemplateParams) (string, string, error) { | ||||||
|
@@ -254,3 +272,11 @@ func userCredentialsAndServerTLS(tp *param.TemplateParams) (string, string, erro | |||||
} | ||||||
return string(userCredJSON), string(certJSON), nil | ||||||
} | ||||||
|
||||||
func checkHostnameExistsInUserAccessMap(userAccessMap map[string]string, hostname string) error { | ||||||
// check if hostname that is provided by the user exists in the user access map | ||||||
if _, ok := userAccessMap[hostname]; !ok { | ||||||
return errors.New("hostname provided in the repository server CR does not exist in the user access map") | ||||||
} | ||||||
return nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does second sentence mean, user should figure out the hostname by looking at the user access credential secret?
What does it mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ! User could provide the hostname which he/she wants to use by looking at user access credentials secret. If it's not provided we'll get the last entry from the user access map which is present inside the secret by default.