Пример #1
0
 public static IContainer CreateContainerInstance(this IStorageManager storageManager, string accountName, string containerName, ServiceType serviceType)
 {
     if (serviceType == ServiceType.BlobService)
     {
         return(storageManager.CreateBlobContainerInstance(accountName, containerName));
     }
     NephosAssertionException.Fail("Invalid service type {0}.", new object[] { serviceType });
     return(null);
 }
Пример #2
0
        protected internal override IEnumerable <IAsyncResult> AuthorizePublicAccess(AsyncIteratorContext <AuthorizationResult> context, AuthorizationResult authorizationResult, IStorageManager storageManager, string resourceAccount, string resourceContainer, string resourceIdentifier, IAccountIdentifier requestor, PermissionLevel permission, Duration d, TimeSpan timeout)
        {
            using (IBlobContainer blobContainer = storageManager.CreateBlobContainerInstance(resourceAccount, resourceContainer))
            {
                blobContainer.Timeout = d.Remaining(timeout);
                IAsyncResult asyncResult = blobContainer.BeginGetProperties(ContainerPropertyNames.ServiceMetadata, null, context.GetResumeCallback(), context.GetResumeState("NephosAuthorizationManager.AuthorizeRequestImpl"));
                yield return(asyncResult);

                try
                {
                    blobContainer.EndGetProperties(asyncResult);
                }
                catch (ContainerNotFoundException containerNotFoundException)
                {
                    throw new ContainerUnauthorizedException(resourceAccount, resourceContainer, resourceIdentifier, requestor, permission, containerNotFoundException);
                }
                catch (ServerBusyException serverBusyException)
                {
                    Logger <IRestProtocolHeadLogger> .Instance.ErrorDebug.Log("Got ServerBusy while trying to get container Acl settings during Authorization so not continuing");

                    throw;
                }
                catch (TimeoutException timeoutException)
                {
                    Logger <IRestProtocolHeadLogger> .Instance.ErrorDebug.Log("Request timed out while trying to get container Acl settings during Authorization so not continuing");

                    throw;
                }
                catch (StorageManagerException storageManagerException1)
                {
                    StorageManagerException storageManagerException = storageManagerException1;
                    IStringDataEventStream  verboseDebug            = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                    verboseDebug.Log("Got and swallowed exception when accessing acl setting for authorization: {0}", new object[] { storageManagerException });
                    authorizationResult.FailureReason = AuthorizationFailureReason.AccessPermissionFailure;
                    authorizationResult.Authorized    = false;
                    context.ResultData = authorizationResult;
                    goto Label0;
                }
                string str = (new ContainerAclSettings(blobContainer.ServiceMetadata)).PublicAccessLevel;
                if (!string.IsNullOrEmpty(str))
                {
                    if (string.IsNullOrEmpty(resourceIdentifier))
                    {
                        if (Comparison.StringEqualsIgnoreCase(str, "container") || Comparison.StringEqualsIgnoreCase(str, bool.TrueString))
                        {
                            authorizationResult.FailureReason = AuthorizationFailureReason.NotApplicable;
                            authorizationResult.Authorized    = true;
                            context.ResultData = authorizationResult;
                            goto Label0;
                        }
                    }
                    else if (Comparison.StringEqualsIgnoreCase(str, "blob") || Comparison.StringEqualsIgnoreCase(str, "container") || Comparison.StringEqualsIgnoreCase(str, bool.TrueString))
                    {
                        authorizationResult.FailureReason = AuthorizationFailureReason.NotApplicable;
                        authorizationResult.Authorized    = true;
                        context.ResultData = authorizationResult;
                        goto Label0;
                    }
                    authorizationResult.FailureReason = AuthorizationFailureReason.AccessPermissionFailure;
                    authorizationResult.Authorized    = false;
                    context.ResultData = authorizationResult;
                }
                else
                {
                    authorizationResult.FailureReason = AuthorizationFailureReason.AccessPermissionFailure;
                    authorizationResult.Authorized    = false;
                    context.ResultData = authorizationResult;
                }
            }
Label0:
            yield break;
        }