Example #1
0
 /// <summary>
 /// Uploads stream to remote path.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="sourceStream">The source stream.</param>
 /// <param name="remotePath">The remote target file path.</param>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// FilePath remoteFilePath = "/site/wwwroot/hello.txt";
 ///
 /// FilePath localFilePath = "./hello.txt";
 ///
 /// using(Stream sourceStream = kuduClient.FileSystem.GetFile(localFilePath).OpenRead())
 /// {
 ///     kuduClient.VFSUploadStream(sourceStream, remoteFilePath);
 /// }
 /// </code>
 /// </example>
 // ReSharper disable once InconsistentNaming
 public static void VFSUploadStream(
     this IKuduClient client,
     Stream sourceStream,
     FilePath remotePath)
 {
     client.UploadStream(sourceStream, remotePath, EncodeVFSPath);
 }
Example #2
0
        internal static void DownloadFile <T>(
            this IKuduClient client,
            T remotePath,
            FilePath localPath,
            Func <T, string> encodeRemotePathFunc)
            where T : Path
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (remotePath == null)
            {
                throw new ArgumentNullException(nameof(remotePath));
            }

            if (localPath == null)
            {
                throw new ArgumentNullException(nameof(localPath));
            }

            if (encodeRemotePathFunc == null)
            {
                throw new ArgumentNullException(nameof(encodeRemotePathFunc));
            }

            using (var localStream = client.FileSystem.GetFile(localPath).OpenWrite())
            {
                client.HttpGetToStream(
                    encodeRemotePathFunc(remotePath),
                    localStream);
            }
        }
Example #3
0
        internal static void UploadStream <T>(
            this IKuduClient client,
            Stream sourceStream,
            T remotePath,
            Func <T, string> encodeRemotePathFunc, // ReSharper disable once UnusedParameter.Global
            bool allowNullStream = false)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (!allowNullStream && sourceStream == null)
            {
                throw new ArgumentNullException(nameof(sourceStream));
            }

            if (remotePath == null)
            {
                throw new ArgumentNullException(nameof(remotePath));
            }

            client.HttpPutStream(
                encodeRemotePathFunc(remotePath),
                sourceStream);
        }
Example #4
0
        /// <summary>
        /// Executes an arbitrary command line and return its output.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <param name="command">The command to execute.</param>
        /// <param name="directory">The remote directory to execute command in.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns><see ref="KuduCommandResult"/></returns>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// IKuduCommandResult commandResult = kuduClient.ExecuteCommand(
        ///     "echo",
        ///     "D:/home/site/wwwroot",
        ///     "hello");
        ///
        /// Information(
        ///     "Output:\r\n{0}\r\nError:\r\n{1}\r\nExitCode: {2}",
        ///     commandResult.Output,
        ///     commandResult.Error,
        ///     commandResult.ExitCode);
        /// </code>
        /// </example>
        public static IKuduCommandResult ExecuteCommand(
            this IKuduClient client,
            string command,
            string directory,
            ProcessArgumentBuilder arguments = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (string.IsNullOrWhiteSpace(command))
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (string.IsNullOrWhiteSpace(directory))
            {
                throw new ArgumentNullException(nameof(directory));
            }

            var commandArgs = new ProcessArgumentBuilder().AppendQuoted(command);

            arguments?.CopyTo(commandArgs);

            var param = new
            {
                command = commandArgs.Render(),
                dir     = directory,
            };

            return(client.HttpPostJsonObject <object, KuduCommandResult>(
                       "/api/command",
                       param));
        }
Example #5
0
 /// <summary>
 /// Uploads file to remote path.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="localPath">The local source file path.</param>
 /// <param name="remotePath">The remote target file path.</param>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// FilePath remoteFilePath = "/site/wwwroot/hello.txt";
 ///
 /// FilePath localFilePath = "./hello.txt";
 ///
 /// kuduClient.VFSUploadFile(localFilePath, remoteFilePath);
 /// </code>
 /// </example>
 // ReSharper disable once InconsistentNaming
 public static void VFSUploadFile(
     this IKuduClient client,
     FilePath localPath,
     FilePath remotePath)
 {
     client.UploadFile(localPath, remotePath, EncodeVFSPath);
 }
Example #6
0
 /// <summary>
 /// Downloads remote file locally.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="remotePath">The remote source path.</param>
 /// <param name="localPath">The local target path.</param>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// FilePath remoteFilePath = "/site/wwwroot/hello.txt";
 ///
 /// FilePath localFilePath = "./hello.txt";
 ///
 /// kuduClient.VFSDownloadFile(remoteFilePath, localFilePath);
 /// </code>
 /// </example>
 // ReSharper disable once InconsistentNaming
 public static void VFSDownloadFile(
     this IKuduClient client,
     FilePath remotePath,
     FilePath localPath)
 {
     client.DownloadFile(remotePath, localPath, EncodeVFSPath);
 }
