Exemplo n.º 1
0
        public override Task <AddResponse> Add(AddRequest request, ServerCallContext context)
        {
            var options = new CovertCode.Services.Secret.Infrastructure.SecretRepositoryOptions()
            {
                DbConnectionString = _config["AppSettings:DbConnectionString"].ToString()
            };

            var core   = new Core.SecretManager(options);
            var secret = new Contracts.DTOs.SecretDto()
            {
                Value        = request.Value,
                AccessPhrase = Guid.NewGuid().ToString("N").Substring(0, 8),
                ExpireDate   = DateTime.UtcNow.AddSeconds(request.Ttl),
                PassPhrase   = string.IsNullOrEmpty(request.PassPhrase) ? string.Empty : request.PassPhrase
            };

            var savedSecret = core.Add(secret);

            return(Task.FromResult(new AddResponse
            {
                WasSuccessful = (savedSecret.SecretId > 0),
                SecretID = (savedSecret.SecretId > 0) ? savedSecret.SecretId : -1,
                AccessPhrase = savedSecret.AccessPhrase
            }));
        }
Exemplo n.º 2
0
        public override Task <GetByAccessPhraseResponse> GetByAccessPhrase(GetByAccessPhraseRequest request, ServerCallContext context)
        {
            var options = new CovertCode.Services.Secret.Infrastructure.SecretRepositoryOptions()
            {
                DbConnectionString = _config["AppSettings:DbConnectionString"].ToString()
            };

            var core   = new Core.SecretManager(options);
            var secret = core.GetByAccessPhrase(request.AccessPhrase);

            return(Task.FromResult(new GetByAccessPhraseResponse
            {
                WasSuccessful = (secret.SecretId > 0),
                Value = secret.Value
            }));
        }