factory.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. package object
  15. import (
  16. "yunion.io/x/cloudmux/pkg/multicloud/objectstore"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. api "yunion.io/x/onecloud/pkg/apis/compute"
  20. "yunion.io/x/onecloud/pkg/hostman/storageman/backupstorage"
  21. "yunion.io/x/onecloud/pkg/httperrors"
  22. )
  23. type sObjectBackupStorageFactory struct{}
  24. func (factory *sObjectBackupStorageFactory) NewBackupStore(backupStroageId string, backupStorageAccessInfo *jsonutils.JSONDict) (backupstorage.IBackupStorage, error) {
  25. accessInfo := api.SBackupStorageAccessInfo{}
  26. err := backupStorageAccessInfo.Unmarshal(&accessInfo)
  27. if err != nil {
  28. return nil, errors.Wrap(err, "Unmarshal access info")
  29. }
  30. if len(accessInfo.ObjectBucketUrl) == 0 {
  31. return nil, errors.Wrap(httperrors.ErrInputParameter, "need object_bucket_url in backup_storage_access_info")
  32. }
  33. if len(accessInfo.ObjectAccessKey) == 0 {
  34. return nil, errors.Wrap(httperrors.ErrInputParameter, "need object_access_key in backup_storage_access_info")
  35. }
  36. if len(accessInfo.ObjectSecret) == 0 {
  37. return nil, errors.Wrap(httperrors.ErrInputParameter, "need object_secret in backup_storage_access_info")
  38. }
  39. return newObjectBackupStorage(
  40. backupStroageId,
  41. accessInfo.ObjectBucketUrl,
  42. accessInfo.ObjectAccessKey,
  43. accessInfo.ObjectSecret,
  44. objectstore.S3SignVersion(accessInfo.ObjectSignVer),
  45. accessInfo.ObjectBucketUrlExt,
  46. )
  47. }
  48. func init() {
  49. backupstorage.RegisterFactory(&sObjectBackupStorageFactory{})
  50. }