public async static Task <IHttpResponse> UpdateAsync( [UpdateId(Name = AuthorizationIdPropertyName)] IRef <Authorization> authorizationRef, [Property(Name = LocationLogoutReturnPropertyName)] Uri locationLogoutReturn, EastFive.Api.SessionToken?securityMaybe, NoContentResponse onUpdated, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { return(await authorizationRef.StorageUpdateAsync( async (authorization, saveAsync) => { if (authorization.deleted.HasValue) { return onNotFound(); } if (authorization.authorized) { authorization.LocationAuthentication = default(Uri); if (!securityMaybe.HasValue) { return onUnauthorized(); } } authorization.LocationLogoutReturn = locationLogoutReturn; await saveAsync(authorization); return onUpdated(); }, () => onNotFound())); }
public async static Task <IHttpResponse> GetByIdAsync( [QueryParameter(Name = IntegrationIdPropertyName)] IRef <XIntegration> integrationRef, IAuthApplication application, SessionToken security, ContentTypeResponse <XIntegration> onFound, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { if (!security.accountIdMaybe.HasValue) { return(onUnauthorized()); } var accountId = security.accountIdMaybe.Value; return(await await integrationRef.StorageGetAsync( integration => { return Auth.Method.ById(integration.Method, application, method => { integration.methodName = method.name; return onFound(integration); }, () => onNotFound()); }, () => onNotFound().AsTask())); }
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 IHttpResponse ListFlows( [OptionalQueryParameter] string flow, [OptionalQueryParameter] string collections, [OptionalQueryParameter] bool?preferJson, //Security security, IInvokeApplication invokeApplication, HttpApplication httpApp, IHttpRequest request, IProvideUrl url, ContentTypeResponse <string []> onSuccess, NotFoundResponse onNotFound) { var lookups = httpApp .GetResources() .ToArray(); var manifest = new EastFive.Api.Resources.Manifest(lookups, httpApp); var flows = manifest.Routes .SelectMany(route => route.Methods) .SelectMany(method => method.MethodPoco .GetAttributesInterface <IDefineFlow>(multiple: true) .Select(attr => (method, attr))) .GroupBy(methodAndFlow => methodAndFlow.attr.FlowName) .Where(grp => grp.Key.HasBlackSpace()) .Select(grp => grp.Key) .ToArray(); return(onSuccess(flows)); }
public void NotFoundResponse() { var response = new NotFoundResponse("application/json"); response.ContentType.Should().Be("application/json"); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public static async Task <IHttpResponse> PropertyInformation( [QueryParameter(Name = "table")] string tableName, [QueryParameter(Name = "property")] string propertyName, IApplication httpApp, ContentTypeResponse <PropertyLookupInformation[]> onFound, NotFoundResponse onNotFound, BadRequestResponse onPropertyDoesNotSupportFindBy) { return(await StorageTable.DiscoverStorageResources(httpApp.GetType()) .Where(table => table.name == tableName) .First( (storageTable, next) => { return storageTable.properties .Where(prop => prop.name == propertyName) .First( async(prop, next2) => { if (!prop.member.ContainsAttributeInterface <IProvideFindBy>()) { return onPropertyDoesNotSupportFindBy(); } var findBy = prop.member.GetAttributeInterface <IProvideFindBy>(); var information = await findBy.GetInfoAsync(prop.member); return onFound(information); }, () => onNotFound().AsTask()); }, () => onNotFound().AsTask())); }
public static async Task <IHttpResponse> FindByIdAsync( [QueryParameter(CheckFileName = true)] Guid processStageTypeId, EastFive.Api.Security security, ContentResponse onFound, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { return(await await ProcessStageTypes.FindAllAsync(security, types => types.First( async(stage, next) => { if (stage.processStageTypeId == processStageTypeId) { return onFound(stage); } return await next(); }, () => onNotFound().ToTask()), () => onUnauthorized().ToTask())); //return Connectors.FindByIdAsync(id, // security.performingAsActorId, security.claims, // (synchronization, destinationIntegrationId) => onFound(GetResource(synchronization, destinationIntegrationId, url)), // () => onNotFound(), // () => onUnauthorized()); }
public static async Task <IHttpResponse> GetAsync( [QueryParameter(Name = SessionIdPropertyName, CheckFileName = true)] IRef <Session> sessionRef, EastFive.Api.SessionTokenMaybe security, IAuthApplication application, ContentTypeResponse <Session> onFound, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized, ConfigurationFailureResponse onConfigurationFailure) { if (!IsAnonSessionAllowed()) { if (security.sessionId != sessionRef.id) { return(onUnauthorized()); } } return(await await sessionRef.StorageGetAsync( (session) => { return Web.Configuration.Settings.GetUri( EastFive.Security.AppSettings.TokenScope, scope => { return Web.Configuration.Settings.GetDouble(Security.SessionServer.Configuration.AppSettings.TokenExpirationInMinutes, (tokenExpirationInMinutes) => { return GetClaimsAsync(application, session.authorization, (claims, accountIdMaybe, authorized) => { session.account = accountIdMaybe; session.authorized = authorized; return Api.Auth.JwtTools.CreateToken(session.id, scope, TimeSpan.FromMinutes(tokenExpirationInMinutes), claims, (tokenNew) => { session.token = tokenNew; return onFound(session); }, (missingConfig) => onConfigurationFailure("Missing", missingConfig), (configName, issue) => onConfigurationFailure(configName, issue)); }, (why) => onNotFound()); }, (why) => onConfigurationFailure("Missing", why).AsTask()); }, (why) => onConfigurationFailure("Missing", why).AsTask()); }, () => onNotFound().AsTask())); bool IsAnonSessionAllowed() { var appType = application.GetType(); if (!appType.TryGetAttributeInterface <IConfigureAuthorization>(out IConfigureAuthorization authConfig)) { return(false); } return(authConfig.IsAnonymousSessionAllowed); } }
public void DefaultNotFoundResponse() { var response = new NotFoundResponse(); response.ContentType.Should().Be("text/html"); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public static async Task <IHttpResponse> QuerySubImageByContentIdAsync( [QueryParameter(CheckFileName = true, Name = ContentIdPropertyName)] Guid contentId, [QueryParameter(Name = XPropertyName)] int x, [QueryParameter(Name = YPropertyName)] int y, [QueryParameter(Name = WPropertyName)] int w, [QueryParameter(Name = HPropertyName)] int h, [OptionalQueryParameter] int?width, [OptionalQueryParameter] int?height, [OptionalQueryParameter] bool?fill, ImageResponse imageResponse, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { var response = await EastFive.Api.Azure.Content.FindContentByContentIdAsync(contentId, (contentType, imageData) => { var image = System.Drawing.Image.FromStream(new MemoryStream(imageData)); var newImage = image .Crop(x, y, w, h) .Scale(width, height, fill); return(imageResponse(newImage, filename: contentId.ToString("N"), contentType: contentType)); }, () => onNotFound(), () => onUnauthorized()); return(response); }
public async static Task <HttpResponseMessage> XlsPostAsync(EastFive.Security.SessionServer.Context context, ContentBytes sheet, [QueryParameter] Guid integration, IDictionary <string, bool> resourceTypes, HttpRequestMessage request, System.Web.Http.Routing.UrlHelper url, RedirectResponse onSuccess, NotFoundResponse onNotFound, GeneralConflictResponse onError) { var sheetId = Guid.NewGuid(); return(await await context.Integrations.UpdateAsync(integration, sheet.content.MD5HashGuid().ToString("N"), new Dictionary <string, string>() { { "resource_types", resourceTypes.SelectKeys().Join(",") }, { "sheet_id", sheetId.ToString("N") }, }, (redirectUrl) => { return EastFive.Api.Azure.Credentials.Sheets.SaveAsync(sheetId, sheet.contentType.MediaType, sheet.content, integration, context.DataContext, () => onSuccess(redirectUrl), "Guid not unique".AsFunctionException <HttpResponseMessage>()); }, () => onNotFound().ToTask(), () => onError("The provided integration ID has not been connected to an authorization.").ToTask())); }
public static IHttpResponse Get( ContentResponse onSuccess, NotFoundResponse onNotFound) { return(EastFive.Azure.AppSettings.Apple.AppleAppSiteAssociationId.ConfigurationString( (appId) => { var content = new { applinks = new { apps = new string[] { }, details = new object[] { new { appID = appId, paths = new string [] { "*" }, } } } }; return onSuccess(content); }, (why) => onNotFound().AddReason(why))); }
public static async Task <HttpResponseMessage> GetAllSecureAsync( [QueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey, [QueryParameter(Name = "authorization")] IRef <Authorization> authorizationRef, ApiSecurity apiSecurity, AzureApplication application, HttpRequestMessage request, MultipartResponseAsync <Authorization> onContent, RedirectResponse onSuccess, NotFoundResponse onNotFound, ForbiddenResponse onFailure) { return(await await authorizationRef.StorageGetAsync( async authorization => { return await await Method.ById(authorization.Method, application, async method => { return await await method.ParseTokenAsync(authorization.parameters, application, (externalId, loginProvider) => { return Auth.Redirection.ProcessAsync(authorization, async updatedAuth => { }, method, externalId, authorization.parameters, Guid.NewGuid(), request.RequestUri, application, loginProvider, (uri) => onSuccess(uri), (why) => onFailure().AddReason(why), application.Telemetry); }, why => onFailure().AddReason(why).AsTask()); }, () => onFailure().AddReason("Method no longer supported").AsTask()); }, () => onNotFound().AsTask())); }
public static Task <IHttpResponse> UpdateProcessStepAsync( [QueryParameter(Name = ProcessStep.IdPropertyName, CheckFileName = true)] Guid processId, [PropertyOptional(Name = ProcessStep.ConfirmedByPropertyName)] Guid?confirmedById, [PropertyOptional(Name = ProcessStep.ConfirmedWhenPropertyName)] DateTime?confirmedWhen, [PropertyOptional(Name = ProcessStep.ResourceKeysPropertyName)] string[] resourceKeys, [PropertyOptional(Name = ProcessStep.ResourcesPropertyName)] Guid[] resources, EastFive.Api.Security security, IProvideUrl url, NoContentResponse onUpdated, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(EastFive.Azure.Processes.UpdateAsync(processId, confirmedById, confirmedWhen, resourceKeys.NullToEmpty().Zip(resources.NullToEmpty(), (k, id) => k.PairWithValue(id)).ToArray(), security, () => onUpdated(), () => onNotFound(), () => onUnauthorized(), (why) => onFailure(why))); //return Connectors.UpdateConnectorAsync(id, // Flow, security.performingAsActorId, security.claims, // () => onUpdated(), // () => onNotFound(), // (why) => onFailure(why)); }
public static Task <IHttpResponse> QueryByIdAsync( [QueryId(Name = IdPropertyName)] IRef <Profile> profileRef, ContentTypeResponse <Profile> onFound, NotFoundResponse onNotFound) { return(profileRef.HttpGetAsync(onFound, onNotFound)); }
public static Task <IHttpResponse> DownloadAsync( StreamResponse onFound, NotFoundResponse onNotFound) { return(SpaHandler.LoadSpaFile( (blobStream) => onFound(blobStream), () => onNotFound())); }
public static Task <IHttpResponse> GetByIdAsync( [QueryId] IRef <InvocationMessage> invocationMessageRef, ContentTypeResponse <InvocationMessage> onFound, NotFoundResponse onNotFound) { return(invocationMessageRef.StorageGetAsync( (InvocationMessage ent) => onFound(ent), () => onNotFound())); }
public static Task <IHttpResponse> HttpDeleteAsync <TResource>( this IRef <TResource> resourceRef, NoContentResponse onDeleted, NotFoundResponse onNotFound) where TResource : IReferenceable { return(resourceRef.StorageDeleteAsync( onDeleted: (discard) => onDeleted(), () => onNotFound())); }
private IActionResult Response <T>(IResponseModel <T> result) where T : class { return(result switch { SuccessResponse <T> _ => Ok(result), NotFoundResponse <T> _ => NotFound(result), BadRequestResponse <T> _ => BadRequest(result), InternalError <T> _ => StatusCode(500, result), _ => NotFound() });
public static Task <IHttpResponse> DeleteByIdAsync( [WorkflowParameter(Value = "{{TeamsNotification_}}")] [UpdateId(Name = IdPropertyName)] IRef <TeamsNotification> teamsNotificationId, NoContentResponse onDeleted, NotFoundResponse onNotFound) { return(teamsNotificationId.HttpDeleteAsync( onDeleted, onNotFound)); }
public static Task <HttpResponseMessage> QueryByIdAsync( [QueryId] IRef <Method> methodRef, Api.Azure.AzureApplication application, ContentTypeResponse <Method> onFound, NotFoundResponse onNotFound) { return(ById(methodRef, application, method => onFound(method), () => onNotFound())); }
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 ActionResult <Customer> Get(int id) { Customer customer = _repository.Get(id); if (customer == null) { return(NotFound(NotFoundResponse.Create <Customer>(id))); } return(Ok(customer)); }
public static Task <HttpResponseMessage> FindByIdAsync( [QueryParameter(CheckFileName = true, Name = "id")] Guid adapterId, Security security, Context context, HttpRequestMessage request, UrlHelper url, ContentResponse onFound, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { return(EastFive.Azure.Synchronization.Connections.FindAdapterByIdAsync(adapterId, (adapter) => onFound(GetResource(adapter, url)), () => onNotFound())); }
public ActionResult <Order> Get(int id) { Order order = _repository.Get(id); if (order == null) { return(NotFound(NotFoundResponse.Create <Order>(id))); } return(Ok(order)); }
public static Task <HttpResponseMessage> DeleteByIdAsync( [QueryParameter(CheckFileName = true, Name = ResourceBase.IdPropertyName)] Guid synchronizationId, Security security, Context context, HttpRequestMessage request, UrlHelper url, ContentResponse onFound, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { return(Connectors.DeleteByIdAsync(synchronizationId, security.performingAsActorId, security.claims, () => onFound(true), () => onNotFound())); }
public static Task <IHttpResponse> DeleteAsync( [UpdateId(Name = SessionIdPropertyName)] IRef <Session> sessionRef, NoContentResponse onDeleted, NotFoundResponse onNotFound) { return(sessionRef.StorageDeleteAsync( onDeleted: (discard) => { return onDeleted(); }, onNotFound: () => onNotFound())); }
public static Task <IHttpResponse> DeleteByIdAsync( [QueryParameter(CheckFileName = true, Name = ProcessStep.IdPropertyName)] Guid processStepId, EastFive.Api.Security security, NoContentResponse onDeleted, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { return(EastFive.Azure.Processes.DeleteByIdAsync(processStepId, security, () => onDeleted(), () => onNotFound(), () => onUnauthorized())); }
public static Task <IHttpResponse> QueryByContentIdAsync( [QueryParameter(CheckFileName = true, Name = ContentIdPropertyName)] Guid contentId, [OptionalQueryParameter] int?width, [OptionalQueryParameter] int?height, [OptionalQueryParameter] bool?fill, [OptionalQueryParameter] string renderer, BytesResponse onRawResponse, ImageRawResponse onImageResponse, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { var response = EastFive.Api.Azure.Content.FindContentByContentIdAsync(contentId, (contentType, image) => { if (renderer.HasBlackSpace()) { if (renderer.ToLower() == "unzip") { using (var compressedStream = new MemoryStream(image)) using (var zipStream = new System.IO.Compression.ZipArchive(compressedStream, ZipArchiveMode.Read)) using (var resultStream = new MemoryStream()) { var zipFile = zipStream.Entries.First(); zipFile.Open().CopyTo(resultStream); var data = resultStream.ToArray(); return(onRawResponse(data, contentType: "application/object", filename: zipFile.Name)); //return request.CreateFileResponse(data, "application/object", filename: zipFile.Name); } } } //if (contentType.StartsWith("video", StringComparison.InvariantCultureIgnoreCase) && // (width.HasValue || height.HasValue || fill.HasValue)) //{ // var videoPreviewImage = default(System.Drawing.Image); // Properties.Resources.video_preview; // return request.CreateImageResponse(videoPreviewImage, // width: width, height: height, fill: fill, // filename: contentId.ToString("N")); //} return(onImageResponse(image, width: width, height: height, fill: fill, filename: contentId.ToString("N"), contentType: contentType)); //return request.CreateImageResponse(image, // width: width, height: height, fill: fill, // filename: contentId.ToString("N"), // contentType: contentType); }, () => onNotFound(), () => onUnauthorized()); return(response); }
public async Task <IActionResult> Create(ClientRegisterCommand command) { var result = await _mediator.Send(command); return(result switch { SuccessResponse <ClientResponse> _ => StatusCode(201, result), NotFoundResponse <ClientResponse> _ => NotFound(result), BadRequestResponse <ClientResponse> _ => BadRequest(result), InternalError <ClientResponse> _ => StatusCode(500, result), _ => NotFound() });