// 2020 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package ecm import ( "fmt" "github.rackspace.com/DCM/discover/common" "github.rackspace.com/DCM/discover/log" "github.rackspace.com/DCM/netparse" "github.rackspace.com/gorax/clients/dcxAutohost" "github.rackspace.com/gorax/passkey" ) type ( // DCX type represents client references to third-party resources required // for the methods within this package. DCX struct { dcx *dcxAutohost.Client key *passkey.Client db *common.DB vlansByID map[string]netparse.Vlan log.Collector } ) // dpClient (Client) function should exist in every implementation of the Client interface. // This function will create an initialized type that will satisfy the requirements of the Client interface. func dcxECM(key *passkey.Client) (*DCX, error) { client := new(DCX) ssoKey := key.Service.SSO.Credential // Build the authentication to send to dcxAutohost auth := dcxAutohost.WithCredential(ssoKey.Username, ssoKey.Password) dcx, err := dcxAutohost.New(auth, false) if err != nil { return client, fmt.Errorf("dcxECM:dcx.New:%s", err) } mgo, err := common.NewDB(key) if err != nil { return client, fmt.Errorf("dcxECM:NewDB:%s", err) } client.dcx = dcx client.db = mgo client.key = key client.vlansByID = make(map[string]netparse.Vlan) return client, nil }