github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/obs/client_other.go (about)

     1  // Copyright 2019 Huawei Technologies Co.,Ltd.
     2  // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
     3  // this file except in compliance with the License.  You may obtain a copy of the
     4  // License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software distributed
     9  // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    10  // CONDITIONS OF ANY KIND, either express or implied.  See the License for the
    11  // specific language governing permissions and limitations under the License.
    12  
    13  package obs
    14  
    15  import (
    16  	"strings"
    17  )
    18  
    19  // Refresh refreshes ak, sk and securityToken for obsClient.
    20  func (obsClient ObsClient) Refresh(ak, sk, securityToken string) {
    21  	for _, sp := range obsClient.conf.securityProviders {
    22  		if bsp, ok := sp.(*BasicSecurityProvider); ok {
    23  			bsp.refresh(strings.TrimSpace(ak), strings.TrimSpace(sk), strings.TrimSpace(securityToken))
    24  			break
    25  		}
    26  	}
    27  }
    28  
    29  func (obsClient ObsClient) getSecurity() securityHolder {
    30  	if obsClient.conf.securityProviders != nil {
    31  		for _, sp := range obsClient.conf.securityProviders {
    32  			if sp == nil {
    33  				continue
    34  			}
    35  			sh := sp.getSecurity()
    36  			if sh.ak != "" && sh.sk != "" {
    37  				return sh
    38  			}
    39  		}
    40  	}
    41  	return emptySecurityHolder
    42  }
    43  
    44  // Close closes ObsClient.
    45  func (obsClient *ObsClient) Close() {
    46  	obsClient.httpClient = nil
    47  	obsClient.conf.transport.CloseIdleConnections()
    48  	obsClient.conf = nil
    49  }