v1.3.0
This commit is contained in:
@@ -1,39 +1,95 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Configuration for creating request to platform
|
||||
type Config struct {
|
||||
// JWT platform token
|
||||
// Required: false
|
||||
// Example: "qwqwdfwv68979we0q9bfv7e9sbvd89798qrwv97ff"
|
||||
Token string
|
||||
Token string `json:"token" yaml:"token"`
|
||||
|
||||
// Application (client) identifier for authorization
|
||||
// in the cloud platform controller in oauth2 mode.
|
||||
// Required: true
|
||||
// Example: "ewqfrvea7s890avw804389qwguf234h0otfi3w4eiu"
|
||||
AppID string
|
||||
AppID string `json:"appId" yaml:"appId" validate:"required"`
|
||||
|
||||
// Application (client) secret code for authorization
|
||||
// in the cloud platform controller in oauth2 mode.
|
||||
// Example: "frvet09rvesfis0c9erv9fsov0vsdfi09ovds0f"
|
||||
AppSecret string
|
||||
AppSecret string `json:"appSecret" yaml:"appSecret" validate:"required"`
|
||||
|
||||
// Platform authentication service address
|
||||
// Required: true
|
||||
// Example: "https://sso.digitalenergy.online"
|
||||
SSOURL string
|
||||
SSOURL string `json:"ssoUrl" yaml:"ssoUrl" validate:"url"`
|
||||
|
||||
// The address of the platform on which the actions are planned
|
||||
// Required: true
|
||||
// Example: "https://mr4.digitalenergy.online"
|
||||
DecortURL string
|
||||
DecortURL string `json:"decortUrl" yaml:"decortUrl" validate:"url"`
|
||||
|
||||
// Amount platform request attempts
|
||||
// Default value: 5
|
||||
// Required: false
|
||||
Retries uint64
|
||||
Retries uint64 `json:"retries" yaml:"retries"`
|
||||
|
||||
// Skip verify, true by default
|
||||
// Required: false
|
||||
SSLSkipVerify bool
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
}
|
||||
|
||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
||||
func ParseConfigJSON(path string) (Config, error) {
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
err = json.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return Config{}, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// ParseConfigYAML parses Config from specified YAML-formatted file.
|
||||
func ParseConfigYAML(path string) (Config, error) {
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
err = yaml.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return Config{}, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
@@ -1,33 +1,89 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Legacy client configuration
|
||||
type LegacyConfig struct {
|
||||
// ServiceAccount username
|
||||
// Required: true
|
||||
// Example : "osh_mikoev"
|
||||
Username string
|
||||
Username string `json:"username" yaml:"username" validate:"required"`
|
||||
|
||||
// ServiceAccount password
|
||||
// Required: true
|
||||
// Example: "[1o>hYkjnJr)HI78q7t&#%8Lm"
|
||||
Password string
|
||||
Password string `json:"password" yaml:"password" validate:"required"`
|
||||
|
||||
// Platform token
|
||||
// Required: false
|
||||
// Example: "158e76424b0d4810b6086hgbhj928fc4a6bc06e"
|
||||
Token string
|
||||
Token string `json:"token" yaml:"token"`
|
||||
|
||||
// Address of the platform on which the actions are planned
|
||||
// Required: true
|
||||
// Example: "https://mr4.digitalenergy.online"
|
||||
DecortURL string
|
||||
DecortURL string `json:"decortUrl" yaml:"decortUrl" validate:"url"`
|
||||
|
||||
// Amount platform request attempts
|
||||
// Default value: 5
|
||||
// Required: false
|
||||
Retries uint64
|
||||
Retries uint64 `json:"retries" yaml:"retries"`
|
||||
|
||||
// Skip verify, true by default
|
||||
// Required: false
|
||||
SSLSkipVerify bool
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
}
|
||||
|
||||
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
||||
func ParseLegacyConfigJSON(path string) (LegacyConfig, error) {
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return LegacyConfig{}, err
|
||||
}
|
||||
|
||||
var config LegacyConfig
|
||||
|
||||
err = json.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
return LegacyConfig{}, err
|
||||
}
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return LegacyConfig{}, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// ParseLegacyConfigYAML parses LegacyConfig from specified YAML-formatted file.
|
||||
func ParseLegacyConfigYAML(path string) (LegacyConfig, error) {
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return LegacyConfig{}, err
|
||||
}
|
||||
|
||||
var config LegacyConfig
|
||||
|
||||
err = yaml.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
return LegacyConfig{}, err
|
||||
}
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return LegacyConfig{}, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user