This commit is contained in:
asteam
2024-08-23 16:55:50 +03:00
parent 6f40af6a5f
commit 003e4d656e
524 changed files with 43376 additions and 432 deletions

View File

@@ -6,7 +6,6 @@ import (
"os"
"strings"
log "github.com/sirupsen/logrus"
sdk_config "repository.basistech.ru/BASIS/decort-golang-sdk/config"
)
@@ -38,82 +37,82 @@ type dynamixProviderConfig struct {
func (d *dynamixProviderConfig) new(config dynamixProviderModel) {
d.authenticator = strings.ToLower(config.Authenticator.ValueString())
if config.Oauth2Url.IsUnknown() {
d.oauth2Url = os.Getenv("DECORT_OAUTH2_URL")
if config.Oauth2Url.IsNull() {
d.oauth2Url = os.Getenv("DYNAMIX_OAUTH2_URL")
} else {
d.oauth2Url = config.Oauth2Url.ValueString()
}
d.oauth2Url = strings.ToLower(d.oauth2Url)
d.controllerUrl = strings.ToLower(config.ControllerUrl.ValueString())
if d.controllerUrl == "" {
log.Debugf("empty DECORT cloud controller URL provided")
return
if config.ControllerUrl.IsNull() {
d.controllerUrl = os.Getenv("DYNAMIX_CONTROLLER_URL")
} else {
d.controllerUrl = strings.ToLower(config.ControllerUrl.ValueString())
}
if config.User.IsUnknown() {
d.user = os.Getenv("DECORT_USER")
if config.User.IsNull() {
d.user = os.Getenv("DYNAMIX_USER")
} else {
d.user = config.User.ValueString()
}
if config.Password.IsUnknown() {
d.password = os.Getenv("DECORT_PASSWORD")
if config.Password.IsNull() {
d.password = os.Getenv("DYNAMIX_PASSWORD")
} else {
d.password = config.Password.ValueString()
}
if config.BvsUser.IsUnknown() {
d.bvsUser = os.Getenv("DECORT_BVS_USER")
if config.BvsUser.IsNull() {
d.bvsUser = os.Getenv("DYNAMIX_BVS_USER")
} else {
d.bvsUser = config.BvsUser.ValueString()
}
if config.BvsPassword.IsUnknown() {
d.bvsPassword = os.Getenv("DECORT_BVS_PASSWORD")
if config.BvsPassword.IsNull() {
d.bvsPassword = os.Getenv("DYNAMIX_BVS_PASSWORD")
} else {
d.bvsPassword = config.BvsPassword.ValueString()
}
if config.Domain.IsUnknown() {
d.domain = os.Getenv("DECORT_DOMAIN")
if config.Domain.IsNull() {
d.domain = os.Getenv("DYNAMIX_DOMAIN")
} else {
d.domain = config.Domain.ValueString()
}
if config.AppId.IsUnknown() {
d.appId = os.Getenv("DECORT_APP_ID")
if config.AppId.IsNull() {
d.appId = os.Getenv("DYNAMIX_APP_ID")
} else {
d.appId = config.AppId.ValueString()
}
if config.AppSecret.IsUnknown() {
d.appSecret = os.Getenv("DECORT_APP_SECRET")
if config.AppSecret.IsNull() {
d.appSecret = os.Getenv("DYNAMIX_APP_SECRET")
} else {
d.appSecret = config.AppSecret.ValueString()
}
if config.Jwt.IsUnknown() {
d.jwt = os.Getenv("DECORT_JWT")
if config.Jwt.IsNull() {
d.jwt = os.Getenv("DYNAMIX_JWT")
} else {
d.jwt = config.Jwt.ValueString()
}
if config.AllowUnverifiedSsl.IsUnknown() {
if config.AllowUnverifiedSsl.IsNull() {
d.allowUnverifiedSsl = false // default false
} else {
d.allowUnverifiedSsl = config.AllowUnverifiedSsl.ValueBool()
}
if !config.PathConfig.IsUnknown() {
if !config.PathConfig.IsNull() {
d.pathConfig = config.PathConfig.ValueString()
}
if !config.PathToken.IsUnknown() {
if !config.PathToken.IsNull() {
d.pathToken = config.PathToken.ValueString()
}
if !config.TimeToRefresh.IsUnknown() {
if !config.TimeToRefresh.IsNull() {
d.timeToRefresh = config.TimeToRefresh.ValueInt64()
}
@@ -125,6 +124,12 @@ func (d *dynamixProviderConfig) new(config dynamixProviderModel) {
// reason, the method will return mode = MODE_UNDEF and error.
func (d *dynamixProviderConfig) validateAuthenticator() (int, error) {
var mode = MODE_UNDEF
if d.oauth2Url == "" {
return mode, fmt.Errorf("OAuth2 URL is required")
}
if d.controllerUrl == "" {
return mode, fmt.Errorf("controllerURL is required")
}
switch d.authenticator {
case "jwt":
if d.jwt == "" {
@@ -132,9 +137,6 @@ func (d *dynamixProviderConfig) validateAuthenticator() (int, error) {
}
mode = MODE_JWT
case "decs3o":
if d.oauth2Url == "" {
return mode, fmt.Errorf("authenticator mode 'decs3o' specified but no OAuth2 URL provided")
}
if d.appId == "" {
return mode, fmt.Errorf("authenticator mode 'decs3o' specified but no Application ID provided")
}
@@ -149,6 +151,12 @@ func (d *dynamixProviderConfig) validateAuthenticator() (int, error) {
if d.password == "" {
return mode, fmt.Errorf("authenticator mode 'legacy' specified but no password provided")
}
if d.appId == "" {
return mode, fmt.Errorf("authenticator mode 'legacy' specified but no Application ID provided")
}
if d.appSecret == "" {
return mode, fmt.Errorf("authenticator mode 'legacy' specified but no Secret ID provided")
}
mode = MODE_LEGACY
case "bvs":
if d.bvsUser == "" {
@@ -157,9 +165,6 @@ func (d *dynamixProviderConfig) validateAuthenticator() (int, error) {
if d.bvsPassword == "" {
return mode, fmt.Errorf("authenticator mode 'bvs' specified but no bvs password provided")
}
if d.oauth2Url == "" {
return mode, fmt.Errorf("authenticator mode 'bvs' specified but no bvs URL provided")
}
if d.appId == "" {
return mode, fmt.Errorf("authenticator mode 'bvs' specified but no Application ID provided")
}