Repository: pingcap/tidb
File: pkg/objstore/ossstore/store.go (Go)

Code before:
	"net/http"
	"strings"
	"time"

	"github.com/alibabacloud-go/tea/tea"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/credentials-go/credentials/providers"
	"github.com/pingcap/errors"
	backuppb "github.com/pingcap/kvproto/pkg/brpb"
	"github.com/pingcap/log"
	berrors "github.com/pingcap/tidb/br/pkg/errors"
	"github.com/pingcap/tidb/pkg/objstore/recording"
	"github.com/pingcap/tidb/pkg/objstore/s3like"
	"github.com/pingcap/tidb/pkg/objstore/storeapi"
	"github.com/pingcap/tidb/pkg/util/httputil"
	"go.uber.org/zap"
)

const (
	defaultRegion = "cn-hangzhou"
	// ECS RAM role credential provider name, see
	// https://github.com/aliyun/credentials-go/blob/7d2a3e68402630904f518531e80b370b3649c6a1/credentials/providers/ecs_ram_role.go#L238
	ecsRAMRoleProviderName = "ecs_ram_role"
	// the URL to get region ID from ECS metadata service, Aliyun SDK doesn't
	// provider this API, so we have to write our own, see
	// https://github.com/aliyun/aliyun_assist_client/blob/feb283504ee5a11484067af9762f1008baa664b0/common/metaserver/prop.go#L34-L37
	// and https://www.alibabacloud.com/blog/alibaba-cloud-ecs-metadata-user-data-and-dynamic-data_594351#:~:text=Retrieve%20Region%20Information
	regionIDMetaURL = "http://100.100.100.200/latest/meta-data/region-id"
)

// OSSStore is the OSS storage implementation.
type OSSStore struct {
	*s3like.Storage
	credRefresher *credentialRefresher
}

// Close implements storeapi.Storage.
func (s *OSSStore) Close() {
	s.Storage.Close()
	if s.credRefresher != nil {
		s.credRefresher.close()
	}
}

// NewOSSStorage creates a OSS storage client.
//
// permissions required to create the client:
//   - GetBucketLocation
//
// permissions required to r/w data:

Review comment (suggestion):
Typo in comment: "provider" should be "provide". The comment reads "Aliyun SDK doesn't provider this API" but should read "Aliyun SDK doesn't provide this API".
```suggestion
	// provide this API, so we have to write our own, see
```

Code after:
	"net/http"
	"strings"
	"time"

	"github.com/alibabacloud-go/tea/tea"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/credentials-go/credentials/providers"
	"github.com/pingcap/errors"
	backuppb "github.com/pingcap/kvproto/pkg/brpb"
	"github.com/pingcap/log"
	berrors "github.com/pingcap/tidb/br/pkg/errors"
	"github.com/pingcap/tidb/pkg/objstore/recording"
	"github.com/pingcap/tidb/pkg/objstore/s3like"
	"github.com/pingcap/tidb/pkg/objstore/storeapi"
	"github.com/pingcap/tidb/pkg/util/httputil"
	"go.uber.org/zap"
)

const (
	defaultRegion = "cn-hangzhou"
	// ECS RAM role credential provider name, see
	// https://github.com/aliyun/credentials-go/blob/7d2a3e68402630904f518531e80b370b3649c6a1/credentials/providers/ecs_ram_role.go#L238
	ecsRAMRoleProviderName = "ecs_ram_role"
	// the URL to get region ID from ECS metadata service, Aliyun SDK doesn't
	// provide this API, so we have to write our own, see
	// https://github.com/aliyun/aliyun_assist_client/blob/feb283504ee5a11484067af9762f1008baa664b0/common/metaserver/prop.go#L34-L37
	// and https://www.alibabacloud.com/blog/alibaba-cloud-ecs-metadata-user-data-and-dynamic-data_594351#:~:text=Retrieve%20Region%20Information
	regionIDMetaURL = "http://100.100.100.200/latest/meta-data/region-id"
)

// OSSStore is the OSS storage implementation.
type OSSStore struct {
	*s3like.Storage
	credRefresher *credentialRefresher
}

// Close implements storeapi.Storage.
func (s *OSSStore) Close() {
	s.Storage.Close()
	if s.credRefresher != nil {
		s.credRefresher.close()
	}
}

// NewOSSStorage creates a OSS storage client.
//
// permissions required to create the client:
//   - GetBucketLocation
//
// permissions required to r/w data: