public async static Task <IHttpResponse> GetByAccountAsync( [QueryParameter(Name = AccountPropertyName)] Guid accountId, IAuthApplication application, SessionToken security, MultipartAsyncResponse <XIntegration> onContents, UnauthorizedResponse onUnauthorized) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onUnauthorized()); } var integrations = GetIntegrationsByAccount(accountId) .Select( kvp => { var integration = kvp.Key; return(Auth.Method.ById(kvp.Value.Method, application, method => { integration.methodName = method.name; return integration; }, () => default(XIntegration?))); }) .Await() .SelectWhereHasValue(); return(onContents(integrations)); }
public static Task <IHttpResponse> QueryBySessionAsync( [QueryParameter(Name = "session")] IRef <Session> sessionRef, IAuthApplication application, MultipartAsyncResponse <Method> onContent, ReferencedDocumentNotFoundResponse <Session> onSessionNotFound, UnauthorizedResponse onHacked) { return(sessionRef.StorageGetAsync( session => { var integrationProviders = application.LoginProviders .Where(loginProvider => loginProvider.Value.GetType().IsSubClassOfGeneric(typeof(IProvideSession))) .Select( async loginProvider => { var supportsIntegration = await(loginProvider.Value as IProvideSession).SupportsSessionAsync(session); return supportsIntegration.PairWithValue(loginProvider); }) .AsyncEnumerable() .Where(kvp => kvp.Key) .SelectValues() .Select( (loginProvider) => { return new Method { authenticationId = new Ref <Method>(loginProvider.Value.Id), name = loginProvider.Value.Method, }; }); return onContent(integrationProviders); }, //() => onSessionNotFound().AsTask()); () => onHacked())); }
public static IHttpResponse GetByMethodAsync( [QueryParameter(Name = Authorization.MethodPropertyName)] IRef <Method> methodRef, IAuthApplication application, SessionToken security, MultipartAsyncResponse <XIntegration> onContents, UnauthorizedResponse onUnauthorized) { if (!security.accountIdMaybe.HasValue) { return(onUnauthorized()); } var accountId = security.accountIdMaybe.Value; var integrations = GetIntegrationsByAccount(accountId) .Where(integration => integration.Value.Method.id == methodRef.id) .Select( kvp => { var integration = kvp.Key; return(Auth.Method.ById(kvp.Value.Method, application, method => { integration.methodName = method.name; return integration; }, () => default(XIntegration?))); }) .Await() .SelectWhereHasValue(); return(onContents(integrations)); }
public static IHttpResponse List( MultipartAsyncResponse <Account> onFound) { var accounts = typeof(Authentication) .StorageGetAll() .Select(obj => (Authentication)obj) .Distinct(auth => auth.userIdentification) .Select( (auth) => { var accountRef = auth.userIdentification .MD5HashGuid() .AsRef <Account>(); return(accountRef.StorageUpdateAsync( async(account, saveAsync) => { account.userIdentification = auth.userIdentification; await saveAsync(account); account.password = "******"; return account; }, () => { return new Account { accountRef = accountRef, userIdentification = auth.userIdentification, password = "******", }; })); }) .Await(); return(onFound(accounts)); }
public static IHttpResponse ListAsync( MultipartAsyncResponse <Client> onListed) { return(typeof(Client) .StorageGetAll() .Select(c => (Client)c) .HttpResponse(onListed));; }
public static IHttpResponse ListByRequestUrlAsync( [QueryParameter(Name = "request_uri")] Uri requestUri, MultipartAsyncResponse <InvocationMessage> onRun) { var messages = requestUri.StorageGetBy( (InvocationMessage ent) => ent.requestUri); return(onRun(messages)); }
public static IHttpResponse GetByInvocationMessageAsync( [QueryParameter(Name = InvocationMessagePropertyName)] IRef <InvocationMessage> message, MultipartAsyncResponse <ExecutionResult> onResults) { var messages = message.StorageGetBy( (ExecutionResult ent) => ent.invocationMessage); return(onResults(messages)); }
public static IHttpResponse QueryByResourceAsync( [QueryParameter(Name = ResourcePropertyName)] string resource, [QueryParameter(Name = WhenPropertyName)] DateTime when, MultipartAsyncResponse <Profile> onFound) { return(resource .StorageGetBy( (Profile profile) => profile.resource, profile => profile.when == when) .HttpResponse(onFound)); }
public static IHttpResponse HttpGetAll <TResource>( this IQueryable <TResource> resources, MultipartAsyncResponse <TResource> onFound, Func <TResource, TResource> select = default) where TResource : IReferenceable, new() { return(resources .StorageGet() .IfThen(!select.IsDefaultOrNull(), ress => ress.Select(select)) .HttpResponse(onFound)); }
public static async Task <IHttpResponse> QueueUpBackupPartitions( [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef, [Property(Name = StorageSettingCopyFromPropertyName)] string storageSettingCopyFrom, [Property(Name = StorageSettingCopyToPropertyName)] string storageSettingCopyTo, [Resource] RepositoryBackup repositoryBackup, AzureApplication application, EastFive.Api.Security security, RequestMessage <TableBackup> requestQuery, IHttpRequest request, EastFive.Analytics.ILogger logger, MultipartAsyncResponse <InvocationMessage> onQueued, AlreadyExistsResponse onAlreadyExists) { CloudStorageAccount account = CloudStorageAccount .Parse(storageSettingCopyFrom); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); return(await repositoryBackup.StorageCreateAsync( (discard) => { var includedTables = BackupFunction.DiscoverStorageResources() .Where(x => x.message.Any()) .Select(x => x.tableName) .ToArray(); var resourceInfoToProcess = tableClient.GetTables() .Where(table => includedTables.Contains(table.Name, StringComparer.OrdinalIgnoreCase)) .Distinct() .Select( async cloudTable => { var tableBackup = new TableBackup() { tableBackupRef = Ref <TableBackup> .NewRef(), backup = repositoryBackupRef, tableName = cloudTable.Name, when = DateTime.UtcNow, }; var invocationMessage = await requestQuery .HttpPost(tableBackup) .CompileRequest(request) .FunctionAsync(); logger.Trace($"Invocation[{invocationMessage.id}] will backup table `{tableBackup.tableName}`."); return invocationMessage; }) .Await(readAhead: 10); return onQueued(resourceInfoToProcess); }, () => onAlreadyExists())); }
public static IHttpResponse GetAll( RequestMessage <TeamsNotification> teamsNotifications, MultipartAsyncResponse <TeamsNotification> onFound) { return(teamsNotifications .StorageGet() .Select( n => { return n; }) .HttpResponse(onFound)); }
public static IHttpResponse ListAsync( [QueryParameter(Name = "start_time")] DateTime startTime, [QueryParameter(Name = "end_time")] DateTime endTime, [HeaderLog] EastFive.Analytics.ILogger analyticsLog, MultipartAsyncResponse <InvocationMessage> onRun) { Expression <Func <InvocationMessage, bool> > allQuery = (im) => true; var messages = allQuery .StorageQuery() .Where(msg => msg.lastModified >= startTime) .Where(msg => msg.lastModified <= endTime); return(onRun(messages)); }
public static IHttpResponse InvokeAsync( [UpdateId] IRefs <InvocationMessage> invocationMessageRefs, [HeaderLog] ILogger analyticsLog, InvokeApplicationDirect invokeApplication, CancellationToken cancellationToken, MultipartAsyncResponse <IHttpResponse> onRun) { var messages = invocationMessageRefs.refs .Select( invocationMessageRef => InvokeAsync(invocationMessageRef, invokeApplication, logging: new EventLogger(analyticsLog), cancellationToken: cancellationToken)) .AsyncEnumerable(); return(onRun(messages)); }
[Api.HttpGet] //(MatchAllBodyParameters = false)] public async static Task <IHttpResponse> GetByAccountAsync( [QueryParameter(Name = AccountPropertyName)] Guid accountId, Api.Azure.AzureApplication application, SessionToken security, MultipartAsyncResponse <Integration> onContents, ReferencedDocumentNotFoundResponse <object> onAccountNotFound, UnauthorizedResponse onUnauthorized) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onUnauthorized()); } return(await GetIntegrationsByAccountAsync(accountId, (kvps) => onContents(kvps.SelectKeys()), () => onAccountNotFound())); }
public static IHttpResponse GetAsync( RequestMessage <Claim> claims, Authorization auth, MultipartAsyncResponse <Claim> onFound, UnauthorizedResponse onUnauthorized) { if (!auth.accountIdMaybe.HasValue) { return(onUnauthorized()); } Expression <Func <Claim, bool> > allQuery = (claim) => true; var claimsForUser = claims .Where(claim => claim.actorId == auth.accountIdMaybe.Value) .StorageGet(); return(onFound(claimsForUser)); }
public static IHttpResponse AllAsync( [QueryParameter(Name = "start_time")] DateTime startTime, [QueryParameter(Name = "end_time")] DateTime endTime, RequestMessage <Authorization> authorizations, IAuthApplication application, EastFive.Api.SessionToken?securityMaybe, MultipartAsyncResponse <Login> onFound) { var methodLookups = application.LoginProviders .Select( (loginProvider) => { return(loginProvider.Value.Id.PairWithValue(loginProvider.Value.Method)); }) .ToDictionary(); var results = authorizations .Where(auth => auth.lastModified <= endTime) .Where(auth => auth.lastModified >= startTime) .StorageGet() .Take(100) .Select( async auth => { var name = auth.accountIdMaybe.HasValue ? await application.GetActorNameDetailsAsync(auth.accountIdMaybe.Value, (a, b, c) => $"{a} {b}", () => "") : ""; return(new Login() { actorId = auth.accountIdMaybe, authorization = auth.authorizationRef, name = name, method = methodLookups.ContainsKey(auth.Method.id) ? methodLookups[auth.Method.id] : auth.Method.id.ToString(), when = auth.lastModified, }); }) .Await(); return(onFound(results)); }
public static IHttpResponse ClearAsync( [WorkflowParameter(Value = "true")] [QueryParameter(Name = "clear")] bool clear, RequestMessage <TeamsNotification> teamsNotifications, EastFive.Api.Security security, MultipartAsyncResponse <TeamsNotification> onDeleted) { return(teamsNotifications .StorageGet() .StorageDeleteBatch( tr => { return (tr.Result as IWrapTableEntity <TeamsNotification>).Entity; }) .HttpResponse(onDeleted)); }
public static IHttpResponse PossibleFolderNames( [WorkflowParameter(Value = "2022-02-07")] [QueryParameter(Name = WhenPropertyName)] DateTime when, Security security, [WorkflowVariableArrayIndexedValue(Index = 0, VariableName = EastFive.Azure.Workflows.MonitoringFlow.Variables.FolderName)] MultipartAsyncResponse <string> onList) { return(when .StorageGetBy((MonitoringRequest mr) => mr.when) .Select( mr => { return mr.folderName; }) .Distinct() .HttpResponse(onList)); }
public static async Task <IHttpResponse> QueryByIntegrationAsync( [QueryParameter(Name = "integration")] IRef <XIntegration> integrationRef, IAuthApplication application, EastFive.Api.SessionToken security, MultipartAsyncResponse <Method> onContent, UnauthorizedResponse onUnauthorized, ReferencedDocumentNotFoundResponse <XIntegration> onIntegrationNotFound) { return(await await integrationRef.StorageGetAsync( async (integration) => { var accountId = integration.accountId; if (!await application.CanAdministerCredentialAsync(accountId, security)) { return onUnauthorized(); } var integrationProviders = application.LoginProviders .Where(loginProvider => loginProvider.Value.GetType().IsSubClassOfGeneric(typeof(IProvideIntegration))) .Select( async loginProvider => { var integrationProvider = loginProvider.Value as IProvideIntegration; var supportsIntegration = await integrationProvider.SupportsIntegrationAsync(accountId); return supportsIntegration.PairWithValue(loginProvider); }) .AsyncEnumerable() .Where(kvp => kvp.Key) .SelectValues() .Select( (loginProvider) => { var integrationProvider = loginProvider.Value as IProvideIntegration; return new Method { authenticationId = new Ref <Method>(loginProvider.Value.Id), name = integrationProvider.GetDefaultName(new Dictionary <string, string>()), }; }); return onContent(integrationProviders); }, () => onIntegrationNotFound().AsTask())); }
public static IHttpResponse List( [QueryParameter(Name = NamePropertyName)] string name, HttpApplication httpApp, MultipartAsyncResponse <StorageRow> onFound, NotFoundResponse onNotFound) { return(DiscoverStorageResources(httpApp.GetType()) .Where(table => table.name == name) .First( (storageTable, next) => { var table = storageTable.cloudTable; var query = new TableQuery <GenericTableEntity>(); var allRows = AzureTableDriverDynamic .FindAllInternal(query, table) .Select( tableRow => { return new StorageRow() { rowKey = tableRow.RowKey, partitionKey = tableRow.PartitionKey, properties = tableRow.properties .Select( property => { var epValue = property.Value .GetPropertyAsObject(out bool hasValue); return property.Key .PairWithValue(epValue); }) .ToDictionary(), }; }); return onFound(allRows); }, () => onNotFound())); }
public static IHttpResponse HttpResponse <TResource>( this IEnumerableAsync <TResource> resources, MultipartAsyncResponse <TResource> responseDelegate) { return(responseDelegate(resources)); }
public static async Task <IHttpResponse> QueueUpBackupPartitions( [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef, [Property(Name = WhenPropertyName)] DateTime when, RequestMessage <TableBackup> requestQuery, IHttpRequest request, EastFive.Analytics.ILogger logger, MultipartAsyncResponse <InvocationMessage> onQueued, NoContentResponse onTooEarly, NotFoundResponse onNotFound) { return(await repositoryBackupRef.StorageUpdateAsync( async (repoBack, saveAsync) => { var needsToRun = NCrontab.CrontabSchedule.TryParse(repoBack.frequency, chronSchedule => { var next = chronSchedule.GetNextOccurrence(repoBack.when); if (when > next) { return true; } return false; }, ex => { return false; }); if (!needsToRun) { return onTooEarly(); } var includedTables = BackupFunction.DiscoverStorageResources() .Where(x => x.message.Any()) .Select(x => x.tableName) .ToArray(); CloudStorageAccount account = CloudStorageAccount .Parse(repoBack.storageSettingCopyFrom); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); var tables = tableClient.GetTables(); var resourceInfoToProcess = tables .Where(table => includedTables.Contains(table.Name, StringComparer.OrdinalIgnoreCase)) .Distinct() .Select( async cloudTable => { var tableBackup = new TableBackup() { tableBackupRef = Ref <TableBackup> .NewRef(), backup = repositoryBackupRef, tableName = cloudTable.Name, when = DateTime.UtcNow, }; var invocationMessage = await requestQuery .HttpPost(tableBackup) .CompileRequest(request) .FunctionAsync(); logger.Trace($"Invocation[{invocationMessage.id}] will backup table `{tableBackup.tableName}`."); return invocationMessage; }) .Await(readAhead: 10); repoBack.when = when; await saveAsync(repoBack); return onQueued(resourceInfoToProcess); }, () => onNotFound())); }