private void CreateAuthorizationServerResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
 {
     if (creatorConfig.AuthorizationServers != null)
     {
         CreateResource(resources, creatorConfig, _templateFileNames.AuthorizationServers(), _nestedTemplateName.AuthorizationServers());
     }
 }
 private void CreatePropertyResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
 {
     if (creatorConfig.NamedValues != null)
     {
         CreateResource(resources, creatorConfig, _templateFileNames.NamedValues(), _nestedTemplateName.NamedValues());
     }
 }
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var template = EmptyTemplate;

            template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var resources = new List <TemplateResource>();

            foreach (LoggerDeploymentDefinition logger in creatorConfig.Loggers)
            {
                var loggerTemplateResource = new LoggerTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{logger.Name}')]",
                    Properties = new LoggerProperties()
                    {
                        LoggerType  = logger.LoggerType,
                        Description = logger.Description,
                        Credentials = logger.Credentials,
                        IsBuffered  = logger.IsBuffered,
                        ResourceId  = logger.ResourceId
                    },
                    DependsOn = new string[] { }
                };
                resources.Add(loggerTemplateResource);
            }

            template.Resources = resources.ToArray();
            return(await Task.FromResult(template));
        }
Exemplo n.º 4
0
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var template = EmptyTemplate;

            template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var resources = new List <TemplateResource>();

            foreach (var apiVersionSet in creatorConfig.ApiVersionSets)
            {
                var apiVersionSetTemplateResource = new APIVersionSetTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{apiVersionSet.Name}')]",
                    Properties = new ApiVersionSetProperties()
                    {
                        DisplayName       = apiVersionSet.DisplayName,
                        Description       = apiVersionSet.Description,
                        VersionHeaderName = apiVersionSet.VersionHeaderName,
                        VersionQueryName  = apiVersionSet.VersionQueryName,
                        VersioningScheme  = apiVersionSet.VersioningScheme,
                    },
                    DependsOn = new string[] { }
                };

                resources.Add(apiVersionSetTemplateResource);
            }

            template.Resources = resources.ToArray();
            return(await Task.FromResult(template));
        }
 private void CreateBackendResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
 {
     if (creatorConfig.Backends != null)
     {
         CreateResource(resources, creatorConfig, _templateFileNames.Backends(), _nestedTemplateName.Backends());
     }
 }
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var template = EmptyTemplate;

            template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var fileReader = new FileReader();
            var policy     = creatorConfig.Policy;
            var isUrl      = policy.IsUri(out _);

            var policyTemplateResource = new PolicyTemplateResource()
            {
                Name       = $"[concat(parameters('ApimServiceName'), '/policy')]",
                Properties = new PolicyProperties()
                {
                    Format = isUrl ? "rawxml-link" : "rawxml",
                    Value  = isUrl ? policy : await fileReader.RetrieveFileContentsAsync(policy)
                },
                DependsOn = new string[0]
            };

            template.Resources = new TemplateResource[] { policyTemplateResource };

            return(await Task.FromResult(template));
        }
 private void CreateGlobalPolicyResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
 {
     if (creatorConfig.Policy != null)
     {
         CreateResource(resources, creatorConfig, _templateFileNames.GlobalServicePolicy(), _nestedTemplateName.GlobalServicePolicy());
     }
 }
        public Template CreateMasterTemplateParameterValues(DeploymentDefinition creatorConfig)
        {
            var masterTemplate = EmptyTemplate;

            // add parameters with value property
            Dictionary <string, TemplateParameterProperties> parameters = new Dictionary <string, TemplateParameterProperties>();
            TemplateParameterProperties apimServiceNameProperties       = new TemplateParameterProperties()
            {
                value = creatorConfig.ApimServiceName
            };

            parameters.Add("ApimServiceName", apimServiceNameProperties);

            TemplateParameterProperties linkedTemplatesBaseUrlProperties = new TemplateParameterProperties()
            {
                value = creatorConfig.LinkedTemplatesBaseUrl
            };

            parameters.Add("LinkedTemplatesBaseUrl", linkedTemplatesBaseUrlProperties);

            if (creatorConfig.LinkedTemplatesUrlQueryString != null)
            {
                TemplateParameterProperties linkedTemplatesUrlQueryStringProperties = new TemplateParameterProperties()
                {
                    value = creatorConfig.LinkedTemplatesUrlQueryString
                };
                parameters.Add("LinkedTemplatesUrlQueryString", linkedTemplatesUrlQueryStringProperties);
            }


            masterTemplate.Parameters = parameters;
            return(masterTemplate);
        }
        private async Task CreateResources(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
        {
            CreateGlobalPolicyResource(creatorConfig, resources);

            CreateNamedValueResource(creatorConfig, resources);

            CreateApiVersionSetResource(creatorConfig, resources);

            CreateLoggerResource(creatorConfig, resources);

            CreateBackendResource(creatorConfig, resources);

            CreateAuthorizationServerResource(creatorConfig, resources);

            CreateProductResource(creatorConfig, resources);

            CreateTagResource(creatorConfig, resources);

            CreateUserResource(creatorConfig, resources);

            CreateSubscriptionResource(creatorConfig, resources);

            CreateCertificateResource(creatorConfig, resources);

            await CreateApiResource(creatorConfig, resources);
        }
Exemplo n.º 10
0
 private void CreateCertificateResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
 {
     if (creatorConfig.Certificates != null)
     {
         CreateResource(resources, creatorConfig, _templateFileNames.Certificates(), _nestedTemplateName.Certificates());
     }
 }
Exemplo n.º 11
0
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var template = EmptyTemplate;

            template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var resources = new List <TemplateResource>();

            foreach (var product in creatorConfig.Products)
            {
                // create product resource with properties
                var productsTemplateResource = new ProductsTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{product.Name}')]",
                    Properties = new ProductsProperties()
                    {
                        Description          = product.Description,
                        Terms                = product.Terms,
                        SubscriptionRequired = product.SubscriptionRequired,
                        ApprovalRequired     = product.SubscriptionRequired ? product.ApprovalRequired : null,
                        SubscriptionsLimit   = product.SubscriptionRequired ? product.SubscriptionsLimit : null,
                        State                = product.State,
                        DisplayName          = product.DisplayName
                    },
                    DependsOn = new string[] { }
                };

                resources.Add(productsTemplateResource);

                resources.AddRange(await CreateChildResourceTemplates(product));
            }

            template.Resources = resources.ToArray();
            return(await Task.FromResult(template));
        }
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var fileReader = new FileReader();

            var template = EmptyTemplate;

            template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var resources = new List <TemplateResource>();

            foreach (var certificateTemplatePropeties in creatorConfig.Certificates)
            {
                certificateTemplatePropeties.Data = await fileReader.RetrieveFileContentsAsync(certificateTemplatePropeties.FilePath, convertToBase64 : true);

                var certificateTemplateResource = new CertificateTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{certificateTemplatePropeties.Name}')]",
                    Properties = new CertificateProperties()
                    {
                        Data     = certificateTemplatePropeties.Data,
                        Password = certificateTemplatePropeties.Password
                    },
                    DependsOn = new string[] { }
                };
                resources.Add(certificateTemplateResource);
            }

            template.Resources = resources.ToArray();
            return(await Task.FromResult(template));
        }
