Example #1
0
        async ValueTask <bool> CacheServices()
        {
            //TODO: need to get service userIds first then get the keys for that service
            var response = await _ropuWebClient.Get <List <ServiceInfo> >("api/Services/All");

            if (response.StatusCode != HttpStatusCode.OK)
            {
                Console.Error.WriteLine("Failed to get services list for cache keys");
                return(false);
            }
            var services = await response.GetJson();

            var keysResponse = await _ropuWebClient.Post <IEnumerable <uint>, List <EntitiesKeys> >(
                "api/Key/UsersKeys",
                services.Select(s => s.UserId));

            if (keysResponse.StatusCode != HttpStatusCode.OK)
            {
                Console.Error.WriteLine($"Failed to get service keys, with response {keysResponse.StatusCode}");
                return(false);
            }

            var entities = await keysResponse.GetJson();

            foreach (var entity in entities)
            {
                var keys = entity.Keys.Select(key => _cachedEncryiptonKeyFactory(key)).ToList();
                if (!_users.TryAdd(entity.UserOrGroupId, keys))
                {
                    _users[entity.UserOrGroupId] = keys;
                }
            }
            return(true);
        }
Example #2
0
        public async ValueTask <bool> Create(NewUser newUser)
        {
            var response = await _client.Post($"api/users/create", newUser);

            if (response.IsSuccessful)
            {
                return(true);
            }
            Console.Error.WriteLine($"Failed to create user {newUser.Name}");
            return(false);
        }
Example #3
0
        async Task UpdateWeb()
        {
            while (!_closing)
            {
                var response = await _webClient.Post("api/Services/UpdateLoadBalancer", new LoadBalancerInfo()
                {
                    IPEndPoint = _settings.PublicIPEndpoint
                });

                if (!response.IsSuccessful)
                {
                    Console.Error.WriteLine($"Failed to update the web with the load balancer status {response.StatusCode}");
                }
                await Task.Delay(5000);
            }
        }