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); }
protected override async Task WaitForJob(string id) { if (CommandArgumentValue.IsArgumentUsed(_waitForJobArg)) { await base.WaitForJob(id); } }
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() { bool isInteractive = CommandArgumentValue.IsArgumentUsed(_interactiveArg); Logger.Info($"Device log-in at '{Options.Value.IdentityServiceUrl}' in progress..."); var response = await _authenticatorClient.RequestDeviceAuthorizationAsync( CommonConstants.ApiScopes.IdentityApiFullAccess | CommonConstants.ApiScopes.SystemApiFullAccess | CommonConstants.ApiScopes.JobApiFullAccess); Logger.Info($"Device Code: {response.DeviceCode}"); Logger.Info($"Estimated code expiration at: {response.ExpiresAt}"); Logger.Info(""); Logger.Info(""); Logger.Info($"Using a browser, visit:"); Logger.Info($"{response.VerificationUri}"); Logger.Info($"Enter the code:"); Logger.Info($"{response.UserCode}"); if (isInteractive) { Logger.Info($"Opening default browser..."); Process.Start(new ProcessStartInfo(response.VerificationUriComplete) { UseShellExecute = true }); } while (true) { Logger.Info("Waiting for device authentication..."); Thread.Sleep(response.PollingInterval * 1000); var authenticationData = await _authenticatorClient.RequestDeviceTokenAsync(response.DeviceCode); if (authenticationData.IsAuthenticationPending) { Thread.Sleep(response.PollingInterval * 1000); continue; } _authenticationService.SaveAuthenticationData(authenticationData); Logger.Info($"Device log-in successful. Token expires at '{authenticationData.ExpiresAt}'."); break; } }
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}')."); }