Exemplo n.º 13
0
        private void CreateResource(List <TemplateResource> resources, DeploymentDefinition creatorConfig, string fileName, string templateResourceName, IEnumerable <string> dependencies = null)
        {
            string linkedUri = GenerateLinkedTemplateUri(creatorConfig, fileName);

            var masterTemplateResource = CreateLinkedMasterTemplateResource(templateResourceName, linkedUri, dependencies ?? new string[0]);

            resources.Add(masterTemplateResource);
        }
Exemplo n.º 14
0
        public bool Validate(DeploymentDefinition creatorConfig)
        {
            // ensure required parameters have been passed in

            return(ValidateBaseProperties(creatorConfig) &&
                   ValidateAPIs(creatorConfig) &&
                   ValidateAPIVersionSets(creatorConfig) &&
                   ValidateProducts(creatorConfig) &&
                   ValidateLoggers(creatorConfig) &&
                   ValidateAuthorizationServers(creatorConfig) &&
                   ValidateBackends(creatorConfig));
        }
Exemplo n.º 15
0
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            Template masterTemplate = EmptyTemplate;

            masterTemplate.Parameters = this.CreateMasterTemplateParameters(creatorConfig);

            var resources = new List <TemplateResource>();

            await CreateResources(creatorConfig, resources);

            masterTemplate.Resources = resources.ToArray();
            return(masterTemplate);
        }
