示例#1
0
        public override void AcceptRequest(RequestContext context, Microsoft.Cis.Services.Nephos.Common.ServiceType serviceType)
        {
            Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("Accepting request");

            context.ServiceType = serviceType;
            PerRequestStorageManager perRequestStorageManager = new PerRequestStorageManager(BlobServiceEntry.SharedStorageManager, context.OperationStatus);
            AuthenticationManager    operationStatus          = XFEBlobAuthenticationManager.CreateAuthenticationManager(perRequestStorageManager, false);

            operationStatus.OperationStatus = context.OperationStatus;
            AuthorizationManager authorizationManager = XFEBlobAuthorizationManager.CreateAuthorizationManager(perRequestStorageManager, true);

            authorizationManager.OperationStatus = context.OperationStatus;
            ServiceManager serviceManager = RealServiceManager.CreateServiceManager(authorizationManager, perRequestStorageManager, BlobServiceEntry.SharedConfig);

            serviceManager.OperationStatus = context.OperationStatus;
            IProcessor processor = HttpRestProcessor.Create(context, perRequestStorageManager, operationStatus, serviceManager, HttpRestProcessor.HttpProcessorConfigurationDefaultInstance, new TransformExceptionDelegate(SqlExceptionManager.TransformSqlException), null);
            bool       flag      = true;

            try
            {
                try
                {
                    processor.BeginProcess(new AsyncCallback(this.ProcessAsyncCallback), processor);
                    flag = false;
                }
                catch (NephosAssertionException nephosAssertionException1)
                {
                    NephosAssertionException nephosAssertionException = nephosAssertionException1;
                    IStringDataEventStream   error = Logger <IRestProtocolHeadLogger> .Instance.Error;
                    object[] str = new object[] { nephosAssertionException.ToString() };
                    error.Log("ASSERTION in BeginProcess: {0}", str);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    IStringDataEventStream unhandledException = Logger <IRestProtocolHeadLogger> .Instance.UnhandledException;
                    object[] objArray = new object[] { exception.ToString() };
                    unhandledException.Log("BeginProcess threw exception {0}", objArray);
                }
            }
            finally
            {
                if (flag)
                {
                    processor.Dispose();
                }
            }
            Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("Returning from AcceptRequest method.");
        }
示例#2
0
        void Microsoft.Cis.Services.Nephos.Common.Protocols.Rest.IServiceEntry.Initialize(IServiceEntrySink sink)
        {
            Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("[Nephos.Storage] { Initialize");

            HttpRestProcessor.HttpProcessorConfigurationDefaultInstance = HttpProcessorConfiguration.LoadDefaultHttpProcessorConfiguration(sink, "UriHostSuffixes", null);
            BlobServiceEntry.SharedStorageManager = new DbStorageManager();
            BlobServiceEntry.SharedConfig         = new ServiceManagerConfiguration();
            this.authenticationManager            = XFEBlobAuthenticationManager.CreateAuthenticationManager(BlobServiceEntry.SharedStorageManager, false);
            this.serviceManager             = RealServiceManager.CreateServiceManager(XFEBlobAuthorizationManager.CreateAuthorizationManager(BlobServiceEntry.SharedStorageManager, true), BlobServiceEntry.SharedStorageManager, BlobServiceEntry.SharedConfig);
            StorageStamp.TranslateException = new TranslateExceptionDelegate(SqlExceptionManager.ReThrowException);
            BlockBlobGarbageCollector.Initialize();
            Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("[Nephos.Storage] } Initialize");

            sink.RegisterRestHandler(this);
        }
示例#3
0
 public ContainerUnauthorizedException(string resourceAccount, string resourceContainer, string resourceIdentifier, IAccountIdentifier requestor, Microsoft.Cis.Services.Nephos.Common.Authorization.PermissionLevel permissionLevel, SASPermission signedPermission, Exception innerException) : this(string.Format(CultureInfo.InvariantCulture, "{0} does not have {1} access to resource {2}", new object[] { requestor.AccountName, permissionLevel, RealServiceManager.GetResourceString(resourceAccount, resourceContainer, resourceIdentifier) }), resourceAccount, resourceContainer, resourceIdentifier, requestor, permissionLevel, signedPermission, innerException)
 {
 }
