コード例 #1
0
        public PolicyTemplateResource CreateProductPolicyTemplateResource(ProductConfig product, string[] dependsOn)
        {
            if (string.IsNullOrEmpty(product.name))
            {
                product.name = product.displayName;
            }

            Uri  uriResult;
            bool isUrl = Uri.TryCreate(product.policy, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
            // create policy resource with properties
            PolicyTemplateResource policyTemplateResource = new PolicyTemplateResource()
            {
                name       = $"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{product.name}/policy')]",
                type       = ResourceTypeConstants.ProductPolicy,
                apiVersion = GlobalConstants.APIVersion,
                properties = new PolicyTemplateProperties()
                {
                    // if policy is a url inline the url, if it is a local file inline the file contents
                    format = isUrl ? "rawxml-link" : "rawxml",
                    value  = isUrl ? product.policy : this.fileReader.RetrieveLocalFileContents(product.policy)
                },
                dependsOn = dependsOn
            };

            return(policyTemplateResource);
        }
コード例 #2
0
        public List <ProductGroupsValue> CreateProductGroupTemplateResources(ProductConfig product, string[] dependsOn)
        {
            // create a products/apis association resource for each product provided in the config file
            List <ProductGroupsValue> productGroupTemplates = new List <ProductGroupsValue>();

            // products is comma separated list of productIds
            string[] groupNames = product.groups.Split(", ");
            foreach (string groupName in groupNames)
            {
                ProductGroupsValue productAPITemplate = this.CreateProductGroupTemplateResource(groupName, product.displayName, dependsOn);
                productGroupTemplates.Add(productAPITemplate);
            }
            return(productGroupTemplates);
        }
コード例 #3
0
        public List <SubscriptionsTemplateResource> CreateSubscriptionsTemplateResources(ProductConfig product, string[] dependsOn)
        {
            // TODO: throw error if scope is not null

            var scope = $"/products/{product.name}";

            var resources = new List <SubscriptionsTemplateResource>(product.subscriptions.Count);

            foreach (var subscription in product.subscriptions)
            {
                subscription.scope = scope;
                resources.Add(CreateSubscriptionsTemplateResource(subscription, dependsOn));
            }

            return(resources);
        }