public static async Task <IHttpResponse> SendCollectionToPostman( [WorkflowParameterFromVariable(Value = EastFive.Azure.Workflows.MonitoringFlow.Variables.FolderName)] [QueryParameter(Name = FolderNamePropertyName)] string folderName, [OptionalQueryParameter(Name = WhenPropertyName)] DateTime?whenMaybe, IHttpRequest httpRequest, Security security, ContentTypeResponse <CollectionSummary> onPosted, GeneralFailureResponse onFailure) { //var postmanItems = await when // .StorageGetBy((MonitoringRequest mr) => mr.when) // .Where(mr => String.Equals(mr.folderName, folderName, StringComparison.CurrentCultureIgnoreCase)) // .Select(mr => mr.ConvertToPostmanItemAsync()) // .Await() // .ToArrayAsync(); var postmanItems = await folderName .StorageGetBy((MonitoringRequest mr) => mr.folderName) .Where(mr => whenMaybe.HasValue? whenMaybe.EqualToDay(mr.when) : true) .Select(mr => mr.ConvertToPostmanItemAsync()) .Await() .ToArrayAsync(); return(await Collection.CreateOrUpdateMonitoringCollectionAsync( $"MonitoringRequest - {folderName}", httpRequest.RequestUri, collectionToModify => { return collectionToModify .AppendItems(postmanItems, folderName: folderName); }, onCreatedOrUpdated : (collection) => onPosted(collection), why => onFailure(why))); }
public static async Task <IHttpResponse> SendToPostman( [QueryId] IRef <MonitoringRequest> monitoringRequestRef, [QueryParameter(Name = WhenPropertyName)] DateTime when, Security security, ContentTypeResponse <Meta.Postman.Resources.Collection.Item> onContent, NotFoundResponse onNotFound, GeneralFailureResponse onFailure) { return(await await monitoringRequestRef .StorageGetAsync( additionalProperties : (query) => query.Where(item => item.when == when), onFound : async itemToCreateOrUpdate => { var postmanItem = await itemToCreateOrUpdate.ConvertToPostmanItemAsync(); return await Collection.CreateOrUpdateMonitoringCollectionAsync( $"MonitoringRequest - {itemToCreateOrUpdate.when}", itemToCreateOrUpdate.url, collectionToModify => { return collectionToModify .AppendItem(postmanItem, folderName: itemToCreateOrUpdate.folderName); }, onCreatedOrUpdated: (discard) => onContent(postmanItem), onFailure: why => onFailure(why)); }, onDoesNotExists : () => onNotFound().AsTask())); }
public static async Task <IHttpResponse> DeleteAsync( [UpdateId(Name = AuthorizationIdPropertyName)] IRef <Authorization> authorizationRef, IProvideUrl urlHelper, AzureApplication application, NoContentResponse onLogoutComplete, AcceptedBodyResponse onExternalSessionActive, NotFoundResponse onNotFound, GeneralFailureResponse onFailure) { return(await authorizationRef.StorageUpdateAsync( async (authorizationToDelete, updateAsync) => { authorizationToDelete.deleted = DateTime.UtcNow; if (!authorizationToDelete.authorized) { return onLogoutComplete().AddReason("Deleted"); } var locationLogout = await await Auth.Method.ById(authorizationToDelete.Method, application, (authentication) => { return authentication.GetLogoutUrlAsync( application, urlHelper, authorizationRef.id); }, () => default(Uri).AsTask()); authorizationToDelete.LocationLogout = locationLogout; await updateAsync(authorizationToDelete); bool NoRedirectRequired() { if (locationLogout.IsDefaultOrNull()) { return true; } if (!locationLogout.IsAbsoluteUri) { return true; } if (locationLogout.AbsoluteUri.IsNullOrWhiteSpace()) { return true; } return false; } if (NoRedirectRequired()) { return onLogoutComplete().AddReason("Logout Complete"); } return onExternalSessionActive(authorizationToDelete, "application/json") .AddReason($"External session removal required:{locationLogout.AbsoluteUri}"); }, () => onNotFound())); }
public static async Task <IHttpResponse> ClearPostmanAsync( [WorkflowParameterFromVariable( Value = EastFive.Azure.Workflows.MonitoringFlow.Variables.FolderName, Disabled = true)] [OptionalQueryParameter(Name = TeamsNotification.CollectionPropertyName)] string collectionFolder, Security security, ContentTypeResponse <CollectionSummary> onCleared, NotFoundResponse onNotFound, GeneralFailureResponse onFailure) { return(await EastFive.Api.AppSettings.Postman.MonitoringCollectionId.ConfigurationString( async collectionId => { return await await EastFive.Api.Meta.Postman.Resources.Collection.Collection.GetAsync(collectionId, collection => { var collectionCleared = collectionFolder.HasBlackSpace() ? MutateCollectionWithFolderName(collectionFolder) : MutateCollection(); return collectionCleared.UpdateAsync <IHttpResponse>( (updatedCollection) => { return onCleared(updatedCollection); }, onFailure: (why) => onFailure(why)); Collection MutateCollection() { return new Collection { info = collection.info, item = new Item[] { }, variable = collection.variable, }; } Collection MutateCollectionWithFolderName(string folderName) { collection.item = collection.item .NullToEmpty() .Where(item => !collectionFolder.Equals(item.name)) .ToArray(); return collection; } }, () => onNotFound().AsTask(), onFailure: why => onFailure(why).AsTask()); }, onUnspecified : (why) => onFailure("Postman Monitoring not setup").AsTask())); }
public override Task <IHttpResponse> InstigateInternal(IApplication httpApp, IHttpRequest request, ParameterInfo parameterInfo, Func <object, Task <IHttpResponse> > onSuccess) { GeneralFailureResponse responseDelegate = (why) => { var response = request.CreateResponse(StatusCode); if (why.IsDefaultNullOrEmpty()) { return(UpdateResponse(parameterInfo, httpApp, request, response)); } return(UpdateResponse(parameterInfo, httpApp, request, response.AddReason(why))); }; return(onSuccess(responseDelegate)); }
public static async Task <HttpResponseMessage> PostLoginAsync( Guid authenticationId, HttpApplication application, UrlHelper urlHelper, RedirectResponse onRedirect, GeneralFailureResponse onFailure) { return(EastFive.Security.RSA.FromConfig(EastFive.Azure.AppSettings.AdminLoginRsaKey, rsa => { using (rsa) { var authenticationIdBytes = authenticationId.ToByteArray(); var signedBytes = rsa.SignData(authenticationIdBytes, CryptoConfig.MapNameToOID("SHA512")); var redirectUrl = urlHelper.GetLocation <AdminLoginRedirection>( adminLoginRedir => adminLoginRedir.authenticationId.AssignQueryValue(authenticationId), adminLoginRedir => adminLoginRedir.token.AssignQueryValue(signedBytes), application); return onRedirect(redirectUrl); } }, (why) => onFailure(why))); }
public static Task <HttpResponseMessage> GetRedirection( [QueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey, [QueryParameter(Name = "authorization")] IRef <Authorization> authRef, ApiSecurity apiSecurity, AzureApplication application, HttpRequestMessage request, RedirectResponse onRedirection, GeneralFailureResponse onFailure, UnauthorizedResponse onUnauthorized, ConfigurationFailureResponse onConfigFailure) { return(authRef.StorageUpdateAsync( async(authorization, saveAsync) => { var url = await await Method.ById(authorization.Method, application, async method => { return await await method.ParseTokenAsync(authorization.parameters, application, async(externalId, loginProvider) => { var tag = "OpioidTool"; return await EastFive.Web.Configuration.Settings.GetString($"AffirmHealth.PDMS.PingRedirect.{tag}.PingAuthName", async pingAuthName => { return await EastFive.Web.Configuration.Settings.GetGuid($"AffirmHealth.PDMS.PingRedirect.{tag}.PingReportSetId", reportSetId => { var requestParams = authorization.parameters .AppendIf("PingAuthName".PairWithValue(pingAuthName), !authorization.parameters.ContainsKey("PingAuthName")) .AppendIf("ReportSetId".PairWithValue(reportSetId.ToString()), !authorization.parameters.ContainsKey("ReportSetId")) .ToDictionary(); return Auth.Redirection.ProcessAsync(authorization, updatedAuth => 1.AsTask(), method, externalId, requestParams, Guid.NewGuid(), request.RequestUri, application, loginProvider, (uri) => { return uri; }, (why) => default(Uri), application.Telemetry); }, why => { return default(Uri).AsTask(); }); }, why => { return default(Uri).AsTask(); }); }, (why) => default(Uri).AsTask()); }, () => default(Uri).AsTask()); if (url.IsDefaultOrNull()) { return onFailure("Failed to determine correct redirect URL"); } authorization.expired = false; await saveAsync(authorization); return onRedirection(url); })); }