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 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.");
        }
Example #3
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}').");
        }