public override async Task Execute() { var clientIdArgData = CommandArgumentValue.GetArgumentValue(_clientId); var clientId = clientIdArgData.GetValue <string>(); var clientNameArgData = CommandArgumentValue.GetArgumentValue(_clientName); var clientName = clientNameArgData.GetValue <string>(); var clientSecretArgData = CommandArgumentValue.GetArgumentValue(_clientSecret); var clientSecret = clientSecretArgData.GetValue <string>(); Logger.Info($"Creating client '{clientId}' at '{ServiceClient.ServiceUri}'"); var clientDto = new ClientDto { IsEnabled = true, ClientId = clientId, ClientName = clientName, ClientSecret = clientSecret, AllowedGrantTypes = new[] { OidcConstants.GrantTypes.ClientCredentials }, AllowedScopes = new[] { CommonConstants.SystemApiFullAccess }, IsOfflineAccessEnabled = true }; await ServiceClient.CreateClient(clientDto); Logger.Info($"ServiceClient '{clientId}' at '{ServiceClient.ServiceUri}' created."); }
public override Task Execute() { Logger.Info("Configuring the tool"); if (CommandArgumentValue.IsArgumentUsed(_tenantIdArg)) { var tenantIdArgData = CommandArgumentValue.GetArgumentValue(_tenantIdArg); Options.Value.TenantId = tenantIdArgData.GetValue <string>().ToLower(); } if (CommandArgumentValue.IsArgumentUsed(_coreServicesUriArg)) { var coreServicesUriData = CommandArgumentValue.GetArgumentValue(_coreServicesUriArg); Options.Value.CoreServiceUrl = coreServicesUriData.GetValue <string>().ToLower(); } if (CommandArgumentValue.IsArgumentUsed(_jobServicesUriArg)) { var jobServicesUriData = CommandArgumentValue.GetArgumentValue(_jobServicesUriArg); Options.Value.JobServiceUrl = jobServicesUriData.GetValue <string>().ToLower(); } if (CommandArgumentValue.IsArgumentUsed(_identityServicesUriArg)) { var identityServicesUriData = CommandArgumentValue.GetArgumentValue(_identityServicesUriArg); Options.Value.IdentityServiceUrl = identityServicesUriData.GetValue <string>().ToLower(); } _configWriter.WriteSettings(Constants.OspToolUserFolderName); return(Task.CompletedTask); }
public override async Task Execute() { var nameArgData = CommandArgumentValue.GetArgumentValue(_nameArg); var name = nameArgData.GetValue <string>().ToLower(); string newUserName = null; if (CommandArgumentValue.IsArgumentUsed(_newNameArg)) { var newUserNameArgData = CommandArgumentValue.GetArgumentValue(_newNameArg); newUserName = newUserNameArgData.GetValue <string>().ToLower(); } string roleName = null; if (CommandArgumentValue.IsArgumentUsed(_roleArg)) { var roleArgData = CommandArgumentValue.GetArgumentValue(_roleArg); roleName = roleArgData.GetValue <string>().ToLower(); } string eMail = null; if (CommandArgumentValue.IsArgumentUsed(_eMailArg)) { var eMailArgData = CommandArgumentValue.GetArgumentValue(_eMailArg); eMail = eMailArgData.GetValue <string>().ToLower(); } Logger.Info($"Updating user '{name}' at '{ServiceClient.ServiceUri}'"); var userDto = new UserDto { Email = eMail, Name = newUserName, Roles = new List <RoleDto>() }; if (!string.IsNullOrWhiteSpace(roleName)) { RoleDto roleDto; try { roleDto = await ServiceClient.GetRoleByName(roleName); } catch (ServiceClientResultException) { Logger.Error($"Role '{roleName}' does not exist at '{ServiceClient.ServiceUri}'"); return; } userDto.Roles = new[] { roleDto }; } await ServiceClient.UpdateUser(name, userDto); Logger.Info($"User '{name}' updated."); }
public override async Task Execute() { var isEnabled = CommandArgumentValue.GetArgumentScalarValue <bool>(_isEnabledArg); var name = CommandArgumentValue.GetArgumentScalarValue <string>(_nameArg); var serviceHookBaseUri = CommandArgumentValue.GetArgumentScalarValue <string>(_serviceHookBaseUriArg); var serviceHookAction = CommandArgumentValue.GetArgumentScalarValue <string>(_serviceHookActionArg); var ckId = CommandArgumentValue.GetArgumentScalarValue <string>(_ckIdArg); var filterArgData = CommandArgumentValue.GetArgumentValue(_filterArg); Logger.Info( $"Creating service hook for entity '{ckId}' at '{ServiceClient.ServiceUri}'"); List <FieldFilterDto> fieldFilters = new List <FieldFilterDto>(); foreach (var filterArg in filterArgData.Values) { var terms = filterArg.Split(" "); if (terms.Length != 3) { throw new InvalidOperationException($"Filter term '{filterArg}' is invalid. Three terms needed."); } var attribute = terms[0].Trim('\''); if (!Enum.TryParse(terms[1], true, out FieldFilterOperatorDto operatorDto)) { throw new InvalidOperationException($"Operator '{terms[1]}' of term '{filterArg}' is invalid."); } var comparisionValue = terms[2].Trim('\''); fieldFilters.Add(new FieldFilterDto { AttributeName = attribute, Operator = operatorDto, ComparisonValue = comparisionValue }); } var createServiceHookDto = new ServiceHookMutationDto { Enabled = isEnabled, Name = name, QueryCkId = ckId, FieldFilter = JsonConvert.SerializeObject(fieldFilters), ServiceHookBaseUri = serviceHookBaseUri, ServiceHookAction = serviceHookAction }; var query = new GraphQLRequest { Query = GraphQl.CreateServiceHook, Variables = new { entities = new[] { createServiceHookDto } } }; var result = await ServiceClient.SendMutationAsync <IEnumerable <RtServiceHookDto> >(query); Logger.Info($"Service hook '{name}' added (ID '{result.First().RtId}')."); }
public override async Task Execute() { var tenantIdArgData = CommandArgumentValue.GetArgumentValue(_tenantIdArg); var tenantId = tenantIdArgData.GetValue <string>().ToLower(); Logger.Info($"Detach tenant '{tenantId}' at '{ServiceClient.ServiceUri}'"); await ServiceClient.DetachTenant(tenantId); Logger.Info($"Tenant '{tenantId}' at '{ServiceClient.ServiceUri}' detached."); }
public override async Task Execute() { var nameArgData = CommandArgumentValue.GetArgumentValue(_nameArg); var name = nameArgData.GetValue <string>().ToLower(); Logger.Info($"Deleting user '{name}' at '{ServiceClient.ServiceUri}'"); await ServiceClient.DeleteUser(name); Logger.Info($"User '{name}' deleted."); }
public override async Task Execute() { var tenantIdArgData = CommandArgumentValue.GetArgumentValue(_tenantIdArg); var tenantId = tenantIdArgData.GetValue <string>().ToLower(); Logger.Info($"Clearing cache tenant '{tenantId}' on at '{ServiceClient.ServiceUri}'"); await ServiceClient.ClearTenantCache(tenantId); Logger.Info($"Tenant cache '{tenantId}' on at '{ServiceClient.ServiceUri}' cleared."); }
public override async Task Execute() { var clientIdArgData = CommandArgumentValue.GetArgumentValue(_clientId); var clientId = clientIdArgData.GetValue <string>(); Logger.Info($"Deleting client '{clientId}' from '{ServiceClient.ServiceUri}'"); await ServiceClient.DeleteClient(clientId); Logger.Info($"ServiceClient '{clientId}' deleted."); }
public override async Task Execute() { var tenantIdArgData = CommandArgumentValue.GetArgumentValue(_tenantIdArg); var tenantId = tenantIdArgData.GetValue <string>().ToLower(); var databaseArgData = CommandArgumentValue.GetArgumentValue(_databaseArg); var databaseName = databaseArgData.GetValue <string>().ToLower(); Logger.Info($"Creating tenant '{tenantId}' (database '{databaseName}') at '{ServiceClient.ServiceUri}'"); await ServiceClient.CreateTenant(tenantId, databaseName); Logger.Info($"Tenant '{tenantId}' (database '{databaseName}') at '{ServiceClient.ServiceUri}' created."); }
public override async Task Execute() { var nameArgData = CommandArgumentValue.GetArgumentValue(_nameArg); var name = nameArgData.GetValue <string>().ToLower(); var passwordArgData = CommandArgumentValue.GetArgumentValue(_passwordArg); var password = passwordArgData.GetValue <string>(); Logger.Info($"Resetting password for user '{name}' at '{ServiceClient.ServiceUri}'"); await ServiceClient.ResetPassword(name, password); Logger.Info($"Resetting password for user '{name}' done."); }
public override async Task Execute() { var fileArgData = CommandArgumentValue.GetArgumentValue(_fileArg); var rtModelFilePath = fileArgData.GetValue <string>().ToLower(); var tenantId = Options.Value.TenantId; if (string.IsNullOrWhiteSpace(tenantId)) { throw new ServiceConfigurationMissingException("Tenant is missing."); } Logger.Info("Importing runtime model '{0}'", rtModelFilePath); var id = await _coreServicesClient.ImportRtModel(tenantId, rtModelFilePath); Logger.Info($"Runtime model import id '{id}' has been started."); await WaitForJob(id); }
public override async Task Execute() { var clientUriArgData = CommandArgumentValue.GetArgumentValue(_clientUri); var clientUri = clientUriArgData.GetValue <string>(); var clientIdArgData = CommandArgumentValue.GetArgumentValue(_clientId); var clientId = clientIdArgData.GetValue <string>(); var clientNameArgData = CommandArgumentValue.GetArgumentValue(_clientName); var clientName = clientNameArgData.GetValue <string>(); Logger.Info($"Creating client '{clientId}' (URI '{clientUri}') at '{ServiceClient.ServiceUri}'"); var clientDto = new ClientDto { IsEnabled = true, ClientId = clientId, ClientName = clientName, ClientUri = clientUri, AllowedCorsOrigins = new[] { clientUri.TrimEnd('/') }, AllowedGrantTypes = new[] { OidcConstants.GrantTypes.AuthorizationCode }, AllowedScopes = new[] { CommonConstants.SystemApiFullAccess }, PostLogoutRedirectUris = new[] { clientUri.EnsureEndsWith("/") }, RedirectUris = new[] { clientUri.EnsureEndsWith("/") }, IsOfflineAccessEnabled = true }; if (CommandArgumentValue.IsArgumentUsed(_redirectUri)) { var redirectUriArgData = CommandArgumentValue.GetArgumentValue(_redirectUri); var redirectUri = redirectUriArgData.GetValue <string>(); clientDto.RedirectUris = new[] { redirectUri }; } await ServiceClient.CreateClient(clientDto); Logger.Info($"ServiceClient '{clientId}' (URI '{clientUri}') at '{ServiceClient.ServiceUri}' created."); }
public override async Task Execute() { var clientIdArgData = CommandArgumentValue.GetArgumentValue(_clientId); var clientId = clientIdArgData.GetValue <string>(); Logger.Info($"Updating client '{clientId}' at '{ServiceClient.ServiceUri}'"); var clientDto = await ServiceClient.GetClient(clientId); if (CommandArgumentValue.IsArgumentUsed(_clientUri)) { var clientUriArgData = CommandArgumentValue.GetArgumentValue(_clientUri); var clientUri = clientUriArgData.GetValue <string>(); clientDto.ClientUri = clientUri; clientDto.AllowedCorsOrigins = new[] { clientUri.TrimEnd('/') }; clientDto.PostLogoutRedirectUris = new[] { clientUri.EnsureEndsWith("/") }; clientDto.RedirectUris = new[] { clientUri.EnsureEndsWith("/") }; } if (CommandArgumentValue.IsArgumentUsed(_redirectUri)) { var redirectUriArgData = CommandArgumentValue.GetArgumentValue(_redirectUri); var redirectUri = redirectUriArgData.GetValue <string>(); clientDto.RedirectUris = new[] { redirectUri }; } if (CommandArgumentValue.IsArgumentUsed(_clientName)) { var clientNameArgData = CommandArgumentValue.GetArgumentValue(_clientName); var clientName = clientNameArgData.GetValue <string>(); clientDto.ClientName = clientName; } await ServiceClient.UpdateClient(clientId, clientDto); Logger.Info($"ServiceClient '{clientId}' at '{ServiceClient.ServiceUri}' updated."); }
public override async Task Execute() { var serviceHookId = CommandArgumentValue.GetArgumentScalarValue <string>(_serviceHookIdArg); var isEnabled = CommandArgumentValue.GetArgumentScalarValueOrDefault <bool>(_isEnabledArg); var name = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_nameArg); var serviceHookBaseUri = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_serviceHookBaseUriArg); var serviceHookAction = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_serviceHookActionArg); var ckId = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_ckIdArg); Logger.Info( $"Update service hook '{serviceHookId}' at '{_tenantClient.ServiceUri}'"); List <FieldFilterDto> fieldFilters = new List <FieldFilterDto>(); if (CommandArgumentValue.IsArgumentUsed(_filterArg)) { var filterArgData = CommandArgumentValue.GetArgumentValue(_filterArg); foreach (var filterArg in filterArgData.Values) { var terms = filterArg.Split(" "); if (terms.Length != 3) { throw new InvalidOperationException( $"Filter term '{filterArg}' is invalid. Three terms needed."); } var attribute = terms[0].Trim('\''); if (!Enum.TryParse(terms[1], true, out FieldFilterOperatorDto operatorDto)) { throw new InvalidOperationException($"Operator '{terms[1]}' of term '{filterArg}' is invalid."); } var comparisionValue = terms[2].Trim('\''); fieldFilters.Add(new FieldFilterDto { AttributeName = attribute, Operator = operatorDto, ComparisonValue = comparisionValue }); } } var getQuery = new GraphQLRequest { Query = GraphQl.GetServiceHookDetails, Variables = new { rtId = serviceHookId } }; var getResult = await _tenantClient.SendQueryAsync <RtServiceHookDto>(getQuery); if (!getResult.Items.Any()) { throw new InvalidOperationException( $"Service Hook with ID '{serviceHookId}' does not exist."); } var serviceHookDto = getResult.Items.First(); var updateServiceHook = new ServiceHookMutationDto { Enabled = isEnabled, Name = name, QueryCkId = ckId, FieldFilter = JsonConvert.SerializeObject(fieldFilters), ServiceHookBaseUri = serviceHookBaseUri, ServiceHookAction = serviceHookAction }; var updateQuery = new GraphQLRequest { Query = GraphQl.UpdateServiceHook, Variables = new { entities = new[] { new MutationDto <ServiceHookMutationDto> { RtId = serviceHookDto.RtId, Item = updateServiceHook } } } }; var result = await _tenantClient.SendMutationAsync <IEnumerable <RtServiceHookDto> >(updateQuery); Logger.Info($"Service hook '{serviceHookId}' updated (ID '{result.First().RtId}')."); }