public static Uri HasReconcilePermissionUrl(EnvironmentConfig environmentConfig, string projectId)
        {
            if (environmentConfig == null)
            {
                throw new ArgumentNullException(nameof(environmentConfig));
            }
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId));
            }

            return(new Uri($"https://{environmentConfig.FunctionAppHostname}/api/reconcile/{environmentConfig.Organization}/{projectId}/haspermissions"));
        }
        public static Reconcile ReconcileFromRule(EnvironmentConfig environmentConfig, string projectId, IProjectReconcile rule)
        {
            if (environmentConfig == null)
            {
                throw new ArgumentNullException(nameof(environmentConfig));
            }
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId));
            }

            return(rule != null ? new Reconcile
            {
                Url = new Uri($"https://{environmentConfig.FunctionAppHostname}/api/reconcile/{environmentConfig.Organization}/{projectId}/globalpermissions/{rule.GetType().Name}"),
                Impact = rule.Impact
            } : null);
        }
Beispiel #3
0
        private static void RegisterServices(IServiceCollection services)
        {
            var token        = GetEnvironmentVariable("TOKEN");
            var organization = GetEnvironmentVariable("ORGANIZATION");

            services.AddSingleton <IVstsRestClient>(new VstsRestClient(organization, token));
            services.AddSingleton <IMemoryCache>(_ => new MemoryCache(new MemoryCacheOptions()));

            var config = new EnvironmentConfig
            {
                ExtensionName       = GetEnvironmentVariable("EXTENSION_NAME"),
                ExtensionPublisher  = GetEnvironmentVariable("EXTENSION_PUBLISHER"),
                Organization        = organization,
                FunctionAppHostname = GetEnvironmentVariable("WEBSITE_HOSTNAME"),
            };

            services.AddSingleton(config);
            services.AddSingleton <ITokenizer>(new Tokenizer(GetEnvironmentVariable("EXTENSION_SECRET")));

            services.AddDefaultRules();
            services.AddSingleton(new HttpClient());

            services.AddSingleton <IPoliciesResolver, PoliciesResolver>();
        }