Exemplo n.º 16
0
        private async Task <string[]> CreateApiResourceDependencies(DeploymentDefinition creatorConfig, ApiDeploymentDefinition api)
        {
            var fileReader = new FileReader();

            List <string> apiDependsOn = new List <string>();

            if (api.IsDependOnGlobalServicePolicies(creatorConfig))
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.GlobalServicePolicy()));
            }
            if (api.IsDependOnNamedValues(creatorConfig))
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.NamedValues()));
            }
            if (api.IsDependOnApiVersionSet())
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.ApiVersionSets()));
            }

            if (api.IsDependOnProducts() && creatorConfig.Products?.Count > 0)
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.Products()));
            }

            if (api.IsDependOnTags() && creatorConfig.Tags?.Count > 0)
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.Tags()));
            }

            if (await api.IsDependOnLogger(fileReader) && creatorConfig.Loggers != null)
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.Loggers()));
            }

            if (await api.IsDependOnBackend(fileReader) && creatorConfig.Backends != null)
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.Backends()));
            }

            if (api.IsDependOnAuthorizationServers())
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.AuthorizationServers()));
            }

            if (creatorConfig.Certificates != null)
            {
                apiDependsOn.Add(DependsOn(_nestedTemplateName.Certificates()));
            }

            return(apiDependsOn.ToArray());
        }
Exemplo n.º 17
0
 private bool ValidateBackends(DeploymentDefinition creatorConfig)
 {
     if (creatorConfig.Backends != null)
     {
         foreach (var backend in creatorConfig.Backends)
         {
             if (backend.Title == null)
             {
                 throw new ArgumentException("Title is required if a Backend is provided");
             }
         }
     }
     return(true);
 }
Exemplo n.º 18
0
 private bool ValidateLoggers(DeploymentDefinition creatorConfig)
 {
     if (creatorConfig.Loggers != null)
     {
         foreach (LoggerDeploymentDefinition logger in creatorConfig.Loggers)
         {
             if (logger.Name == null)
             {
                 throw new ArgumentException("Name is required if an Logger is provided");
             }
         }
     }
     return(true);
 }
Exemplo n.º 19
0
 private bool ValidateAuthorizationServers(DeploymentDefinition creatorConfig)
 {
     if (creatorConfig.AuthorizationServers != null)
     {
         foreach (var authorizationServer in creatorConfig.AuthorizationServers)
         {
             if (authorizationServer.displayName == null)
             {
                 throw new ArgumentException("Display name is required if an Authorization Server is provided");
             }
         }
     }
     return(true);
 }
Exemplo n.º 20
0
        private void CreateProductResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
        {
            if (creatorConfig.Products != null)
            {
                var dependencies = new List <string>();

                if (creatorConfig.Tags != null && creatorConfig.Products.Any(q => q.IsDependOnTags()))
                {
                    dependencies.Add(DependsOn(_nestedTemplateName.Tags()));
                }

                if (creatorConfig.Certificates != null)
                {
                    dependencies.Add(DependsOn(_nestedTemplateName.Certificates()));
                }

                CreateResource(resources, creatorConfig, _templateFileNames.Products(), _nestedTemplateName.Products(), dependencies);
            }
        }
Exemplo n.º 21
0
        private bool ValidateAPIVersionSets(DeploymentDefinition creatorConfig)
        {
            if (creatorConfig.ApiVersionSets != null)
            {
                foreach (ApiVersionSetDeploymentDefinition apiVersionSet in creatorConfig.ApiVersionSets)
                {
                    if (apiVersionSet != null && apiVersionSet.DisplayName == null)
                    {
                        throw new ArgumentException("Display name is required if an API Version Set is provided");
                    }

                    if (apiVersionSet != null && apiVersionSet.Name == null)
                    {
                        throw new ArgumentException("Name is required if an API Version Set is provided");
                    }
                }
            }
            return(true);
        }
Exemplo n.º 22
0
        private async Task CreateApiResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
        {
            for (var i = 0; i < creatorConfig.Apis.Count; i++)
            {
                var api = creatorConfig.Apis[i];

                var initialAPIDependsOn = new List <string>(await CreateApiResourceDependencies(creatorConfig, api));

                if (i > 0)
                {
                    var previousApi = creatorConfig.Apis[i - 1];
                    initialAPIDependsOn.Add(DependsOn(_nestedTemplateName.ApiSubsequent(previousApi.Name)));
                }

                CreateResource(resources, creatorConfig, _templateFileNames.ApiInitial(api.Name), _nestedTemplateName.ApiInitial(api.Name), initialAPIDependsOn);
                CreateResource(resources, creatorConfig, _templateFileNames.ApiSubsequent(api.Name), _nestedTemplateName.ApiSubsequent(api.Name),
                               new [] { DependsOn(_nestedTemplateName.ApiInitial(api.Name)) });
            }
        }
