コード例 #1
0
 public static string CreateLinkUri(CosmosClientContext clientContext, DatabaseInternal database, string keyId)
 {
     return(clientContext.CreateLink(
                parentLink: database.LinkUri,
                uriPathSegment: Paths.ClientEncryptionKeysPathSegment,
                id: keyId));
 }
コード例 #2
0
        internal override async Task <Stream> EncryptItemAsync(
            Stream input,
            EncryptionOptions encryptionOptions,
            DatabaseInternal database,
            CosmosDiagnosticsContext diagnosticsContext,
            CancellationToken cancellationToken)
        {
            if (input == null)
            {
                throw new ArgumentException(ClientResources.InvalidRequestWithEncryptionOptions);
            }

            Debug.Assert(encryptionOptions != null);
            Debug.Assert(database != null);
            Debug.Assert(diagnosticsContext != null);

            using (diagnosticsContext.CreateScope("Encrypt"))
            {
                return(await this.EncryptionProcessor.EncryptAsync(
                           input,
                           encryptionOptions,
                           this.ClientOptions.Encryptor,
                           diagnosticsContext,
                           cancellationToken));
            }
        }
コード例 #3
0
 internal UserInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string userId)
     : base(
         clientContext,
         database,
         userId)
 {
 }
コード例 #4
0
 internal ClientEncryptionKeyInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string keyId)
     : base(
         clientContext,
         database,
         keyId)
 {
 }
コード例 #5
0
 internal ContainerInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string containerId,
     CosmosQueryClient cosmosQueryClient = null)
     : base(clientContext,
            database,
            containerId,
            cosmosQueryClient)
 {
 }
コード例 #6
0
 public ClientEncryptionKeyCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string keyId)
 {
     this.Id            = keyId;
     this.ClientContext = clientContext;
     this.LinkUri       = ClientEncryptionKeyCore.CreateLinkUri(
         clientContext,
         database,
         keyId);
     this.Database = database;
 }
コード例 #7
0
        internal UserCore(
            CosmosClientContext clientContext,
            DatabaseInternal database,
            string userId)
        {
            this.Id            = userId;
            this.ClientContext = clientContext;
            this.LinkUri       = clientContext.CreateLink(
                parentLink: database.LinkUri,
                uriPathSegment: Paths.UsersPathSegment,
                id: userId);

            this.Database = database;
        }
コード例 #8
0
        public async Task <ItemResponse <T> > ReadCurrentAsync <T>(
            ConflictProperties cosmosConflict,
            PartitionKey partitionKey,
            ITrace trace,
            CancellationToken cancellationToken = default)
        {
            if (cosmosConflict == null)
            {
                throw new ArgumentNullException(nameof(cosmosConflict));
            }

            // SourceResourceId is RID based on Conflicts, so we need to obtain the db and container rid
            DatabaseInternal databaseCore       = (DatabaseInternal)this.container.Database;
            string           databaseResourceId = await databaseCore.GetRIDAsync(cancellationToken);

            string containerResourceId = await this.container.GetCachedRIDAsync(
                forceRefresh : false,
                trace,
                cancellationToken : cancellationToken);

            string dbLink = this.ClientContext.CreateLink(
                parentLink: string.Empty,
                uriPathSegment: Paths.DatabasesPathSegment,
                id: databaseResourceId);

            string containerLink = this.ClientContext.CreateLink(
                parentLink: dbLink,
                uriPathSegment: Paths.CollectionsPathSegment,
                id: containerResourceId);

            string itemLink = this.ClientContext.CreateLink(
                parentLink: containerLink,
                uriPathSegment: Paths.DocumentsPathSegment,
                id: cosmosConflict.SourceResourceId);

            ResponseMessage response = await this.ClientContext.ProcessResourceOperationStreamAsync(
                resourceUri : itemLink,
                resourceType : ResourceType.Document,
                operationType : OperationType.Read,
                requestOptions : null,
                cosmosContainerCore : this.container,
                feedRange : new FeedRangePartitionKey(partitionKey),
                streamPayload : null,
                requestEnricher : null,
                trace : trace,
                cancellationToken : cancellationToken);

            return(this.ClientContext.ResponseFactory.CreateItemResponse <T>(response));
        }