示例#4
0
        protected IEnumerator <IAsyncResult> GetTableAclImpl(IAccountIdentifier identifier, string account, string tableName, TimeSpan timeout, RequestContext requestContext, AsyncIteratorContext <ContainerAclSettings> context)
        {
            Duration startingNow = Duration.StartingNow;

            if (identifier == null)
            {
                throw new ArgumentNullException("identifier");
            }
            if (string.IsNullOrEmpty(account))
            {
                throw new ArgumentException("account", "Cannot be null or empty");
            }
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentException("tableName", "Cannot be null or empty");
            }
            if (timeout <= TimeSpan.Zero)
            {
                throw new TimeoutException("Timed out in GetTableAcl");
            }
            if (identifier is TableSignedAccessAccountIdentifier || identifier is AccountSasAccessIdentifier)
            {
                throw new NephosUnauthorizedAccessException("Signed access not supported for this request", AuthorizationFailureReason.InvalidOperationSAS);
            }
            IAsyncResult asyncResult = this.authorizationManager.BeginCheckAccess(identifier, account, tableName, null, PermissionLevel.ReadAcl, startingNow.Remaining(timeout), context.GetResumeCallback(), context.GetResumeState("TableManager.GetTableAclImpl"));

            yield return(asyncResult);

            this.authorizationManager.EndCheckAccess(asyncResult);
            string str  = account;
            string str1 = tableName;

            using (IStorageAccount storageAccount = this.storageManager.CreateAccountInstance(str))
            {
                using (ITableContainer tableContainer = storageAccount.CreateTableContainerInstance(str1))
                {
                    ContainerPropertyNames containerPropertyName = ContainerPropertyNames.LastModificationTime | ContainerPropertyNames.ServiceMetadata;
                    tableContainer.Timeout = startingNow.Remaining(timeout);
                    asyncResult            = tableContainer.BeginGetProperties(containerPropertyName, null, CacheRefreshOptions.SkipAllCache, context.GetResumeCallback(), context.GetResumeState("TableManager.GetTableAclImpl"));
                    yield return(asyncResult);

                    tableContainer.EndGetProperties(asyncResult);
                    try
                    {
                        context.ResultData = new ContainerAclSettings(tableContainer.ServiceMetadata);
                    }
                    catch (MetadataFormatException metadataFormatException1)
                    {
                        MetadataFormatException metadataFormatException = metadataFormatException1;
                        throw new NephosStorageDataCorruptionException(string.Format("Error decoding Acl setting for {0}", RealServiceManager.GetResourceString(account, tableName)), metadataFormatException);
                    }
                }
            }
        }
