Documentation ¶
Index ¶
- Constants
- Variables
- func CombineStorageKeys(keys ...string) (string, error)
- func EscapedStorageKey(key string) string
- func GenerateCosmosDBKey(id resources.ID) (string, error)
- func GetPartitionKey(id resources.ID) (string, error)
- func NormalizeLetterOrDigitToUpper(s string) string
- func NormalizeStorageKey(storageKey string, maxLength int) (string, error)
- func NormalizeSubscriptionID(subscriptionID string) string
- func TrimStorageKey(storageKey string, maxLength int) (string, error)
- type ConnectionOptions
- type CosmosDBStorageClient
- func (c *CosmosDBStorageClient) Delete(ctx context.Context, id string, opts ...store.DeleteOptions) error
- func (c *CosmosDBStorageClient) Get(ctx context.Context, id string, opts ...store.GetOptions) (*store.Object, error)
- func (c *CosmosDBStorageClient) Init(ctx context.Context) error
- func (c *CosmosDBStorageClient) Query(ctx context.Context, query store.Query, opts ...store.QueryOptions) (*store.ObjectQueryResult, error)
- func (c *CosmosDBStorageClient) Save(ctx context.Context, obj *store.Object, opts ...store.SaveOptions) error
- type ResourceEntity
Constants ¶
const ( // StorageKeyTrimPaddingLen is the length of the padding when key is trimed. StorageKeyTrimPaddingLen = 17 // The resource group name storage key length. ResourceGroupNameMaxStorageKeyLen = 64 // The resource identifier storage key limit. ResourceIdMaxStorageKeyLen = 157 )
const (
// PartitionKeyName is the property used for partitioning.
PartitionKeyName = "/partitionKey"
)
Variables ¶
var (
ErrInvalidKey = errors.New("key includes invalid character")
)
Functions ¶
func CombineStorageKeys ¶
CombineStorageKeys combines multiple storage keys into one, returning an error if any of the keys contain the key delimiter.
func EscapedStorageKey ¶
EscapedStorageKey escapes a string so that it can be used as a storage key.
func GenerateCosmosDBKey ¶
GenerateCosmosDBKey takes in an ID object and returns a string and an error if the resource group or resource type and name fail to normalize.
func GetPartitionKey ¶
GetPartitionKey returns a partition key based on the given ID, normalizing the subscription ID and normalizing the plane namespace if the ID is UCP-qualified. Examples: /planes/radius/local/... - Partition Key: radius/local subscriptions/{guid}/... - Partition Key: {guid}
func NormalizeLetterOrDigitToUpper ¶
NormalizeLetterOrDigitToUpper takes in a string and returns a new string with all letters and digits converted to uppercase.
func NormalizeStorageKey ¶
NormalizeStorageKey takes a storage key string and a maximum length and returns a normalized string with the maximum length, or an error if the maximum length is exceeded.
func NormalizeSubscriptionID ¶
NormalizeSubscriptionID normalizes subscription id.
Types ¶
type ConnectionOptions ¶
type ConnectionOptions struct { // Url represents the url of cosmosdb endpoint. Url string // DatabaseName represents the database name to connect. DatabaseName string // CollectionName represents the collection name in DataBaseName CollectionName string // DefaultQueryItemCount represents the maximum number of items for query. DefaultQueryItemCount int // CollectionThroughput represents shared throughput database share the throughput (RU/s) allocated to that database. CollectionThroughput int // MasterKey is the key string for CosmosDB connection. MasterKey string }
ConnectionOptions represents connection info to connect CosmosDB
type CosmosDBStorageClient ¶
type CosmosDBStorageClient struct {
// contains filtered or unexported fields
}
CosmosDBStorageClient implements CosmosDB stroage client.
func NewCosmosDBStorageClient ¶
func NewCosmosDBStorageClient(options *ConnectionOptions) (*CosmosDBStorageClient, error)
NewCosmosDBStorageClient creates a new CosmosDBStorageClient instance using the provided ConnectionOptions and returns it, or an error if the ConnectionOptions are invalid.
func (*CosmosDBStorageClient) Delete ¶
func (c *CosmosDBStorageClient) Delete(ctx context.Context, id string, opts ...store.DeleteOptions) error
Delete parses the given ID, gets the partition key, generates the CosmosDB key, and deletes the document from the CosmosDB collection. It returns an error if the document is not found.
func (*CosmosDBStorageClient) Get ¶
func (c *CosmosDBStorageClient) Get(ctx context.Context, id string, opts ...store.GetOptions) (*store.Object, error)
Get retrieves an object using CosmosDBStorageClient using the provided ID and optional GetOptions. It returns an error if the object is not found or if an error occurs while retrieving the object.
func (*CosmosDBStorageClient) Init ¶
func (c *CosmosDBStorageClient) Init(ctx context.Context) error
Init checks if the database and collection exist, and if not, creates them. It returns an error if either of the checks or creations fail.
func (*CosmosDBStorageClient) Query ¶
func (c *CosmosDBStorageClient) Query(ctx context.Context, query store.Query, opts ...store.QueryOptions) (*store.ObjectQueryResult, error)
Query builds and executes a CosmosDB query based on the provided store.Query and returns the results.
func (*CosmosDBStorageClient) Save ¶
func (c *CosmosDBStorageClient) Save(ctx context.Context, obj *store.Object, opts ...store.SaveOptions) error
Save saves an object to the CosmosDB storage, returning an error if one occurs. If an ETag is provided, an error is returned if the ETag does not match the existing ETag.
type ResourceEntity ¶
type ResourceEntity struct { // CosmosDB system-related properties. // ID represents the primary key. ID string `json:"id"` // ETag represents an etag required for optimistic concurrency control. ETag string `json:"_etag"` // Self represents the unique addressable URI for the resource. Self string `json:"_self"` // Timestamp represents the last updated timestamp of the resource. UpdatedTime int `json:"_ts"` // ResourceID represents fully qualified resource id. ResourceID string `json:"resourceId"` // RootScope represents root scope such as subscription id. RootScope string `json:"rootScope"` // ResourceGroup represents fully qualified resource scope. ResourceGroup string `json:"resourceGroup"` // PartitionKey represents the key used for partitioning. PartitionKey string `json:"partitionKey"` // Entity represents the resource metadata. Entity any `json:"entity"` }
ResourceEntity represents the default envelope model to store resource metadata.