public async Task <bool> DetermineIfAPIDependsOnLoggerAsync(APIConfig api, FileReader fileReader)
        {
            if (api.diagnostic != null && api.diagnostic.loggerId != null)
            {
                // capture api diagnostic dependent on logger
                return(true);
            }
            string apiPolicy = api.policy != null ? await fileReader.RetrieveFileContentsAsync(api.policy) : "";

            if (apiPolicy.Contains("logger"))
            {
                // capture api policy dependent on logger
                return(true);
            }
            if (api.operations != null)
            {
                foreach (KeyValuePair <string, OperationsConfig> operation in api.operations)
                {
                    string operationPolicy = operation.Value.policy != null ? await fileReader.RetrieveFileContentsAsync(operation.Value.policy) : "";

                    if (operationPolicy.Contains("logger"))
                    {
                        // capture operation policy dependent on logger
                        return(true);
                    }
                }
            }
            return(false);
        }
        public async Task <bool> IsDependOnBackend(FileReader fileReader)
        {
            string apiPolicy = Policy != null ? await fileReader.RetrieveFileContentsAsync(Policy) : "";

            if (apiPolicy.Contains("set-backend-service"))
            {
                return(true);
            }

            if (Operations == null)
            {
                return(false);
            }

            foreach (KeyValuePair <string, OperationsDeploymentDefinition> operation in Operations)
            {
                string operationPolicy = operation.Value.Policy != null ? await fileReader.RetrieveFileContentsAsync(operation.Value.Policy) : "";

                if (operationPolicy.Contains("set-backend-service"))
                {
                    return(true);
                }
            }

            return(false);
        }
        public async Task <bool> IsDependOnLogger(FileReader fileReader)
        {
            if (Diagnostic != null && Diagnostic.LoggerId != null)
            {
                return(true);
            }

            string apiPolicy = Policy != null ? await fileReader.RetrieveFileContentsAsync(Policy) : "";

            if (apiPolicy.Contains("logger"))
            {
                return(true);
            }

            if (Operations != null)
            {
                foreach (KeyValuePair <string, OperationsDeploymentDefinition> operation in Operations)
                {
                    string operationPolicy = operation.Value.Policy != null ? await fileReader.RetrieveFileContentsAsync(operation.Value.Policy) : "";

                    if (operationPolicy.Contains("logger"))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public async Task <IEnumerable <ApiOperationPolicyTemplateResource> > Create(ApiDeploymentDefinition api, string[] dependsOn)
        {
            var fileReader = new FileReader();
            var apiOperationPolicyTemplateResources = new List <ApiOperationPolicyTemplateResource>();

            foreach (var pair in api.Operations)
            {
                var operationPolicy = pair.Value.Policy;
                var operationName   = pair.Key;

                var isUrl = operationPolicy.IsUri(out _);

                var apiOperationPolicyTemplateResource = new ApiOperationPolicyTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{api.Name}/{operationName}/policy')]",
                    Properties = new ApiOperationPolicyProperties()
                    {
                        Format = isUrl ? "rawxml-link" : "rawxml",
                        Value  = isUrl ? api.Policy : await fileReader.RetrieveFileContentsAsync(api.Policy)
                    },
                    DependsOn = dependsOn
                };

                apiOperationPolicyTemplateResources.Add(apiOperationPolicyTemplateResource);
            }

            return(apiOperationPolicyTemplateResources);
        }
        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));
        }
        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));
        }
        public async Task <bool> DetermineIfAPIDependsOnBackendAsync(APIConfig api, FileReader fileReader)
        {
            string apiPolicy = api.policy != null ? await fileReader.RetrieveFileContentsAsync(api.policy) : "";

            if (apiPolicy.Contains("set-backend-service"))
            {
                // capture api policy dependent on backend
                return(true);
            }
            if (api.operations != null)
            {
                foreach (KeyValuePair <string, OperationsConfig> operation in api.operations)
                {
                    string operationPolicy = operation.Value.policy != null ? await fileReader.RetrieveFileContentsAsync(operation.Value.policy) : "";

                    if (operationPolicy.Contains("set-backend-service"))
                    {
                        // capture operation policy dependent on backend
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#8
0
        public async Task <ApiPolicyTemplateResource> Create(ApiDeploymentDefinition api, string[] dependsOn)
        {
            var fileReader = new FileReader();

            var isUrl = api.Policy.IsUri(out _);

            var policyTemplateResource = new ApiPolicyTemplateResource()
            {
                Name       = $"[concat(parameters('ApimServiceName'), '/{api.Name}/policy')]",
                Properties = new ApiPolicyProperties()
                {
                    Format = isUrl ? "rawxml-link" : "rawxml",
                    Value  = isUrl ? api.Policy : await fileReader.RetrieveFileContentsAsync(api.Policy)
                },
                DependsOn = dependsOn
            };

            return(policyTemplateResource);
        }