示例#5
0
        public ListBlobResultsBlobProperties(IBlobObject blobObject, string separator)
        {
            if (blobObject == null)
            {
                throw new ArgumentNullException("blobObject");
            }
            this.blobName      = blobObject.Name;
            this.containerName = blobObject.ContainerName;
            if (separator == null || blobObject.Type != Microsoft.Cis.Services.Nephos.Common.Storage.BlobType.None)
            {
                this.isActualBlob = true;
                this.contentType  = blobObject.ContentType;
                NephosAssertionException.Assert(blobObject.LastModificationTime.HasValue);
                NephosAssertionException.Assert(blobObject.ContentLength.HasValue);
                this.lastModifiedTime = blobObject.LastModificationTime;
                this.size             = blobObject.ContentLength;
                NameValueCollection nameValueCollection = null;
                if (blobObject.ServiceMetadata != null)
                {
                    nameValueCollection = new NameValueCollection();
                    try
                    {
                        MetadataEncoding.Decode(blobObject.ServiceMetadata, nameValueCollection);
                    }
                    catch (MetadataFormatException metadataFormatException1)
                    {
                        MetadataFormatException metadataFormatException = metadataFormatException1;
                        CultureInfo             invariantCulture        = CultureInfo.InvariantCulture;
                        object[] objArray = new object[] { this.blobName };
                        throw new NephosStorageDataCorruptionException(string.Format(invariantCulture, "Error decoding service metadata for blob {0}", objArray), metadataFormatException);
                    }
                    this.contentEncoding    = nameValueCollection[RealServiceManager.ContentEncodingTag];
                    this.contentLanguage    = nameValueCollection[RealServiceManager.ContentLanguageTag];
                    this.cacheControl       = nameValueCollection[RealServiceManager.CacheControlTag];
                    this.contentCrc64       = nameValueCollection[RealServiceManager.ContentCrc64Tag];
                    this.contentMD5         = nameValueCollection[RealServiceManager.ContentMD5Tag];
                    this.contentDisposition = nameValueCollection[RealServiceManager.ContentDispositionTag];
                    if (this.contentMD5 != null && this.contentMD5.Equals(RealServiceManager.EmptyContentMD5Value, StringComparison.OrdinalIgnoreCase))
                    {
                        this.contentMD5 = null;
                    }
                    this.copyId                = nameValueCollection[RealServiceManager.CopyIdTag];
                    this.copySource            = nameValueCollection[RealServiceManager.CopySourceTag];
                    this.copyStatus            = nameValueCollection[RealServiceManager.CopyStatusTag];
                    this.copyStatusDescription = nameValueCollection[RealServiceManager.CopyStatusDescriptionTag];
                    if (!string.IsNullOrEmpty(nameValueCollection[RealServiceManager.CopyProgressOffsetTag]) && !string.IsNullOrEmpty(nameValueCollection[RealServiceManager.CopyProgressTotalTag]))
                    {
                        this.copyProgress = string.Format("{0}/{1}", nameValueCollection[RealServiceManager.CopyProgressOffsetTag], nameValueCollection[RealServiceManager.CopyProgressTotalTag]);
                    }
                    this.copyCompletionTime = RealServiceManager.ParseDateTimeFromString(nameValueCollection[RealServiceManager.CopyCompletionTimeTag]);
                }
                if (blobObject.ApplicationMetadata != null)
                {
                    this.metadata = new NameValueCollection();
                    try
                    {
                        MetadataEncoding.Decode(blobObject.ApplicationMetadata, this.metadata);
                    }
                    catch (MetadataFormatException metadataFormatException3)
                    {
                        MetadataFormatException metadataFormatException2 = metadataFormatException3;
                        CultureInfo             cultureInfo = CultureInfo.InvariantCulture;
                        object[] objArray1 = new object[] { this.blobName };
                        throw new NephosStorageDataCorruptionException(string.Format(cultureInfo, "Error decoding application metadata for blob {0}", objArray1), metadataFormatException2);
                    }
                }
                this.blobType = BlobTypeStrings.GetString(blobObject.Type);
                if (blobObject.LeaseInfo != null)
                {
                    if (blobObject.LeaseInfo.Type == LeaseType.ReadWrite && blobObject.LeaseInfo.Duration.HasValue)
                    {
                        TimeSpan?duration = blobObject.LeaseInfo.Duration;
                        TimeSpan zero     = TimeSpan.Zero;
                        if ((duration.HasValue ? duration.GetValueOrDefault() <= zero : true))
                        {
                            goto Label1;
                        }
                        this.leaseStatus = "locked";
                        goto Label0;
                    }
Label1:
                    this.leaseStatus = "unlocked";
Label0:
                    if (blobObject.LeaseInfo.State.HasValue)
                    {
                        this.leaseState = LeaseStateStrings.LeaseStates[(int)blobObject.LeaseInfo.State.Value];
                        if (blobObject.LeaseInfo.State.Equals(Microsoft.Cis.Services.Nephos.Common.Storage.LeaseState.Leased))
                        {
                            TimeSpan?nullable = blobObject.LeaseInfo.Duration;
                            TimeSpan timeSpan = TimeSpan.FromSeconds(4294967295);
                            if ((!nullable.HasValue ? true : nullable.GetValueOrDefault() != timeSpan))
                            {
                                this.leaseDuration = "fixed";
                            }
                            else
                            {
                                this.leaseDuration = "infinite";
                            }
                        }
                    }
                }
                this.snapshot = blobObject.Snapshot;
                if (blobObject.Type != Microsoft.Cis.Services.Nephos.Common.Storage.BlobType.IndexBlob)
                {
                    this.sequenceNumber = null;
                }
                else
                {
                    NephosAssertionException.Assert(blobObject.SequenceNumber.HasValue, "SequenceNumber must be present for PageBlob's.");
                    this.sequenceNumber = blobObject.SequenceNumber;
                }
                this.isBlobEncrypted   = blobObject.IsBlobEncrypted;
                this.isIncrementalCopy = blobObject.IsIncrementalCopy;
                if (this.isIncrementalCopy && nameValueCollection != null)
                {
                    this.lastCopySnapshot = RealServiceManager.ParseDateTimeFromString(nameValueCollection[RealServiceManager.LastCopySnapshotTag]);
                }
            }
        }