This commit is contained in:
KasimBaybikov
2023-05-04 10:08:25 +03:00
parent 9bad8a6947
commit 8ca233dd32
288 changed files with 6645 additions and 11464 deletions

View File

@@ -35,6 +35,11 @@ import (
// "time"
log "github.com/sirupsen/logrus"
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
jwt "github.com/golang-jwt/jwt/v4"
@@ -62,6 +67,7 @@ type ControllerCfg struct {
oauth2_url string // always required
decort_username string // assigned to either legacy_user (legacy mode) or Oauth2 user (oauth2 mode) upon successful verification
cc_client *http.Client // assigned when all initial checks successfully passed
caller interfaces.Caller
}
func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
@@ -147,6 +153,17 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
return nil, err
}
ret_config.decort_username = ret_config.legacy_user
sdkConf := config.LegacyConfig{
Username: ret_config.legacy_user,
Password: ret_config.legacy_password,
DecortURL: ret_config.controller_url,
Retries: 0,
SSLSkipVerify: allow_unverified_ssl,
}
ret_config.caller = decort.NewLegacy(sdkConf)
case MODE_JWT:
//
ok, err := ret_config.validateJWT("")
@@ -177,6 +194,17 @@ func ControllerConfigure(d *schema.ResourceData) (*ControllerCfg, error) {
} else {
return nil, fmt.Errorf("Failed to extract user and iss fields from JWT token in oauth2 mode.")
}
sdkConf := config.Config{
AppID: ret_config.app_id,
AppSecret: ret_config.app_secret,
SSOURL: ret_config.oauth2_url,
DecortURL: ret_config.controller_url,
SSLSkipVerify: allow_unverified_ssl,
}
ret_config.caller = decort.New(sdkConf)
default:
// FYI, this should never happen due to all above checks, but we want to be fool proof
return nil, fmt.Errorf("Unknown authenticator mode code %d provided.", ret_config.auth_mode_code)
@@ -327,6 +355,26 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) {
return true, nil
}
func (config *ControllerCfg) CloudAPI() *cloudapi.CloudAPI {
if config.auth_mode_code == MODE_LEGACY {
client, _ := config.caller.(*decort.LegacyDecortClient)
return client.CloudAPI()
}
client, _ := config.caller.(*decort.DecortClient)
return client.CloudAPI()
}
func (config *ControllerCfg) CloudBroker() *cloudbroker.CloudBroker {
if config.auth_mode_code == MODE_LEGACY {
client, _ := config.caller.(*decort.LegacyDecortClient)
return client.CloudBroker()
}
client, _ := config.caller.(*decort.DecortClient)
return client.CloudBroker()
}
func (config *ControllerCfg) DecortAPICall(ctx context.Context, method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam
// This is a convenience wrapper around standard HTTP request methods that is aware of the
// authorization mode for which the provider was initialized and compiles request accordingly.