コード例 #1
0
        /// <summary>
        /// Provisions/destroys infrastructure.
        /// </summary>
        /// <param name="provision">The delegate to call after the infrastructure
        /// configuration has been loaded.</param>
        /// <param name="dryrun">Whether or not this is a dryrun.</param>
        private void Process(Provision provision, bool dryrun)
        {
            Validate();

            var platform       = LoadPlatform();
            var infrastructure = platform.Load(Yaml.GetRootNode());

            provision(platform, infrastructure, dryrun);
        }
コード例 #2
0
        /// <summary>
        /// Loads the platform configuration from the given YAML.
        /// </summary>
        /// <returns>The platform configuration loaded from the given YAML.</returns>
        /// <exception cref="KeyNotFoundException">If the platform key is not present
        /// inside the configuration..</exception>
        /// <exception cref="ArgumentException">If the platform is not
        /// supported.</exception>
        public IPlatform LoadPlatform()
        {
            var root               = Yaml.GetRootNode();
            var platformName       = root.GetKey("platform", required: true);
            var availablePlatforms = GetAvailablePlatforms(Assembly);
            var platformSettings   = new PlatformSettings(ApiKey, ApiUrl);

            if (availablePlatforms.TryGetValue(platformName, out var platform))
            {
                return(platform(platformSettings));
            }

            var line = root.GetNode("platform").Start.Line;
            var availablePlatformsText = string.Join(
                ", ", availablePlatforms.Keys);

            throw new ArgumentException(
                      $"Unknown platform {platformName} (line {line}). Available "
                      + $"platforms are: {availablePlatformsText}");
        }
コード例 #3
0
        /// <summary>
        /// Validates the YAML configuration to ensure correctness.
        /// </summary>
        /// <exception cref="AgrixValidationException">If there is a validation
        /// error.</exception>
        public void Validate()
        {
            IPlatform platform;

            try
            {
                platform = LoadPlatform();
            }
            catch (KeyNotFoundException e)
            {
                throw new AgrixValidationException("platform key is missing", e);
            }
            catch (ArgumentException e)
            {
                throw new AgrixValidationException(e.Message, e);
            }

            try
            {
                platform.TestConnection();
            }
            catch (Exception e)
            {
                throw new AgrixValidationException(e.Message, e);
            }

            try
            {
                platform.Load(Yaml.GetRootNode());
            }
            catch (KnownKeyNotFoundException <string> e)
            {
                throw new AgrixValidationException(
                          $"scripts validation error: {e.Message}", e);
            }
        }