コード例 #9
0
        public override async Task <ItemResponse <T> > ReadCurrentAsync <T>(
            ConflictProperties cosmosConflict,
            PartitionKey partitionKey,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (cosmosConflict == null)
            {
                throw new ArgumentNullException(nameof(cosmosConflict));
            }

            // SourceResourceId is RID based on Conflicts, so we need to obtain the db and container rid
            DatabaseInternal databaseCore       = (DatabaseInternal)this.container.Database;
            string           databaseResourceId = await databaseCore.GetRIDAsync(cancellationToken);

            string containerResourceId = await this.container.GetRIDAsync(cancellationToken);

            Uri dbLink = this.clientContext.CreateLink(
                parentLink: string.Empty,
                uriPathSegment: Paths.DatabasesPathSegment,
                id: databaseResourceId);

            Uri containerLink = this.clientContext.CreateLink(
                parentLink: dbLink.OriginalString,
                uriPathSegment: Paths.CollectionsPathSegment,
                id: containerResourceId);

            Uri itemLink = this.clientContext.CreateLink(
                parentLink: containerLink.OriginalString,
                uriPathSegment: Paths.DocumentsPathSegment,
                id: cosmosConflict.SourceResourceId);

            Task <ResponseMessage> response = this.clientContext.ProcessResourceOperationStreamAsync(
                resourceUri: itemLink,
                resourceType: ResourceType.Document,
                operationType: OperationType.Read,
                requestOptions: null,
                cosmosContainerCore: this.container,
                partitionKey: partitionKey,
                streamPayload: null,
                requestEnricher: null,
                diagnosticsContext: null,
                cancellationToken: cancellationToken);

            return(await this.clientContext.ResponseFactory.CreateItemResponseAsync <T>(response));
        }
コード例 #10
0
        protected ContainerCore(
            CosmosClientContext clientContext,
            DatabaseInternal database,
            string containerId,
            CosmosQueryClient cosmosQueryClient = null)
        {
            this.Id            = containerId;
            this.ClientContext = clientContext;
            this.LinkUri       = clientContext.CreateLink(
                parentLink: database.LinkUri.OriginalString,
                uriPathSegment: Paths.CollectionsPathSegment,
                id: containerId);

            this.Database  = database;
            this.Conflicts = new ConflictsInlineCore(this.ClientContext, this);
            this.Scripts   = new ScriptsInlineCore(this, this.ClientContext);
            this.cachedUriSegmentWithoutId = this.GetResourceSegmentUriWithoutId();
            this.queryClient       = cosmosQueryClient ?? new CosmosQueryClientCore(this.ClientContext, this);
            this.lazyBatchExecutor = new Lazy <BatchAsyncContainerExecutor>(() => this.ClientContext.GetExecutorForContainer(this));
        }
コード例 #11
0
        internal override async Task <Stream> DecryptItemAsync(
            Stream input,
            DatabaseInternal database,
            CosmosDiagnosticsContext diagnosticsContext,
            CancellationToken cancellationToken)
        {
            if (input == null || this.ClientOptions.Encryptor == null)
            {
                return(input);
            }

            Debug.Assert(database != null);
            Debug.Assert(diagnosticsContext != null);

            using (diagnosticsContext.CreateScope("Decrypt"))
            {
                return(await this.EncryptionProcessor.DecryptAsync(
                           input,
                           this.ClientOptions.Encryptor,
                           diagnosticsContext,
                           cancellationToken));
            }
        }
コード例 #12
0
 internal abstract Task <Stream> DecryptItemAsync(
     Stream input,
     DatabaseInternal database,
     CosmosDiagnosticsContext diagnosticsContext,
     CancellationToken cancellationToken);