yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/objectstore/xsky/provider/provider.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package provider
    16  
    17  import (
    18  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    19  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    20  	"yunion.io/x/cloudmux/pkg/multicloud/objectstore"
    21  	s3provider "yunion.io/x/cloudmux/pkg/multicloud/objectstore/provider"
    22  	"yunion.io/x/cloudmux/pkg/multicloud/objectstore/xsky"
    23  )
    24  
    25  type SXskyProviderFactory struct {
    26  	s3provider.SObjectStoreProviderFactory
    27  }
    28  
    29  func (self *SXskyProviderFactory) GetId() string {
    30  	return api.CLOUD_PROVIDER_XSKY
    31  }
    32  
    33  func (self *SXskyProviderFactory) GetName() string {
    34  	return api.CLOUD_PROVIDER_XSKY
    35  }
    36  
    37  func (self *SXskyProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig) (cloudprovider.ICloudProvider, error) {
    38  	client, err := xsky.NewXskyClient(
    39  		objectstore.NewObjectStoreClientConfig(
    40  			cfg.URL, cfg.Account, cfg.Secret,
    41  		).CloudproviderConfig(cfg),
    42  	)
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  	return s3provider.NewObjectStoreProvider(self, client, []string{
    47  		string(cloudprovider.ACLPrivate),
    48  		string(cloudprovider.ACLPublicRead),
    49  		string(cloudprovider.ACLPublicReadWrite),
    50  	}), nil
    51  }
    52  
    53  func (self *SXskyProviderFactory) GetClientRC(info cloudprovider.SProviderInfo) (map[string]string, error) {
    54  	client, err := xsky.NewXskyClient(
    55  		objectstore.NewObjectStoreClientConfig(
    56  			info.Url, info.Account, info.Secret,
    57  		),
    58  	)
    59  	if err != nil {
    60  		return nil, err
    61  	}
    62  	return client.GetClientRC(), nil
    63  }
    64  
    65  func init() {
    66  	factory := SXskyProviderFactory{}
    67  	cloudprovider.RegisterFactory(&factory)
    68  }