mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
refactor: added check for secretID in secrets store
This commit is contained in:
parent
67e2d40606
commit
c88a29be00
1 changed files with 18 additions and 9 deletions
27
cmd/crawl.go
27
cmd/crawl.go
|
|
@ -37,28 +37,37 @@ var CrawlCmd = &cobra.Command{
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
var (
|
||||||
|
uri = args[0]
|
||||||
|
store secrets.SecretStore
|
||||||
|
err error
|
||||||
|
)
|
||||||
// try and load credentials from local store first
|
// try and load credentials from local store first
|
||||||
store, err := secrets.OpenStore(secretsFile)
|
store, err = secrets.OpenStore(secretsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to open store")
|
log.Warn().Err(err).Msg("failed to open local store...falling back to default provided arguments")
|
||||||
// try and use the `username` and `password` arguments instead
|
// try and use the `username` and `password` arguments instead
|
||||||
store = &secrets.StaticStore{
|
store = secrets.NewStaticStore(username, password)
|
||||||
Username: username,
|
|
||||||
Password: password,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// found the store so try to load the creds
|
||||||
|
_, err = store.GetSecretByID(uri)
|
||||||
|
if err != nil {
|
||||||
|
store = secrets.NewStaticStore(username, password)
|
||||||
|
}
|
||||||
|
|
||||||
systems, err := crawler.CrawlBMCForSystems(crawler.CrawlerConfig{
|
systems, err := crawler.CrawlBMCForSystems(crawler.CrawlerConfig{
|
||||||
URI: args[0],
|
URI: uri,
|
||||||
CredentialStore: store,
|
CredentialStore: store,
|
||||||
Insecure: insecure,
|
Insecure: insecure,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("error crawling BMC")
|
log.Error().Err(err).Msg("failed to crawl BMC")
|
||||||
}
|
}
|
||||||
// Marshal the inventory details to JSON
|
// Marshal the inventory details to JSON
|
||||||
jsonData, err := json.MarshalIndent(systems, "", " ")
|
jsonData, err := json.MarshalIndent(systems, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("error marshalling to JSON:")
|
log.Error().Err(err).Msg("failed to marshal JSON")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue