示例#1
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            var    azureToken      = request.DataStore.GetJson("AzureToken", "access_token");
            string environmentId   = request.DataStore.GetValue("PowerAppEnvironment");
            string sqlConnectionId = request.DataStore.GetValue("PowerAppSqlConnectionId");

            try
            {
                if (environmentId != null && sqlConnectionId != null)
                {
                    ActionResponse wrangledFile = await RequestUtility.CallAction(request, "Microsoft-WranglePowerApp");

                    if (wrangledFile.IsSuccess && wrangledFile.Body != null)
                    {
                        string path = wrangledFile.Body.ToString();

                        AzureHttpClient ahc = new AzureHttpClient(azureToken);

                        PowerAppResourceStorage resourceStorage = await ahc.Request <PowerAppResourceStorage>(HttpMethod.Post,
                                                                                                              string.Format(PowerAppUtility.URL_POWERAPPS_GENERATE_RESOURCE_STORAGE, JsonUtility.GetWebToken(azureToken, "oid")),
                                                                                                              JsonUtility.Serialize <PowerAppEnvironmentWrapper>(new PowerAppEnvironmentWrapper(environmentId)));

                        if (!string.IsNullOrEmpty(path) && resourceStorage != null && !string.IsNullOrEmpty(resourceStorage.SharedAccessSignature))
                        {
                            string uri = resourceStorage.SharedAccessSignature.Replace("?", "/document.msapp?");

                            CloudBlockBlob blob = new CloudBlockBlob(new Uri(uri));

                            using (WebClient wc = new WebClient())
                            {
                                byte[] file = wc.DownloadData(path);

                                await blob.UploadFromStreamAsync(new MemoryStream(file));

                                PowerAppMetadata metadata = await ahc.Request <PowerAppMetadata>(HttpMethod.Post, PowerAppUtility.URL_POWERAPPS_PUBLISH_APP,
                                                                                                 JsonUtility.Serialize <PowerAppPublish>(new PowerAppPublish(uri, $"TwitterTemplate{RandomGenerator.GetDateStamp()}", environmentId, sqlConnectionId)));

                                if (metadata != null)
                                {
                                    if (await ahc.IsSuccess(HttpMethod.Post, string.Format(PowerAppUtility.URL_POWERAPPS_SQL_CONNECTION_UPDATE, sqlConnectionId, environmentId),
                                                            JsonUtility.Serialize <PowerAppSqlConnectionUpdate>(new PowerAppSqlConnectionUpdate(metadata.Name))))
                                    {
                                        if (await ahc.IsSuccess(HttpMethod.Post, string.Format(PowerAppUtility.URL_POWERAPPS_RECORD_SCOPES_CONSENT, metadata.Name), JsonUtility.Serialize <PowerAppConsents>(new PowerAppConsents(sqlConnectionId))))
                                        {
                                            request.DataStore.AddToDataStore("PowerAppUri", string.Format(PowerAppUtility.URL_POWERAPPS_WEB, metadata.Name));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                PowerAppUtility.SkipPowerApp(request.DataStore);
            }

            return(new ActionResponse(ActionStatus.Success));
        }
        // Exports an Activity Log for the given subscription to Event Hub
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            string apiVersion    = "2016-03-01";
            string ehnamespace   = request.DataStore.GetValue("ActivityLogNamespace");
            string resourceGroup = request.DataStore.GetValue("SelectedResourceGroup");
            string subscription  = request.DataStore.GetJson("SelectedSubscription", "SubscriptionId");
            string token         = request.DataStore.GetJson("AzureToken", "access_token");

            string body = $"{{\"id\":null,\"location\":null,\"name\":null,\"properties\":{{\"categories\":[\"Write\",\"Delete\",\"Action\"],\"storageAccountId\":null,\"locations\":[\"australiaeast\",\"australiasoutheast\",\"brazilsouth\",\"canadacentral\",\"canadaeast\",\"centralindia\",\"centralus\",\"eastasia\",\"eastus\",\"eastus2\",\"japaneast\",\"japanwest\",\"koreacentral\",\"koreasouth\",\"northcentralus\",\"northeurope\",\"southcentralus\",\"southindia\",\"southeastasia\",\"uksouth\",\"ukwest\",\"westcentralus\",\"westeurope\",\"westindia\",\"westus\",\"westus2\",\"global\"],\"retentionPolicy\":{{\"enabled\":false,\"days\":0}},\"serviceBusRuleId\":\"/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.EventHub/namespaces/{ehnamespace}/authorizationrules/RootManageSharedAccessKey\"}},\"tags\":null}}";
            string uri  = $"https://management.azure.com/subscriptions/{subscription}/providers/microsoft.insights/logprofiles/default?api-version={apiVersion}";

            AzureHttpClient ahc = new AzureHttpClient(token, subscription);

            bool isSuccess = await ahc.IsSuccess(HttpMethod.Put, uri, body);

            for (int i = 0; i < ATTEMPTS && !isSuccess; i++)
            {
                Thread.Sleep(WAIT);
                isSuccess = await ahc.IsSuccess(HttpMethod.Put, uri, body);
            }

            string logProfileError = string.Empty;

            if (!isSuccess)
            {
                logProfileError = await ahc.Test(HttpMethod.Put, uri);
            }

            return(isSuccess
                ? new ActionResponse(ActionStatus.Success)
                : new ActionResponse(ActionStatus.Failure, new ActionResponseExceptionDetail("ActivityLogsErrorExportingToEventHub", logProfileError)));
        }
示例#3
0
        public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request)
        {
            string powerAppEnvironmentId = request.DataStore.GetValue("PowerAppEnvironment");

            if (powerAppEnvironmentId != null)
            {
                AzureHttpClient ahc = new AzureHttpClient(request.DataStore.GetJson("AzureToken", "access_token"));

                string newSqlConnectionId  = RandomGenerator.GetRandomHexadecimal(PowerAppUtility.SQL_CONNECTION_ID_LENGTH);
                string sqlConnectionString = request.DataStore.GetValueAtIndex("SqlConnectionString", "SqlServerIndex");

                SqlCredentials sqlCredentials = SqlUtility.GetSqlCredentialsFromConnectionString(sqlConnectionString);

                PowerAppSqlConnection powerAppSqlConnection = new PowerAppSqlConnection(sqlCredentials, powerAppEnvironmentId);

                string body = JsonUtility.Serialize <PowerAppSqlConnection>(powerAppSqlConnection);
                string url  = string.Format(PowerAppUtility.URL_POWERAPPS_SQL_CONNECTION, newSqlConnectionId, powerAppEnvironmentId);

                if (await ahc.IsSuccess(HttpMethod.Put, url, body))
                {
                    request.DataStore.AddToDataStore("PowerAppSqlConnectionId", newSqlConnectionId, DataStoreType.Private);
                }
                else
                {
                    PowerAppUtility.SkipPowerApp(request.DataStore);
                }
            }

            return(new ActionResponse(ActionStatus.Success));
        }