예제 #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));
            }
        }
 internal UserInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string userId)
     : base(
         clientContext,
         database,
         userId)
 {
 }
 internal ClientEncryptionKeyInlineCore(
     CosmosClientContext clientContext,
     DatabaseInternal database,
     string keyId)
     : base(
         clientContext,
         database,
         keyId)
 {
 }
 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;
        }
        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));
            }
        }
 internal abstract Task <Stream> DecryptItemAsync(
     Stream input,
     DatabaseInternal database,
     CosmosDiagnosticsContext diagnosticsContext,
     CancellationToken cancellationToken);