public async Task <IActionResult> Get([FromRoute] string providerDataId) { var provider = await providersRepository .GetAsync(ProviderId) .ConfigureAwait(false); if (provider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found in this TeamCloud Instance") .ActionResult()); } var project = await projectsRepository .GetAsync(ProjectId) .ConfigureAwait(false); if (project is null) { return(ErrorResult .NotFound($"A Project with the identifier '{ProjectId}' could not be found in this TeamCloud Instance") .ActionResult()); } if (!project.Type.Providers.Any(p => p.Id.Equals(provider.Id, StringComparison.OrdinalIgnoreCase))) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found on the Project '{ProjectId}'") .ActionResult()); } var providerData = await providerDataRepository .GetAsync(providerDataId) .ConfigureAwait(false); if (providerData is null) { return(ErrorResult .NotFound($"A Provider Data item with the ID '{providerDataId}' could not be found") .ActionResult()); } var returnData = providerData.PopulateExternalModel(); return(DataResult <ProviderData> .Ok(returnData) .ActionResult()); }
public async Task <IActionResult> Get([FromQuery] string timeRange = null, [FromQuery] string[] commands = default) { var organizationId = Guid.Parse(OrganizationId); var timeRangeParsed = TimeSpan.TryParse(timeRange, out var timeRangeTemp) && timeRangeTemp.TotalMinutes >= 1 ? (TimeSpan?)timeRangeTemp : null; // time range must be at least a second; otherwise, don't use this information var entities = await commandAuditReader .ListAsync(organizationId, timeRange : timeRangeParsed, commands : commands) .ToListAsync() .ConfigureAwait(false); return(DataResult <List <CommandAuditEntity> > .Ok(entities) .ToActionResult()); }
public async Task <IActionResult> Get(string projectTypeId) { var projectType = await projectTypesRepository .GetAsync(projectTypeId) .ConfigureAwait(false); if (projectType is null) { return(ErrorResult .NotFound($"A ProjectType with the ID '{projectTypeId}' could not be found in this TeamCloud Instance") .ActionResult()); } return(DataResult <ProjectType> .Ok(projectType) .ActionResult()); }
public async Task <IActionResult> Get() { var orgIds = await userRepository .ListOrgsAsync(UserService.CurrentUserId) .ToListAsync() .ConfigureAwait(false); var orgs = !orgIds.Any() ? new List <Organization>() : await organizationRepository .ListAsync(UserService.CurrentUserTenant, orgIds) .ToListAsync() .ConfigureAwait(false); return(DataResult <List <Organization> > .Ok(orgs) .ToActionResult()); }
public async Task <IActionResult> Get([FromRoute] string userNameOrId) { if (string.IsNullOrEmpty(ProjectId)) { return(ErrorResult .BadRequest($"Project Id provided in the url path is invalid. Must be a valid GUID.", ResultErrorCode.ValidationError) .ActionResult()); } if (string.IsNullOrWhiteSpace(userNameOrId)) { return(ErrorResult .BadRequest($"The identifier '{userNameOrId}' provided in the url path is invalid. Must be a valid email address or GUID.", ResultErrorCode.ValidationError) .ActionResult()); } var userId = await userService .GetUserIdAsync(userNameOrId) .ConfigureAwait(false); if (string.IsNullOrEmpty(userId)) { return(ErrorResult .NotFound($"The user '{userNameOrId}' could not be found.") .ActionResult()); } var user = await usersRepository .GetAsync(userId) .ConfigureAwait(false); if (user is null || !user.IsMember(ProjectId)) { return(ErrorResult .NotFound($"The specified User could not be found in this Project.") .ActionResult()); } var returnUser = user.PopulateExternalModel(ProjectId); return(DataResult <User> .Ok(returnUser) .ActionResult()); }
public async Task <IActionResult> Get() { var teamCloudInstance = await teamCloudRepository .GetAsync() .ConfigureAwait(false); if (teamCloudInstance is null) { return(ErrorResult .NotFound($"No TeamCloud Instance was found.") .ActionResult()); } var users = teamCloudInstance?.Users ?? new List <User>(); return(DataResult <List <User> > .Ok(users.ToList()) .ActionResult()); }
public async Task <IActionResult> Get(string providerId) { var provider = await providersRepository .GetAsync(providerId) .ConfigureAwait(false); if (provider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{providerId}' could not be found in this TeamCloud Instance") .ActionResult()); } var returnProvider = provider.PopulateExternalModel(); return(DataResult <Provider> .Ok(returnProvider) .ActionResult()); }
public async Task <IActionResult> Get() { var teamCloudInstance = await teamCloudRepository .GetAsync() .ConfigureAwait(false); if (teamCloudInstance is null) { return(ErrorResult .NotFound($"No TeamCloud Instance was found.") .ActionResult()); } var tags = teamCloudInstance?.Tags is null ? new Dictionary <string, string>() : new Dictionary <string, string>(teamCloudInstance.Tags); return(DataResult <Dictionary <string, string> > .Ok(tags) .ActionResult()); }
public async Task <IActionResult> GetMe() { var me = await userService .CurrentUserAsync() .ConfigureAwait(false); if (me is null) { return(ErrorResult .NotFound($"A User matching the current authenticated user was not found in this TeamCloud instance.") .ToActionResult()); } var returnMe = me.PopulateExternalModel(); return(DataResult <User> .Ok(returnMe) .ToActionResult()); }
public async Task <IActionResult> Get() { var teamCloudInstance = await teamCloudRepository .GetAsync() .ConfigureAwait(false); if (teamCloudInstance is null) { return(ErrorResult .NotFound($"The TeamCloud instance could not be found.") .ActionResult()); } var returnTeamCloudInstance = teamCloudInstance.PopulateExternalModel(); return(DataResult <TeamCloudInstance> .Ok(returnTeamCloudInstance) .ActionResult()); }
public async Task <IActionResult> Get([FromQuery] bool includeShared) { var provider = await providersRepository .GetAsync(ProviderId) .ConfigureAwait(false); if (provider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found in this TeamCloud Instance") .ToActionResult()); } var project = await projectsRepository .GetAsync(ProjectId) .ConfigureAwait(false); if (project is null) { return(ErrorResult .NotFound($"A Project with the identifier '{ProjectId}' could not be found in this TeamCloud Instance") .ToActionResult()); } if (!project.Type.Providers.Any(p => p.Id.Equals(provider.Id, StringComparison.OrdinalIgnoreCase))) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found on the Project '{ProjectId}'") .ToActionResult()); } var data = await providerDataRepository .ListAsync(provider.Id, project.Id, includeShared) .ToListAsync() .ConfigureAwait(false); var returnData = data.Select(d => d.PopulateExternalModel()).ToList(); return(DataResult <List <ProviderData> > .Ok(returnData) .ToActionResult()); }
public async Task <IActionResult> Get() { var adpaterInformationList = await adapterProvider .GetAdapters() .Select(async a => new AdapterInformation() { Type = a.Type, DisplayName = a.DisplayName, InputDataSchema = await a.GetInputDataSchemaAsync().ConfigureAwait(false), InputDataForm = await a.GetInputFormSchemaAsync().ConfigureAwait(false) }) .ToAsyncEnumerable() .OrderBy(ai => ai.Type != DeploymentScopeType.AzureResourceManager).ThenBy(ai => ai.DisplayName) .ToListAsync() .ConfigureAwait(false); return(DataResult <List <AdapterInformation> > .Ok(adpaterInformationList) .ToActionResult()); }
public Task <IActionResult> Get([FromQuery] bool includeShared) => EnsureProjectAndProviderAsync(async(project, provider) => { if (!project.Type.Providers.Any(p => p.Id.Equals(provider.Id, StringComparison.OrdinalIgnoreCase))) { return(ErrorResult .NotFound($"A Provider with the ID '{provider.Id}' could not be found on the Project '{project.Id}'") .ToActionResult()); } var dataDocuments = await providerDataRepository .ListAsync(provider.Id, project.Id, includeShared) .ToListAsync() .ConfigureAwait(false); var data = dataDocuments.Select(d => d.PopulateExternalModel()).ToList(); return(DataResult <List <ProviderData> > .Ok(data) .ToActionResult()); });
public Task <IActionResult> GetMe() => WithContextAsync(async contextUser => { var projectIds = contextUser.ProjectMemberships.Select(pm => pm.ProjectId); if (!projectIds.Any()) { return(DataResult <List <Project> > .Ok(new List <Project>()) .ToActionResult()); } var projects = await projectRepository .ListAsync(OrganizationId, projectIds) .ToListAsync() .ConfigureAwait(false); return(DataResult <List <Project> > .Ok(projects) .ToActionResult()); });
public async Task <IActionResult> Get() { if (string.IsNullOrEmpty(ProjectId)) { return(ErrorResult .BadRequest($"Project Id provided in the url path is invalid. Must be a valid GUID.", ResultErrorCode.ValidationError) .ActionResult()); } var users = await usersRepository .ListAsync(ProjectId) .ToListAsync() .ConfigureAwait(false); var returnUsers = users.Select(u => u.PopulateExternalModel()).ToList(); return(DataResult <List <User> > .Ok(returnUsers) .ActionResult()); }
public async Task <IActionResult> Get([FromRoute] string tagKey) { if (string.IsNullOrEmpty(ProjectId)) { return(ErrorResult .BadRequest($"Project Id provided in the url path is invalid. Must be a non-empty string.", ResultErrorCode.ValidationError) .ActionResult()); } if (string.IsNullOrWhiteSpace(tagKey)) { return(ErrorResult .BadRequest($"The key provided in the url path is invalid. Must be a non-empty string.", ResultErrorCode.ValidationError) .ActionResult()); } var project = await projectsRepository .GetAsync(ProjectId) .ConfigureAwait(false); if (project is null) { return(ErrorResult .NotFound($"A Project with the ID '{ProjectId}' could not be found in this TeamCloud Instance.") .ActionResult()); } if (!project.Tags.TryGetValue(tagKey, out var tagValue)) { return(ErrorResult .NotFound($"The specified Tag could not be found in this Project.") .ActionResult()); } return(DataResult <Dictionary <string, string> > .Ok(new Dictionary <string, string> { { tagKey, tagValue } }) .ActionResult()); }
public async Task <IActionResult> Get() { if (string.IsNullOrEmpty(UserId)) { return(ErrorResult .BadRequest($"User Id provided in the url path is invalid. Must be a valid GUID.", ResultErrorCode.ValidationError) .ActionResult()); } var user = await usersRepository .GetAsync(UserId) .ConfigureAwait(false); if (user is null) { return(ErrorResult .NotFound($"The specified User could not be found in this TeamCloud Instance.") .ActionResult()); } var projectIds = user.ProjectMemberships.Select(pm => pm.ProjectId); if (!projectIds.Any()) { return(DataResult <List <Project> > .Ok(new List <Project>()) .ActionResult()); } var projectDocuments = await projectsRepository .ListAsync(projectIds) .ToListAsync() .ConfigureAwait(false); var projects = projectDocuments.Select(p => p.PopulateExternalModel()).ToList(); return(DataResult <List <Project> > .Ok(projects) .ActionResult()); }
public Task <IActionResult> GetMe() => EnsureCurrentUserAsync(async user => { var projectIds = user.ProjectMemberships.Select(pm => pm.ProjectId); if (!projectIds.Any()) { return(DataResult <List <Project> > .Ok(new List <Project>()) .ToActionResult()); } var projectDocuments = await ProjectRepository .ListAsync(projectIds) .ToListAsync() .ConfigureAwait(false); var projects = projectDocuments.Select(p => p.PopulateExternalModel()).ToList(); return(DataResult <List <Project> > .Ok(projects) .ToActionResult()); });
public async Task <IActionResult> Get() { var provider = await providersRepository .GetAsync(ProviderId) .ConfigureAwait(false); if (provider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found in this TeamCloud Instance") .ActionResult()); } var data = await providerDataRepository .ListAsync(provider.Id) .ToListAsync() .ConfigureAwait(false); var returnData = data.Select(d => d.PopulateExternalModel()).ToList(); return(DataResult <List <ProviderData> > .Ok(returnData) .ActionResult()); }
public async Task <IActionResult> Put([FromRoute] string projectTypeId, [FromBody] ProjectType projectType) { if (projectType is null) { throw new ArgumentNullException(nameof(projectType)); } if (string.IsNullOrWhiteSpace(projectTypeId)) { return(ErrorResult .BadRequest($"The identifier '{projectTypeId}' provided in the url path is invalid. Must be a valid project type ID.", ResultErrorCode.ValidationError) .ActionResult()); } var validation = new ProjectTypeValidator().Validate(projectType); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } if (!projectTypeId.Equals(projectType.Id, StringComparison.OrdinalIgnoreCase)) { return(ErrorResult .BadRequest(new ValidationError { Field = "id", Message = $"ProjectType's id does match the identifier provided in the path." }) .ActionResult()); } var existingProjectType = await projectTypesRepository .GetAsync(projectType.Id) .ConfigureAwait(false); if (existingProjectType is null) { return(ErrorResult .NotFound($"A ProjectType with the ID '{projectType.Id}' could not be found in this TeamCloud Instance") .ActionResult()); } var providers = await providersRepository .ListAsync() .ToListAsync() .ConfigureAwait(false); var validProviders = projectType.Providers .All(p => providers.Any(provider => provider.Id == p.Id)); if (!validProviders) { var validProviderIds = string.Join(", ", providers.Select(p => p.Id)); return(ErrorResult .BadRequest(new ValidationError { Field = "projectType", Message = $"All provider ids on a ProjectType must match the id of a registered Provider on the TeamCloud instance. Valid provider ids are: {validProviderIds}" }) .ActionResult()); } existingProjectType .PopulateFromExternalModel(projectType); var updateResult = await orchestrator .UpdateAsync(existingProjectType) .ConfigureAwait(false); var returnUpdateResult = updateResult.PopulateExternalModel(); return(DataResult <ProjectType> .Ok(returnUpdateResult) .ActionResult()); }
public Task <IActionResult> Get([FromRoute] string componentId) => WithContextAsync <Component>((contextUser, component) => { return(DataResult <Component> .Ok(component) .ToActionResultAsync()); });
public Task <IActionResult> Get([FromRoute] string userNameOrId) => EnsureUserAsync(user => { return(DataResult <User> .Ok(user.PopulateExternalModel()) .ToActionResult()); });
public async Task <IActionResult> Put([FromRoute] string providerDataId, [FromBody] ProviderData providerData) { if (providerData is null) { throw new ArgumentNullException(nameof(providerData)); } if (string.IsNullOrWhiteSpace(providerDataId)) { return(ErrorResult .BadRequest($"The identifier '{providerDataId}' provided in the url path is invalid. Must be a valid GUID.", ResultErrorCode.ValidationError) .ToActionResult()); } var validation = new ProviderDataValidator().Validate(providerData); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ToActionResult()); } if (!providerDataId.Equals(providerData.Id, StringComparison.OrdinalIgnoreCase)) { return(ErrorResult .BadRequest(new ValidationError { Field = "id", Message = $"ProviderData's id does match the identifier provided in the path." }) .ToActionResult()); } var provider = await providersRepository .GetAsync(ProviderId) .ConfigureAwait(false); if (provider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found in this TeamCloud Instance") .ToActionResult()); } var project = await projectsRepository .GetAsync(ProjectId) .ConfigureAwait(false); if (project is null) { return(ErrorResult .NotFound($"A Project with the identifier '{ProjectId}' could not be found in this TeamCloud Instance") .ToActionResult()); } if (!project.Type.Providers.Any(p => p.Id.Equals(provider.Id, StringComparison.OrdinalIgnoreCase))) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found on the Project '{ProjectId}'") .ToActionResult()); } var oldProviderData = await providerDataRepository .GetAsync(providerData.Id) .ConfigureAwait(false); if (oldProviderData is null) { return(ErrorResult .NotFound($"The Provider Data '{providerData.Id}' could not be found..") .ToActionResult()); } var newProviderData = new ProviderDataDocument { ProviderId = provider.Id, Scope = ProviderDataScope.Project, ProjectId = project.Id, }.PopulateFromExternalModel(providerData); var updateResult = await orchestrator .UpdateAsync(newProviderData) .ConfigureAwait(false); var returnUpdateResult = updateResult.PopulateExternalModel(); return(DataResult <ProviderData> .Ok(returnUpdateResult) .ToActionResult()); }
public Task <IActionResult> GetMe() => EnsureCurrentUserAsync(currentUser => { return(DataResult <User> .Ok(currentUser.PopulateExternalModel()) .ToActionResult()); });
public async Task <IActionResult> Put([FromBody] ProviderData providerData) { if (providerData is null) { throw new ArgumentNullException(nameof(providerData)); } var validation = new ProviderDataValidator().Validate(providerData); if (!validation.IsValid) { return(ErrorResult .BadRequest(validation) .ActionResult()); } var provider = await providersRepository .GetAsync(ProviderId) .ConfigureAwait(false); if (provider is null) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found in this TeamCloud Instance") .ActionResult()); } var project = await projectsRepository .GetAsync(ProjectId) .ConfigureAwait(false); if (project is null) { return(ErrorResult .NotFound($"A Project with the identifier '{ProjectId}' could not be found in this TeamCloud Instance") .ActionResult()); } if (!project.Type.Providers.Any(p => p.Id.Equals(provider.Id, StringComparison.OrdinalIgnoreCase))) { return(ErrorResult .NotFound($"A Provider with the ID '{ProviderId}' could not be found on the Project '{ProjectId}'") .ActionResult()); } var oldProviderData = await providerDataRepository .GetAsync(providerData.Id) .ConfigureAwait(false); if (oldProviderData is null) { return(ErrorResult .NotFound($"The Provider Data '{providerData.Id}' could not be found..") .ActionResult()); } var newProviderData = new ProviderDataDocument { ProviderId = provider.Id, Scope = ProviderDataScope.Project, ProjectId = project.Id, }; newProviderData.PopulateFromExternalModel(providerData); var updateResult = await orchestrator .UpdateAsync(newProviderData) .ConfigureAwait(false); var returnUpdateResult = updateResult.PopulateExternalModel(); return(DataResult <ProviderData> .Ok(returnUpdateResult) .ActionResult()); }
public Task <IActionResult> Get([FromRoute] string projectNameOrId) => EnsureProjectAsync(project => { return(DataResult <Project> .Ok(project.PopulateExternalModel()) .ToActionResult()); });
public Task <IActionResult> Get([FromRoute] string projectId) => WithContextAsync <Project>((contextUser, project) => { return(DataResult <Project> .Ok(project) .ToActionResultAsync()); });
public Task <IActionResult> Get([FromRoute] string providerId) => EnsureProviderAsync(provider => { return(DataResult <Provider> .Ok(provider.PopulateExternalModel()) .ToActionResult()); });
public Task <IActionResult> Get([FromRoute] string userId) => WithContextAsync <User>((contextUser, user) => { return(DataResult <User> .Ok(user) .ToActionResultAsync()); });
public Task <IActionResult> Get() => WithContextAsync <DeploymentScope>((contextUser, deploymentScope) => { return(DataResult <DeploymentScope> .Ok(deploymentScope) .ToActionResultAsync()); });