Skip to content

Commit

Permalink
Changed to not write the default creds when there are already creds (#34
Browse files Browse the repository at this point in the history
)

CASMHMS-6129
  • Loading branch information
shunr-hpe committed Feb 13, 2024
1 parent a94b634 commit 8e47d39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.15.0
1.16.0
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.16.0] - 2024-02-07

### Changed
- Changed to not write the default credentials when there are already credentials in vault.

## [1.15.0] - 2023-09-25

### Added
Expand Down
41 changes: 27 additions & 14 deletions cmd/hms_discovery/river.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// (C) Copyright [2020-2022] Hewlett Packard Enterprise Development LP
// (C) Copyright [2020-2022,2024] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -242,22 +242,35 @@ func doRiverDiscovery() {
}
}

// Put the creds in Vault.
compCred := compcredentials.CompCredentials{
Xname: xname,
Username: defaultCredentials["Cray"].Username,
Password: defaultCredentials["Cray"].Password,
}
compCredErr := hsmCredentialStore.StoreCompCred(compCred)
if compCredErr != nil {
logger.Fatal("Failed to store BMC credentials!",
zap.Error(compCredErr),
creds, credsErr := hsmCredentialStore.GetCompCred(xname)
if credsErr != nil {
logger.Info("Using the default creds, because there was a failure reading the creds from vault",
zap.String("xname", xname),
)
zap.Error(credsErr))
}

failedXnames = append(failedXnames, xname)
if (creds.Xname == "" && creds.Username == "") || credsErr != nil {
// Put the creds in Vault.
compCred := compcredentials.CompCredentials{
Xname: xname,
Username: defaultCredentials["Cray"].Username,
Password: defaultCredentials["Cray"].Password,
}
compCredErr := hsmCredentialStore.StoreCompCred(compCred)
if compCredErr != nil {
logger.Fatal("Failed to store BMC credentials!",
zap.Error(compCredErr),
zap.String("xname", xname),
)

break
failedXnames = append(failedXnames, xname)

break
}
} else {
logger.Info("Not writing default creds, because existing creds were found in vault.",
zap.String("xname", xname),
zap.String("username", creds.Username))
}

// From here on we know the xname is reachable and Redfish is responsive.
Expand Down

0 comments on commit 8e47d39

Please sign in to comment.