public override async Task Execute()
        {
            var alias = CommandArgumentValue.GetArgumentScalarValue <string>(_alias);
            var type  = CommandArgumentValue.GetArgumentScalarValue <IdentityProviderTypesDto>(_type);

            Logger.Info($"Creating identity provider '{@alias}' at '{ServiceClient.ServiceUri}'");

            if (type == IdentityProviderTypesDto.Google)
            {
                var identityProviderDto = new GoogleIdentityProviderDto
                {
                    IsEnabled    = CommandArgumentValue.GetArgumentScalarValue <bool>(_enabled),
                    ClientId     = CommandArgumentValue.GetArgumentScalarValue <string>(_clientId),
                    ClientSecret = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_clientSecret),
                    Alias        = alias
                };
                await ServiceClient.CreateIdentityProvider(identityProviderDto);
            }
            else if (type == IdentityProviderTypesDto.Microsoft)
            {
                var identityProviderDto = new MicrosoftIdentityProviderDto
                {
                    IsEnabled    = CommandArgumentValue.GetArgumentScalarValue <bool>(_enabled),
                    ClientId     = CommandArgumentValue.GetArgumentScalarValue <string>(_clientId),
                    ClientSecret = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_clientSecret),
                    Alias        = alias
                };
                await ServiceClient.CreateIdentityProvider(identityProviderDto);
            }



            Logger.Info($"ServiceClient '{alias}' at '{ServiceClient.ServiceUri}' created.");
        }
        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}').");
        }
Esempio n. 3
0
        public override async Task Execute()
        {
            var id = CommandArgumentValue.GetArgumentScalarValue <string>(_id);


            Logger.Info($"Deleting identity provider '{id}' from '{ServiceClient.ServiceUri}'");

            await ServiceClient.DeleteIdentityProvider(id);

            Logger.Info($"Identity provider '{id}' deleted.");
        }
        public override async Task Execute()
        {
            Logger.Info("Adding admin");

            var eMail    = CommandArgumentValue.GetArgumentScalarValue <string>(_eMailArg);
            var password = CommandArgumentValue.GetArgumentScalarValue <string>(_passwordArg);

            await _identityServicesSetupClient.AddAdminUser(new AdminUserDto
            {
                EMail    = eMail,
                Password = password
            });
        }
        public override async Task Execute()
        {
            var serviceHookId = CommandArgumentValue.GetArgumentScalarValue <string>(_serviceHookIdArg);

            Logger.Info($"Deleting service hook '{serviceHookId}' at '{_tenantClient.ServiceUri}'");

            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 deleteMutation = new GraphQLRequest
            {
                Query     = GraphQl.DeleteServiceHook,
                Variables = new
                {
                    entities = new[]
                    {
                        new MutationDto
                        {
                            RtId = serviceHookDto.RtId
                        }
                    }
                }
            };

            var result = await _tenantClient.SendMutationAsync <bool>(deleteMutation);

            if (result)
            {
                Logger.Info($"Service hook '{serviceHookId}' deleted.");
            }
            else
            {
                Logger.Error($"Service hook '{serviceHookId}' delete failed.");
            }
        }