Exemplo n.º 23
0
        private bool ValidateProducts(DeploymentDefinition creatorConfig)
        {
            if (creatorConfig.Products != null)
            {
                foreach (var product in creatorConfig.Products)
                {
                    if (product.DisplayName == null)
                    {
                        throw new ArgumentException("Display name is required if an Product is provided");
                    }

                    if (product.Name == null)
                    {
                        throw new ArgumentException("Name is required if an Product is provided");
                    }
                }
            }

            return(true);
        }
Exemplo n.º 24
0
 private bool ValidateBaseProperties(DeploymentDefinition creatorConfig)
 {
     if (creatorConfig.OutputLocation == null)
     {
         throw new ArgumentException("Output location is required");
     }
     if (creatorConfig.Version == null)
     {
         throw new ArgumentException("Version is required");
     }
     if (creatorConfig.ApimServiceName == null)
     {
         throw new ArgumentException("APIM service name is required");
     }
     if (creatorConfig.LinkedTemplatesBaseUrl == null)
     {
         throw new ArgumentException("LinkTemplatesBaseUrl is required for linked templates");
     }
     return(true);
 }
Exemplo n.º 25
0
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var template = EmptyTemplate;

            template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var resources = new List <TemplateResource>();

            foreach (var backendTemplatePropeties in creatorConfig.Backends)
            {
                var backendTemplateResource = new BackendTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{backendTemplatePropeties.Title}')]",
                    Properties = backendTemplatePropeties,
                    DependsOn  = new string[] { }
                };
                resources.Add(backendTemplateResource);
            }

            template.Resources = resources.ToArray();
            return(await Task.FromResult(template));
        }
Exemplo n.º 26
0
 private bool ValidateAPIs(DeploymentDefinition creatorConfig)
 {
     if (creatorConfig.Apis == null)
     {
         throw new ArgumentException("API configuration is required");
     }
     foreach (ApiDeploymentDefinition api in creatorConfig.Apis)
     {
         if (api.Name == null)
         {
             throw new ArgumentException("API name is required");
         }
         if (api.OpenApiSpec == null)
         {
             throw new ArgumentException("Open API Spec is required");
         }
         if (api.Path == null)
         {
             throw new ArgumentException("API path is required");
         }
         if (api.Operations != null)
         {
             foreach (KeyValuePair <string, OperationsDeploymentDefinition> operation in api.Operations)
             {
                 if (operation.Value == null || operation.Value.Policy == null)
                 {
                     throw new ArgumentException("Policy XML is required if an API operation is provided");
                 }
             }
         }
         if (api.Diagnostic != null && api.Diagnostic.LoggerId == null)
         {
             throw new ArgumentException("LoggerId is required if an API diagnostic is provided");
         }
     }
     return(true);
 }
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var authorizationTemplate = EmptyTemplate;

            authorizationTemplate.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var resources = new List <TemplateResource>();

            foreach (var authorizationServerTemplateProperties in creatorConfig.AuthorizationServers)
            {
                // create authorization server resource with properties
                var authorizationServerTemplateResource = new AuthorizationServerTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{authorizationServerTemplateProperties.displayName}')]",
                    Properties = authorizationServerTemplateProperties,
                    DependsOn  = new string[] { }
                };
                resources.Add(authorizationServerTemplateResource);
            }

            authorizationTemplate.Resources = resources.ToArray();

            return(await Task.FromResult(authorizationTemplate));
        }
Exemplo n.º 28
0
        private void CreateSubscriptionResource(DeploymentDefinition creatorConfig, List <TemplateResource> resources)
        {
            if (creatorConfig.Subscriptions != null)
            {
                var dependencies = new List <string>();

                if (creatorConfig.Products != null)
                {
                    dependencies.Add(DependsOn(_nestedTemplateName.Products()));
                }

                if (creatorConfig.Users != null)
                {
                    dependencies.Add(DependsOn(_nestedTemplateName.Users()));
                }

                foreach (var api in creatorConfig.Apis)
                {
                    dependencies.Add(DependsOn(_nestedTemplateName.ApiInitial(api.Name)));
                }

                CreateResource(resources, creatorConfig, _templateFileNames.Subscriptions(), _nestedTemplateName.Subscriptions(), dependencies.ToArray());
            }
        }
 public bool IsDependOnGlobalServicePolicies(DeploymentDefinition creatorConfig) => creatorConfig.Policy != null;
 public bool IsDependOnNamedValues(DeploymentDefinition creatorConfig) => creatorConfig.NamedValues != null;