Ejemplo n.º 1
0
        /// <summary>
        /// Validates the options and also ensures that all <c>null</c> properties are
        /// initialized to their default values.
        /// </summary>
        /// <param name="clusterDefinition">The cluster definition.</param>
        /// <exception cref="ClusterDefinitionException">Thrown if the definition is not valid.</exception>
        public void Validate(ClusterDefinition clusterDefinition)
        {
            Covenant.Requires <ArgumentNullException>(clusterDefinition != null, nameof(clusterDefinition));

            var issuerSpecPrefix = $"{nameof(IssuerSpec)}";

            Acme = Acme ?? new AcmeIssuer();
            Acme.Validate(clusterDefinition);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates the options and also ensures that all <c>null</c> properties are
        /// initialized to their default values.
        /// </summary>
        /// <param name="clusterDefinition">The cluster definition.</param>
        /// <exception cref="ClusterDefinitionException">Thrown if the definition is not valid.</exception>
        public void Validate(ClusterDefinition clusterDefinition)
        {
            Covenant.Requires <ArgumentNullException>(clusterDefinition != null, nameof(clusterDefinition));

            var acmeOptionsPrefix = $"{nameof(ClusterDefinition.Network.AcmeOptions)}";

            Issuer = Issuer ?? new AcmeIssuer();
            Issuer.Validate(clusterDefinition);

            // Validate the certificate durations.

            CertificateDuration ??= defaultCertificateDuration;
            CertificateRenewBefore ??= defaultCertificateRenewBefore;

            if (!GoDuration.TryParse(CertificateDuration, out var duration))
            {
                throw new ClusterDefinitionException($"[{acmeOptionsPrefix}.{nameof(CertificateDuration)}={CertificateDuration}] cannot be parsed as a GOLANG duration.");
            }

            if (!GoDuration.TryParse(CertificateRenewBefore, out var renewBefore))
            {
                throw new ClusterDefinitionException($"[{acmeOptionsPrefix}.{nameof(CertificateRenewBefore)}={CertificateRenewBefore}] cannot be parsed as a GOLANG duration.");
            }

            if (duration.TimeSpan < TimeSpan.FromSeconds(1))
            {
                throw new ClusterDefinitionException($"[{acmeOptionsPrefix}.{nameof(CertificateDuration)}={CertificateDuration}] cannot be less than 1 second.");
            }

            if (renewBefore.TimeSpan < TimeSpan.FromSeconds(1))
            {
                throw new ClusterDefinitionException($"[{acmeOptionsPrefix}.{nameof(CertificateRenewBefore)}={CertificateRenewBefore}] cannot be less than 1 second.");
            }

            if (duration.TimeSpan < renewBefore.TimeSpan)
            {
                throw new ClusterDefinitionException($"[{acmeOptionsPrefix}.{nameof(CertificateDuration)}={CertificateDuration}] is not greater than or equal to [{acmeOptionsPrefix}.{nameof(CertificateRenewBefore)}={CertificateRenewBefore}].");
            }
        }