public static string CreateClaimType(ApiNames apiName)
        {
            var apiRoot = $"{TraffkHelpers.TraffkUrn}/claims/apis";

            if (apiName == ApiNames.Base)
            {
                return(apiRoot);
            }

            return($"{apiRoot}/{apiName}");
        }
        private JsonServiceClient PickClientForApiName(ApiNames apiName)
        {
            switch (apiName)
            {
            case ApiNames.BASESPACE:
                return(client);

            case ApiNames.BASESPACE_BILLING:
                return(clientBilling);

            default:
                throw new ArgumentOutOfRangeException("apiName");
            }
        }
        public AllAgentMetricsResponse <T> GetMetrics <T>(IMetricGetByIntervalRequestByClient request, ApiNames apiName)
        {
            var fromParameter = request.FromTime.ToString("O");
            var toParameter   = request.ToTime.ToString("O");
            var httpRequest   = new HttpRequestMessage(
                HttpMethod.Get,
                $"{request.AgentUri}/api/metrics/{apiNames[apiName]}/from/{fromParameter}/to/{toParameter}");

            try
            {
                HttpResponseMessage response = _httpClient.SendAsync(httpRequest).Result;

                using var responseStream = response.Content.ReadAsStreamAsync().Result;
                using var streamReader   = new StreamReader(responseStream);
                var content = streamReader.ReadToEnd();

                var options = new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                };
                var returnResp = JsonSerializer.Deserialize <AllAgentMetricsResponse <T> >(content, options);
                return(returnResp);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(null);
        }
Exemple #4
0
 public static string CreatePolicyName(ApiNames api)
 => $"{nameof(PermissionAuthorizeAttribute)}.{api}";
Exemple #5
0
 public static async Task <bool> HasPermission(this ClaimsPrincipal principal, IAuthorizationService auth, ApiNames api)
 => (await auth.AuthorizeAsync(principal, CreatePolicyName(api))).Succeeded;
 public ApiAuthorizeAttribute(ApiNames api)
     : base(PortalPermissionHelpers.CreatePolicyName(api))
 {
     Api = api;
 }
 public ApiRequirement(ApiNames api)
 {
     Api       = api;
     ClaimType = PermissionHelpers.CreateClaimType(api);
 }