Example #7
0
 /// <summary>
 /// Uploads zip file to expand into remote directory path.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="localPath">The local source file path.</param>
 /// <param name="remotePath">The remote target directory path.</param>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// DirectoryPath sourceDirectoryPath = "./Documentation/";
 /// DirectoryPath remoteDirectoryPath = "/site/wwwroot/docs/";
 /// FilePath zipFilePath = "./Documentation.zip";
 ///
 /// Zip(sourceDirectoryPath, zipFilePath);
 ///
 /// kuduClient.ZipUploadFile(
 ///    zipFilePath,
 ///    remoteDirectoryPath);
 /// </code>
 /// </example>
 public static void ZipUploadFile(
     this IKuduClient client,
     FilePath localPath,
     DirectoryPath remotePath)
 {
     client.UploadFile(localPath, remotePath, EncodeZipPath);
 }
Example #8
0
 /// <summary>
 /// Downloads remote directory to local zip file.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="remotePath">The remote source path.</param>
 /// <param name="localPath">The local target path.</param>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// DirectoryPath remoteDirectoryPath = "/site/wwwroot/";
 /// FilePath localFilePath = "./wwwroot.zip";
 ///
 /// kuduClient.ZipDownloadFile(remoteDirectoryPath, localFilePath);
 /// </code>
 /// </example>
 public static void ZipDownloadFile(
     this IKuduClient client,
     DirectoryPath remotePath,
     FilePath localPath)
 {
     client.DownloadFile(remotePath, localPath, EncodeZipPath);
 }
Example #9
0
        /// <summary>
        /// Uploads stream to remote path.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <param name="sourceString">The source string.</param>
        /// <param name="remotePath">The remote target file path.</param>
        /// <param name="encoding">The text encoding.</param>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// string sourceString = "Hello";
        /// FilePath remoteFilePath = "/site/wwwroot/hello.txt";
        ///
        /// kuduClient.VFSUploadString(sourceString, remoteFilePath);
        /// </code>
        /// </example>
        // ReSharper disable once InconsistentNaming
        public static void VFSUploadString(
            this IKuduClient client,
            string sourceString,
            FilePath remotePath,
            Encoding encoding = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (sourceString == null)
            {
                throw new ArgumentNullException(nameof(sourceString));
            }

            if (remotePath == null)
            {
                throw new ArgumentNullException(nameof(remotePath));
            }

            client.HttpPutString(
                EncodeVFSPath(remotePath),
                sourceString,
                encoding);
        }
Example #10
0
 /// <summary>
 /// Deploy local directory to KuduWebsite as read only Zip file system
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="localPath">The local directory path.</param>
 /// <returns>The path of deployed Zip.</returns>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// DirectoryPath sourceDirectoryPath = "./Documentation/";
 ///
 /// FilePath deployFilePath = kuduClient.ZipRunFromDirectory(sourceDirectoryPath);
 ///
 /// Information("Deployed to {0}", deployFilePath);
 /// </code>
 /// </example>
 public static FilePath ZipRunFromDirectory(
     this IKuduClient client,
     DirectoryPath localPath)
 {
     return(client.ZipRunFromDirectory(
                skipPostDeploymentValidation: false,
                localPath: localPath));
 }
Example #11
0
 /// <summary>
 /// Downloads remote file as string.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="remotePath">The remote source path.</param>
 /// <param name="encoding">The text encoding.</param>
 /// <returns>Content as string.</returns>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// FilePath remoteFilePath = "/site/wwwroot/hello.txt";
 ///
 /// string resultString = kuduClient.VFSDownloadString(remoteFilePath);
 ///
 /// Information("Result: {0}", resultString);
 /// </code>
 /// </example>
 // ReSharper disable once InconsistentNaming
 public static string VFSDownloadString(
     this IKuduClient client,
     FilePath remotePath,
     Encoding encoding = null)
 {
     using (var reader = new StreamReader(client.VFSDownloadStream(remotePath), encoding ?? Encoding.UTF8))
     {
         return(reader.ReadToEnd());
     }
 }
Example #12
0
 /// <summary>
 /// Uploads zip stream and extracts to remote directory path.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="sourceStream">The source stream.</param>
 /// <param name="remotePath">The remote directory path.</param>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// DirectoryPath sourceDirectoryPath = "./Documentation/";
 /// DirectoryPath remoteDirectoryPath = "/site/wwwroot/docs/";
 /// FilePath zipFilePath = "./Documentation.zip";
 ///
 /// Zip(sourceDirectoryPath, zipFilePath);
 ///
 /// using(Stream sourceStream = kuduClient.FileSystem.GetFile(zipFilePath).OpenRead())
 /// {
 ///     kuduClient.ZipUploadStream(
 ///        sourceStream,
 ///        remoteDirectoryPath);
 /// }
 /// </code>
 /// </example>
 public static void ZipUploadStream(
     this IKuduClient client,
     Stream sourceStream,
     DirectoryPath remotePath)
 {
     client.UploadStream(
         sourceStream,
         remotePath,
         EncodeZipPath);
 }
Example #13
0
        /// <summary>
        /// Get settings from appservice.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <returns>The appservice settings.</returns>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// ReadOnlyDictionary&lt;string, string&gt; settings = kuduClient.SettingsGet();
        ///
        /// foreach(var setting in settings)
        /// {
        ///     Information(
        ///         "{0}={1}",
        ///         setting.Key,
        ///         setting.Value);
        /// }
        /// </code>
        /// </example>
        public static IReadOnlyDictionary <string, string> SettingsGet(
            this IKuduClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.HttpGetJsonObject <Dictionary <string, string> >(
                       "/api/settings"));
        }
Example #14
0
 /// <summary>
 /// Deploy local directory to KuduWebsite
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="localPath">The local directory path.</param>
 /// <remarks>This will zip the folder in-memory.</remarks>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// DirectoryPath sourceDirectoryPath = "./Documentation/";
 ///
 /// kuduClient.ZipDeployDirectory(
 ///     sourceDirectoryPath);
 /// </code>
 /// </example>
 public static void ZipDeployDirectory(
     this IKuduClient client,
     DirectoryPath localPath)
 {
     client.ZipDirectoryToMemoryStream(
         localPath,
         sourceStream =>
         client.HttpPostStream(
             "/api/zipdeploy",
             sourceStream));
 }
Example #15
0
 /// <summary>
 /// Uploads zip stream and extracts to remote directory path.
 /// </summary>
 /// <param name="client">The Kudu client.</param>
 /// <param name="localPath">The local directory path.</param>
 /// <param name="remotePath">The remote directory path.</param>
 /// <remarks>This will zip the folder in-memory.</remarks>
 /// <example>
 /// <code>
 /// #addin nuget:?package=Cake.Kudu.Client
 ///
 /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
 ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
 ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
 ///
 /// IKuduClient kuduClient = KuduClient(
 ///     baseUri,
 ///     userName,
 ///     password);
 ///
 /// DirectoryPath sourceDirectoryPath = "./Documentation/";
 /// DirectoryPath remoteDirectoryPath = "/site/wwwroot/docs/";
 ///
 /// kuduClient.ZipUploadDirectory(
 ///     sourceDirectoryPath,
 ///     remoteDirectoryPath);
 /// </code>
 /// </example>
 public static void ZipUploadDirectory(
     this IKuduClient client,
     DirectoryPath localPath,
     DirectoryPath remotePath)
 {
     client.ZipDirectoryToMemoryStream(
         localPath,
         sourceStream =>
         client.UploadStream(
             sourceStream,
             remotePath,
             EncodeZipPath));
 }
        internal static void HttpDelete(
            this IKuduClient client,
            string relativeUri)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            ProcessHttpClientAction(
                client,
                relativeUri,
                (httpClient, requestUri) => httpClient.DeleteAsync(requestUri),
                response => true);
        }
        internal static TOut HttpGetJsonObject <TOut>(
            this IKuduClient client,
            string relativeUri)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(ProcessHttpClientAction(
                       client,
                       relativeUri,
                       (httpClient, requestUri) => httpClient.GetAsync(requestUri),
                       JsonResponseToObject <TOut>));
        }
        internal static void HttpPutStream(
            this IKuduClient client,
            string relativeUri,
            Stream value)
        {
            if (relativeUri == null)
            {
                throw new ArgumentNullException(nameof(relativeUri));
            }

            ProcessHttpClientAction(
                client,
                relativeUri,
                (httpClient, requestUri) => httpClient.PutAsync(requestUri, value == null ? null : new StreamContent(value)),
                response => true);
        }
Example #19
0
        internal static void UploadFile <T>(
            this IKuduClient client,
            FilePath localPath,
            T remotePath,
            Func <T, string> encodeRemotePathFunc)
        {
            if (localPath == null)
            {
                throw new ArgumentNullException(nameof(localPath));
            }

            using (var localStream = client.FileSystem.GetFile(localPath).OpenRead())
            {
                client.UploadStream(localStream, remotePath, encodeRemotePathFunc);
            }
        }
Example #20
0
        // ReSharper disable once InconsistentNaming
        private static void VFSDelete(
            this IKuduClient client,
            Core.IO.Path remotePath)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (remotePath == null)
            {
                throw new ArgumentNullException(nameof(remotePath));
            }

            client.HttpDelete(EncodeVFSPath(remotePath));
        }
Example #21
0
        /// <summary>
        /// Delete setting from appservice.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <param name="key">The key of settings to delete.</param>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// kuduClient.SettingsDelete("FOO");
        /// </code>
        /// </example>
        public static void SettingsDelete(
            this IKuduClient client,
            string key)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            client.HttpDelete(
                $"/api/settings/{Uri.EscapeDataString(key)}");
        }
        private static TOut ProcessHttpClientAction <TOut>(
            this IKuduClient client,
            string relativeUri,
            Func <HttpClient, string, Task <HttpResponseMessage> > preFunc,
            Func <HttpResponseMessage, TOut> postFunc)
        {
            if (string.IsNullOrWhiteSpace(relativeUri))
            {
                throw new ArgumentNullException(nameof(relativeUri));
            }

            var requestUri = $"{client.Settings.BaseUri.TrimEnd('/')}/{relativeUri.TrimStart('/')}";
            var response   = preFunc(client.HttpClient, requestUri).GetAwaiter().GetResult();

            LogAndEnsureSuccessStatusCode(client.Log, response);
            return(postFunc(response));
        }
Example #23
0
        /// <summary>
        /// Deploys zip stream Kudu website.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <param name="sourceStream">The source stream.</param>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// DirectoryPath sourceDirectoryPath = "./Documentation/";
        /// FilePath zipFilePath = "./Documentation.zip";
        ///
        /// Zip(sourceDirectoryPath, zipFilePath);
        ///
        /// using(Stream sourceStream = kuduClient.FileSystem.GetFile(zipFilePath).OpenRead())
        /// {
        ///     kuduClient.ZipDeployStream(
        ///        sourceStream);
        /// }
        /// </code>
        /// </example>
        public static void ZipDeployStream(
            this IKuduClient client,
            Stream sourceStream)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (sourceStream == null)
            {
                throw new ArgumentNullException(nameof(sourceStream));
            }

            client.HttpPostStream(
                "/api/zipdeploy",
                sourceStream);
        }
Example #24
0
        /// <summary>
        /// Set settings to appservice.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <param name="settings">The settings to set.</param>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// var newSettings = new Dictionary&lt;string, string&gt;
        ///     {
        ///         { "FOO", "Bar" },
        ///         { "JOHN", "Doe" }
        ///     };
        ///
        /// kuduClient.SettingsSet(
        ///     newSettings);
        /// </code>
        /// </example>
        public static void SettingsSet(
            this IKuduClient client,
            IReadOnlyDictionary <string, string> settings)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            client.HttpPostJsonObject <object, IReadOnlyDictionary <string, string> >(
                "/api/settings",
                settings);
        }
Example #25
0
        /// <summary>
        /// Lists remote resources for a given path.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <param name="remotePath">The remote directory path.</param>
        /// <returns><see cref="IKuduVFS"/> instance containing remote directory and file paths.</returns>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// DirectoryPath remotePath = "/site/wwwroot";
        ///
        /// IKuduVFS kuduVFS = kuduClient.VFSList(remotePath);
        ///
        /// Information("Directories and files");
        /// foreach(IKuduPath path in kuduVFS.Entries)
        /// {
        ///     Information(
        ///         "Name: {0}, Size: {1}, Created: {2:yyyy-MM-dd HH:mm:ss}, Modified: {3:yyyy-MM-dd HH:mm:ss}, Mime: {4}",
        ///         path.Name,
        ///         path.Size,
        ///         path.Created,
        ///         path.Modified,
        ///         path.Mime);
        /// }
        ///
        /// Information("Directories");
        /// foreach(IKuduDirectoryPath directoryPath in kuduVFS.Directories)
        /// {
        ///     Information(
        ///         "Directory: {0}, Size: {1}, Created: {2:yyyy-MM-dd HH:mm:ss}, Modified: {3:yyyy-MM-dd HH:mm:ss}, Mime: {4}, Path: {5}",
        ///         directoryPath.Name,
        ///         directoryPath.Size,
        ///         directoryPath.Created,
        ///         directoryPath.Modified,
        ///         directoryPath.Mime,
        ///         directoryPath.Path);
        /// }
        ///
        /// Information("Files");
        /// foreach(IKuduFilePath filePath in kuduVFS.Files)
        /// {
        ///     Information(
        ///         "File: {0}, Size: {1}, Created: {2:yyyy-MM-dd HH:mm:ss}, Modified: {3:yyyy-MM-dd HH:mm:ss}, Mime: {4}, Path: {5}",
        ///         filePath.Name,
        ///         filePath.Size,
        ///         filePath.Created,
        ///         filePath.Modified,
        ///         filePath.Mime,
        ///         filePath.Path);
        /// }
        /// </code>
        /// </example>
        // ReSharper disable once InconsistentNaming
        public static IKuduVFS VFSList(
            this IKuduClient client,
            DirectoryPath remotePath)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (remotePath == null)
            {
                throw new ArgumentNullException(nameof(remotePath));
            }

            var paths = client.HttpGetJsonObject <KuduPath[]>(
                EncodeVFSPath(remotePath));

            return(KuduVFS.ToKuduVfs(remotePath, paths));
        }
        internal static TOut HttpPostJsonObject <TIn, TOut>(
            this IKuduClient client,
            string relativeUri,
            TIn value,
            string mediaType = "application/json")
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(ProcessHttpClientAction(
                       client,
                       relativeUri,
                       (httpClient, requestUri) => httpClient.PostAsync(
                           requestUri,
                           new StringContent(LitJson.JsonMapper.ToJson(value), Encoding.UTF8, mediaType)),
                       JsonResponseToObject <TOut>));
        }
        internal static void HttpGetToStream(
            this IKuduClient client,
            string relativeUri,
            Stream stream)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            ProcessHttpClientAction(
                client,
                relativeUri,
                (httpClient, requestUri) => httpClient.GetAsync(requestUri),
                response =>
            {
                response.Content.CopyToAsync(stream).GetAwaiter().GetResult();
                return(true);
            });
        }
        internal static Stream HttpGetStream(
            this IKuduClient client,
            string relativeUri)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(ProcessHttpClientAction(
                       client,
                       relativeUri,
                       (httpClient, requestUri) => httpClient.GetAsync(requestUri),
                       response =>
            {
                var ms = new MemoryStream();
                response.Content.CopyToAsync(ms).GetAwaiter().GetResult();
                ms.Position = 0;
                return ms;
            }));
        }
        internal static void HttpPutString(
            this IKuduClient client,
            string relativeUri,
            string value,
            Encoding encoding = null)
        {
            if (relativeUri == null)
            {
                throw new ArgumentNullException(nameof(relativeUri));
            }

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ProcessHttpClientAction(
                client,
                relativeUri,
                (httpClient, requestUri) => httpClient.PutAsync(requestUri, new StringContent(value, encoding ?? Encoding.UTF8)),
                response => true);
        }
Example #30
0
        /// <summary>
        /// Deploys zip file to Kudu wesite.
        /// </summary>
        /// <param name="client">The Kudu client.</param>
        /// <param name="localPath">The local source file path.</param>
        /// <example>
        /// <code>
        /// #addin nuget:?package=Cake.Kudu.Client
        ///
        /// string  baseUri     = EnvironmentVariable("KUDU_CLIENT_BASEURI"),
        ///         userName    = EnvironmentVariable("KUDU_CLIENT_USERNAME"),
        ///         password    = EnvironmentVariable("KUDU_CLIENT_PASSWORD");
        ///
        /// IKuduClient kuduClient = KuduClient(
        ///     baseUri,
        ///     userName,
        ///     password);
        ///
        /// DirectoryPath sourceDirectoryPath = "./Documentation/";
        /// FilePath zipFilePath = "./Documentation.zip";
        ///
        /// Zip(sourceDirectoryPath, zipFilePath);
        ///
        /// kuduClient.ZipDeployFile(
        ///    zipFilePath);
        /// </code>
        /// </example>
        public static void ZipDeployFile(
            this IKuduClient client,
            FilePath localPath)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (localPath == null)
            {
                throw new ArgumentNullException(nameof(localPath));
            }

            if (!client.FileSystem.Exist(localPath))
            {
                throw new FileNotFoundException("Could not find local file to deploy", localPath.FullPath);
            }

            using (var localStream = client.FileSystem.GetFile(localPath).OpenRead())
            {
                client.ZipDeployStream(localStream);
            }
        }