credentials requriements surface in many places thorughout corso: they can be sourced from many locations (envs, files, manually), and used in many more (cli, repo, kopia). This usage could blossom into all kinds of duplicate structs sharing similar info. The goal of this change is to centralize where credentials are declared and managed, and how they then cascade out to other packages.
41 lines
878 B
Go
41 lines
878 B
Go
package storage
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/alcionai/corso/pkg/credentials"
|
|
)
|
|
|
|
type CommonConfig struct {
|
|
credentials.Corso // requires: CorsoPassword
|
|
}
|
|
|
|
// config key consts
|
|
const (
|
|
keyCommonCorsoPassword = "common_corsoPassword"
|
|
)
|
|
|
|
func (c CommonConfig) Config() (config, error) {
|
|
cfg := config{
|
|
keyCommonCorsoPassword: c.CorsoPassword,
|
|
}
|
|
return cfg, c.validate()
|
|
}
|
|
|
|
// CommonConfig retrieves the CommonConfig details from the Storage config.
|
|
func (s Storage) CommonConfig() (CommonConfig, error) {
|
|
c := CommonConfig{}
|
|
if len(s.Config) > 0 {
|
|
c.CorsoPassword = orEmptyString(s.Config[keyCommonCorsoPassword])
|
|
}
|
|
return c, c.validate()
|
|
}
|
|
|
|
// ensures all required properties are present
|
|
func (c CommonConfig) validate() error {
|
|
if len(c.CorsoPassword) == 0 {
|
|
return errors.Wrap(errMissingRequired, credentials.CORSO_PASSWORD)
|
|
}
|
|
return nil
|
|
}
|