private async Task AddCertificate(JObject policy, DeploymentTemplate template)
        {
            var policyPropertyName    = policy["properties"].Value <string>("policyContent") == null ? "value" : "policyContent";
            var certificateThumbprint = TemplateHelper.GetCertificateThumbPrintIdFromPolicy(policy["properties"].Value <string>(policyPropertyName));

            if (!string.IsNullOrEmpty(certificateThumbprint))
            {
                var certificates = await resourceCollector.GetResource(GetAPIMResourceIDString() + "/certificates");

                if (certificates != null)
                {
                    // If the thumbprint is a property, we must lookup the value of the property first.
                    var match = Regex.Match(certificateThumbprint, "{{(?<name>[-_.a-zA-Z0-9]*)}}");

                    if (match.Success)
                    {
                        string propertyName     = match.Groups["name"].Value;
                        var    propertyResource = await resourceCollector.GetResource(GetAPIMResourceIDString() + $"/properties/{propertyName}");

                        if (propertyResource != null)
                        {
                            certificateThumbprint = propertyResource["properties"].Value <string>("value");
                        }
                    }

                    var certificate = certificates.Value <JArray>("value").FirstOrDefault(x =>
                                                                                          x?["properties"]?.Value <string>("thumbprint") == certificateThumbprint);
                    if (certificate != null)
                    {
                        template.CreateCertificate(JObject.FromObject(certificate), true);
                    }
                }
            }
        }
예제 #2
0
        private async Task AddCertificate(JObject policy, DeploymentTemplate template)
        {
            var certificateThumbprint = TemplateHelper.GetCertificateThumbPrintIdFromPolicy(policy["properties"].Value <string>("policyContent"));

            if (!string.IsNullOrEmpty(certificateThumbprint))
            {
                var certificates = await resourceCollector.GetResource(GetAPIMResourceIDString() + "/certificates");

                if (certificates != null)
                {
                    var certificate = certificates.Value <JArray>("value").FirstOrDefault(x =>
                                                                                          x?["properties"]?.Value <string>("thumbprint") == certificateThumbprint);
                    if (certificate != null)
                    {
                        template.CreateCertificate(JObject.FromObject(certificate), true);
                    }
                }
            }
        }