Esempio n. 6
0
        public override async Task Execute()
        {
            Logger.Info(
                $"Resetting notification messages at '{Options.Value.CoreServiceUrl}' for tenant '{Options.Value.TenantId}'");

            var type = CommandArgumentValue.GetArgumentScalarValue <NotificationTypesDto>(_type);

            var filterList = new List <FieldFilterDto>
            {
                new FieldFilterDto
                {
                    AttributeName   = nameof(NotificationMessageDto.SendStatus),
                    Operator        = FieldFilterOperatorDto.Equals,
                    ComparisonValue = SendStatusDto.Error
                },
                new FieldFilterDto
                {
                    AttributeName   = nameof(NotificationMessageDto.NotificationType),
                    Operator        = FieldFilterOperatorDto.Equals,
                    ComparisonValue = type
                }
            };

            var getQuery = new GraphQLRequest
            {
                Query     = GraphQl.GetNotifications,
                Variables = new { fieldFilters = filterList.ToArray() }
            };

            var getResult = await _tenantClient.SendQueryAsync <NotificationMessageDto>(getQuery);

            if (!getResult.Items.Any())
            {
                Logger.Info($"No notifications in error has been returned.");
                return;
            }
            Logger.Info($"{getResult.Items.Count()} notification messages in error has been returned.");

            foreach (var notificationMessageDto in getResult.Items)
            {
                notificationMessageDto.LastTryDateTime = DateTime.UtcNow.AddMinutes(-10);
                notificationMessageDto.SendStatus      = SendStatusDto.Pending;
            }

            await _notificationRepository.StoreNotificationMessages(Options.Value.TenantId, getResult.Items);

            Logger.Info($"Reset notficiation messages completed.");
        }
        public override async Task Execute()
        {
            Logger.Info(
                $"Completing notification messages at '{Options.Value.CoreServiceUrl}' for tenant '{Options.Value.TenantId}'");

            var type = CommandArgumentValue.GetArgumentScalarValue <NotificationTypesDto>(_type);

            var result = await _notificationRepository.GetPendingMessagesAsync(Options.Value.TenantId, type);

            foreach (var notificationMessageDto in result.List)
            {
                notificationMessageDto.SentDateTime = DateTime.UtcNow;
                notificationMessageDto.SendStatus   = SendStatusDto.Sent;
            }

            await _notificationRepository.StoreNotificationMessages(Options.Value.TenantId, result.List);

            Logger.Info($"Notficiation message completed.");
        }
Esempio n. 8
0
        public override async Task Execute()
        {
            var rtModelFilePath = CommandArgumentValue.GetArgumentScalarValue <string>(_fileArg);
            var queryId         = CommandArgumentValue.GetArgumentScalarValue <OspObjectId>(_queryIdArg);

            var tenantId = Options.Value.TenantId;

            if (string.IsNullOrWhiteSpace(tenantId))
            {
                throw new ServiceConfigurationMissingException("Tenant is missing.");
            }

            Logger.Info("Exporting runtime data of query '{0}' to '{1}'", queryId, rtModelFilePath);

            var id = await _coreServicesClient.ExportRtModel(tenantId, queryId);

            Logger.Info($"Runtime model export id '{id}' has been started.");
            await WaitForJob(id);

            await DownloadJobResultAsync(id, rtModelFilePath);
        }
        public override async Task Execute()
        {
            var id = CommandArgumentValue.GetArgumentScalarValue <string>(_id);

            Logger.Info($"Updating identity provider '{id}' at '{ServiceClient.ServiceUri}'");

            var identityProviderDto = await ServiceClient.GetIdentityProvider(id);

            if (identityProviderDto == null)
            {
                Logger.Error($"Identity provider '{id}' at '{ServiceClient.ServiceUri}' not found.");
                return;
            }

            if (identityProviderDto is GoogleIdentityProviderDto)
            {
                var newIdentityProviderDto = new GoogleIdentityProviderDto
                {
                    Id           = identityProviderDto.Id,
                    IsEnabled    = CommandArgumentValue.GetArgumentScalarValue <bool>(_enabled),
                    ClientId     = CommandArgumentValue.GetArgumentScalarValue <string>(_clientId),
                    ClientSecret = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_clientSecret),
                    Alias        = CommandArgumentValue.GetArgumentScalarValue <string>(_alias)
                };
                await ServiceClient.UpdateIdentityProvider(id, identityProviderDto);
            }
            else if (identityProviderDto is MicrosoftIdentityProviderDto)
            {
                var newIdentityProviderDto = new MicrosoftIdentityProviderDto
                {
                    IsEnabled    = CommandArgumentValue.GetArgumentScalarValue <bool>(_enabled),
                    ClientId     = CommandArgumentValue.GetArgumentScalarValue <string>(_clientId),
                    ClientSecret = CommandArgumentValue.GetArgumentScalarValueOrDefault <string>(_clientSecret),
                    Alias        = CommandArgumentValue.GetArgumentScalarValue <string>(_alias),
                };
                await ServiceClient.UpdateIdentityProvider(id, newIdentityProviderDto);
            }

            Logger.Info($"Identity provider '{id}' at '{ServiceClient.ServiceUri}' updated.");
        }
Esempio n. 10
0
        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}').");
        }