Ejemplo n.º 1
0
 public AzureDriveInfo(Rule aliasRule, ProviderInfo providerInfo, PSCredential psCredential = null)
     : base(GetDriveInfo(aliasRule, providerInfo, psCredential))
 {
     Path = new Path {
         Account = aliasRule.HasProperty("key") ? aliasRule["key"].Value : aliasRule.Parameter,
         Container = aliasRule.HasProperty("container") ? aliasRule["container"].Value : "",
         SubPath = aliasRule.HasProperty("root") ? aliasRule["root"].Value.Replace('/', '\\').Replace("\\\\", "\\").Trim('\\') : "",
     };
     Path.Validate();
     Secret = aliasRule.HasProperty("secret") ? aliasRule["secret"].Value : psCredential != null ? psCredential.Password.ToString() : null;
 }
Ejemplo n.º 2
0
        public AzureLocation(AzureDriveInfo driveInfo, Path path, IListBlobItem cloudItem)
        {
            _driveInfo = driveInfo;
            Path = path;
            Path.Validate();

            if (cloudItem != null) {
                _cloudItem = new AsyncLazy<IListBlobItem>(() => cloudItem);
            } else {
                if (IsRootNamespace || IsAccount || IsContainer) {
                    // azure namespace mount.
                    _cloudItem = new AsyncLazy<IListBlobItem>(() => null);
                    return;
                }

                _cloudItem = new AsyncLazy<IListBlobItem>(() => {
                    if (CloudContainer == null) {
                        return null;
                    }
                    // not sure if it's a file or a directory.
                    if (path.EndsWithSlash) {
                        // can't be a file!
                        return CloudContainer.GetDirectoryReference(Path.SubPath);
                    }
                    // check to see if it's a file.
                    var blobRef = CloudContainer.GetBlobReference(Path.SubPath);
                    if (blobRef.Length > 0) {
                        return blobRef;
                    }

                    // well, we know it's not a file, container, or account.
                    // it could be a directory (but the only way to really know that is to see if there is any files that have this as a parent path)
                    var dirRef = CloudContainer.GetDirectoryReference(Path.SubPath);
                    if (dirRef.ListBlobs().Any()) {
                        return dirRef;
                    }

                    // it really didn't match anything, we'll return the reference to the blob in case we want to write to it.
                    return blobRef;
                });
                _cloudItem.InitializeAsync();
            }
        }
Ejemplo n.º 3
0
        private void Init(ProviderInfo provider, string root, PSCredential credential)
        {
            var parsedPath = Path.ParseWithContainer(root);

            if (string.IsNullOrEmpty(parsedPath.Account) || string.IsNullOrEmpty(parsedPath.Scheme)) {
                Path = parsedPath;
                return; // this is the root azure namespace.
            }

            var pi = provider as AzureProviderInfo;
            if (pi == null) {
                throw new CoAppException("Invalid ProviderInfo");
            }

            if (parsedPath.Scheme == ProviderScheme) {
                // it's being passed a full url to a blob storage
                Path = parsedPath;

                if (credential == null || credential.Password == null) {
                    // look for another mount off the same account and container for the credential
                    foreach (var d in pi.Drives.Select(each => each as AzureDriveInfo).Where(d => d.Account == Account && d.ContainerName == ContainerName)) {
                        Secret = d.Secret;
                        return;
                    }
                    // now look for another mount off just the same account for the credential
                    foreach (var d in pi.Drives.Select(each => each as AzureDriveInfo).Where(d => d.Account == Account)) {
                        Secret = d.Secret;
                        return;
                    }
                    throw new CoAppException("Missing credential information for {0} mount '{1}'".format(ProviderScheme, root));
                }
                Secret = credential.Password.ToString();
                return;
            }

            // otherwise, it's an sub-folder off of another mount.

            foreach (var d in pi.Drives.Select(each => each as AzureDriveInfo).Where(d => d.Name == parsedPath.Scheme)) {
                Path = new Path {
                    Account = d.Account,
                    Container = string.IsNullOrEmpty(d.ContainerName) ? parsedPath.Account : d.ContainerName,
                    SubPath = string.IsNullOrEmpty(d.RootPath) ? parsedPath.SubPath : d.RootPath + '\\' + parsedPath.SubPath
                };
                Path.Validate();
                Secret = d.Secret;
                return;
            }
        }
Ejemplo n.º 4
0
        public bool IsSubpath(Path childPath)
        {
            if (Parts.Length >= childPath.Parts.Length) {
                return false;
            }

            return !Parts.Where((t, i) => t != childPath.Parts[i]).Any();
        }