-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from MaciejMis/integration-new-config-file
Integration with ODIM's services part #2
- Loading branch information
Showing
7 changed files
with
153 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/google/uuid" | ||
"github.com/sirupsen/logrus" | ||
"gopkg.in/yaml.v3" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
// Config struct holds configuration of Device Manager | ||
type Config struct { | ||
Host string `yaml:"Host"` | ||
Port string `yaml:"Port"` | ||
UserName string `yaml:"UserName"` | ||
Password string `yaml:"Password"` | ||
RootServiceUUID string `yaml:"RootServiceUUID"` | ||
TLSConf *TLSConf `yaml:"TLSConf"` | ||
PKIRootCAPath string `yaml:"PKIRootCACertificatePath"` | ||
PKIPrivateKeyPath string `yaml:"PKIPrivateKeyPath"` | ||
PKICertificatePath string `yaml:"PKICertificatePath"` | ||
PKIRootCA []byte | ||
PKIPrivateKey []byte | ||
PKICertificate []byte | ||
} | ||
|
||
// TLSConf holds TLS configuration | ||
type TLSConf struct { | ||
MinVersion uint16 `yaml:"MinVersion"` | ||
MaxVersion uint16 `yaml:"MaxVersion"` | ||
} | ||
|
||
// LoadConfiguration loads Device Manager configuration from env path variable DM_CONFIG_FILE_PATH | ||
func LoadConfiguration() (*Config, error) { | ||
config := new(Config) | ||
|
||
if configPath := os.Getenv("DM_CONFIG_FILE_PATH"); configPath != "" { | ||
if configData, err := ioutil.ReadFile(configPath); err == nil { | ||
_ = yaml.Unmarshal(configData, config) | ||
} else { | ||
logrus.Fatalf("cannot load configuration file: %s", err) | ||
} | ||
} else { | ||
logrus.Fatal("missing DM_CONFIG_FILE_PATH env") | ||
} | ||
|
||
if err := loadCerts(config); err != nil { | ||
return config, err | ||
} | ||
|
||
return config, validateConfig(config) | ||
} | ||
|
||
func loadCerts(config *Config) error { | ||
var err error | ||
if config.PKICertificate, err = ioutil.ReadFile(config.PKICertificatePath); err != nil { | ||
return fmt.Errorf("value check failed for CertificatePath:%s with %v", config.PKICertificatePath, err) | ||
} | ||
if config.PKIPrivateKey, err = ioutil.ReadFile(config.PKIPrivateKeyPath); err != nil { | ||
return fmt.Errorf("value check failed for PrivateKeyPath:%s with %v", config.PKIPrivateKeyPath, err) | ||
} | ||
if config.PKIRootCA, err = ioutil.ReadFile(config.PKIRootCAPath); err != nil { | ||
return fmt.Errorf("value check failed for RootCACertificatePath:%s with %v", config.PKIRootCAPath, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateConfig(config *Config) error { | ||
if config.Host == "" { | ||
return fmt.Errorf("missing value for Host") | ||
} | ||
|
||
if config.Port == "" { | ||
return fmt.Errorf("missing value for Port") | ||
} | ||
|
||
if config.UserName == "" { | ||
return fmt.Errorf("missing value for Username") | ||
} | ||
|
||
if config.Password == "" { | ||
return fmt.Errorf("missing value for Password") | ||
} | ||
|
||
if config.RootServiceUUID == "" { | ||
return fmt.Errorf("missing value for RootServiceUUID") | ||
} else if _, err := uuid.Parse(config.RootServiceUUID); err != nil { | ||
return err | ||
} | ||
|
||
if config.TLSConf == nil { | ||
return fmt.Errorf("missing TLSConf, setting default value") | ||
} | ||
|
||
if config.TLSConf.MinVersion == 0 || config.TLSConf.MinVersion == 0x0301 || config.TLSConf.MinVersion == 0x0302 { | ||
return fmt.Errorf("configured TLSConf.MinVersion is wrong") | ||
} | ||
if config.TLSConf.MaxVersion == 0 || config.TLSConf.MaxVersion == 0x0301 || config.TLSConf.MaxVersion == 0x0302 { | ||
return fmt.Errorf("configured TLSConf.MaxVersion is wrong") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
### Device Manager configuration file | ||
Host: odimra.local | ||
Port: 45003 | ||
|
||
PKIRootCACertificatePath: "/etc/plugincert/rootCA.crt" | ||
PKIPrivateKeyPath: "/etc/plugincert/odimra_server.key" | ||
PKICertificatePath: "/etc/plugincert/odimra_server.crt" | ||
|
||
TLSConf: | ||
### Supported TLS versions: | ||
# VersionTLS12 = 0x0303 | ||
# VersionTLS13 = 0x0304 | ||
MinVersion: 0x0303 | ||
MaxVersion: 0x0303 | ||
|
||
### Basic Authentication | ||
UserName: admin | ||
Password: O01bKrP7Tzs7YoO3YvQt4pRa2J_R6HI34ZfP4MxbqNIYAVQVt2ewGXmhjvBfzMifM7bHFccXKGmdHvj3hY44Hw== | ||
|
||
### Redfish service root UUID for Device Manager | ||
RootServiceUUID: 99999999-9999-9999-9999-999999999999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters