/// <summary>
        /// Obtain the connection string from Azure App Service.
        /// </summary>
        /// <param name="apiName">Name of the API.</param>
        /// <param name="subscriptionId">Azure subscription Id</param>
        /// <param name="location">Azure location to be used.</param>
        /// <param name="azureAdToken">Azure AD token to be used.</param>
        /// <returns>Connection string to be saved in the app setting and used for runtime calls</returns>
        public static async Task <string> GetApiHubProviderConnectionStringAsync(string apiName, string subscriptionId, string location, string azureAdToken)
        {
            var hub         = new ApiHubClient(subscriptionId, location, azureAdToken);
            var connections = await hub.GetConnectionsAsync(apiName);

            var connectionKey = await hub.GetConnectionKeyAsync(connections.First());

            var connectionString = hub.GetConnectionString(connectionKey.RuntimeUri, "Key", connectionKey.Key);

            return(connectionString);
        }
Example #2
0
        private static async Task GetConnectionKeyAsync(string aadToken)
        {
            var hub = new ApiHubClient(subscriptionId, location, aadToken);

            var connections = await hub.GetConnectionsAsync("dropbox");

            var connectionKey = await hub.GetConnectionKeyAsync(connections.First());

            var connectionString = hub.GetConnectionString(connectionKey.RuntimeUri, "Key", connectionKey.Key);

            await RunApiHubTests(connectionString);
        }
Example #3
0
        private static async Task ListAllApisAsync(string aadToken)
        {
            var hub = new ApiHubClient(subscriptionId, location, aadToken);

            // get all Managed APIs
            var apis = await hub.GetManagedApis();

            foreach (var managedApi in apis)
            {
                Console.WriteLine("Connections for {0}", managedApi.Name);
                Console.WriteLine("\tId:{0}", managedApi.Id);

                var connections = await hub.GetConnectionsAsync(managedApi.Name);

                foreach (var conn in connections)
                {
                    Console.WriteLine("\t\tName:{0}", conn.Name);
                }
            }
        }
Example #4
0
        private static async Task ReadFromWriteToSaasProvidersTestAsync(string aadToken, string source, string destination)
        {
            var hub = new ApiHubClient(subscriptionId, location, aadToken);

            var connections = await hub.GetConnectionsAsync(source);

            var connectionKey = await hub.GetConnectionKeyAsync(connections.First());

            var connectionString = hub.GetConnectionString(connectionKey.RuntimeUri, "Key", connectionKey.Key);
            var sourceRoot       = ItemFactory.Parse(connectionString);

            connections = await hub.GetConnectionsAsync(destination);

            connectionKey = await hub.GetConnectionKeyAsync(connections.First());

            connectionString = hub.GetConnectionString(connectionKey.RuntimeUri, "Key", connectionKey.Key);
            var destinationRoot = ItemFactory.Parse(connectionString);

            string fileName = "test/aaa.txt";

            var sourceFile = sourceRoot.GetFileReference(fileName);
            await sourceFile.WriteAsync(Encoding.Default.GetBytes(DateTime.Now.ToString()));

            var sourceContent = await sourceFile.ReadAsync();

            var destinationFile = destinationRoot.GetFileReference(fileName);
            await destinationFile.WriteAsync(sourceContent);

            var destinationContent = await destinationFile.ReadAsync();

            if ((Encoding.Default.GetString(sourceContent)).Equals((Encoding.Default.GetString(destinationContent))))
            {
                Console.WriteLine("Source and destination files match!");
            }
            else
            {
                Console.WriteLine("Error: Source and destination files do not match!");
            }
        }