Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BootstrapDTOValidator"/> class.
 /// </summary>
 public BootstrapDTOValidator()
 {
     this.RuleFor(x => x.SupportedProtocols).NotNull();
     this.RuleFor(x => x.Hostname).NotEmpty();
     this.RuleFor(x => x.NAMEEndpoint).NotEmpty();
     this.RuleFor(x => x.NAMEPort).Must(p => p == null || p > 0u);
     this.RuleFor(x => x.AppVersion).Must(v => DependencyVersion.TryParse(v, out var version)).WithMessage("Version is not valid.");
     this.RuleFor(x => x.NAMEVersion).Must(v => DependencyVersion.TryParse(v, out var version)).WithMessage("Version is not valid.");
     this.RuleForEach(x => x.SupportedProtocols).GreaterThan(0u);
 }
Ejemplo n.º 2
0
        private OperatingSystemDependencyVersion HandleWindowsOperatingSystem()
        {
#if NET45
            return(new OperatingSystemDependencyVersion("windows", (uint)Environment.OSVersion.Version.Major, (uint)Environment.OSVersion.Version.Minor, (uint)Environment.OSVersion.Version.Build));
#else
            string osDescription  = RuntimeInformation.OSDescription;
            string versionPortion = osDescription.Split(new char[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Last();

            DependencyVersion version;
            if (!DependencyVersion.TryParse(versionPortion, out version))
            {
                throw new NAMEException($"Windows: Was not able to extract the version from the OS description ({osDescription}).");
            }

            return(new OperatingSystemDependencyVersion("windows", version));
#endif
        }
Ejemplo n.º 3
0
        private OperatingSystemDependencyVersion HandleLinuxOperatingSystem()
        {
            if (!File.Exists(LINUX_OS_RELEASE_FILE))
            {
                throw new NAMEException($"Linux: The file {LINUX_OS_RELEASE_FILE} does not exist or not enough permissions.");
            }

            var    osReleaseLines = File.ReadAllLines(LINUX_OS_RELEASE_FILE);
            string distroId       = null;
            string distroVersion  = null;

            foreach (string line in osReleaseLines)
            {
                if (line.StartsWith(LINUX_OS_RELEASE_DISTRO_NAME_KEY + '=', StringComparison.Ordinal))
                {
                    distroId = line.Split('=')[1].Trim('"');
                }
                else if (line.StartsWith(LINUX_OS_RELEASE_DISTRO_VERSION_KEY + '=', StringComparison.Ordinal))
                {
                    distroVersion = line.Split('=')[1].Trim('"');
                }
            }

            if (distroId == null)
            {
                throw new NAMEException($"Linux: Was unable to resolve the current distribution.");
            }

            if (distroVersion == null)
            {
                throw new NAMEException($"Linux: Was unable to resolve the current version.");
            }

            DependencyVersion parsedVersion;

            if (!DependencyVersion.TryParse(distroVersion, out parsedVersion))
            {
                throw new NAMEException($"Linux: The extracted version ({distroVersion}) from the file {LINUX_OS_RELEASE_FILE} is not valid.");
            }

            return(new OperatingSystemDependencyVersion(distroId, parsedVersion));
        }
Ejemplo n.º 4
0
        private static DependencyVersion ParseVersion(string version, string dependencyType)
        {
            if (version == "*")
            {
                return(null);
            }
            DependencyVersion parsedVersion;

            if (DependencyVersion.TryParse(version, out parsedVersion))
            {
                return(parsedVersion);
            }

            if (!dependencyVersionTranslators.ContainsKey(dependencyType))
            {
                throw new NAMEException($"Could not parse the version of the dependency type {dependencyType}.");
            }

            return(dependencyVersionTranslators[dependencyType].Translate(version));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the versions.
        /// </summary>
        /// <returns>
        /// Returns an enumerable with the versions.
        /// </returns>
        /// <exception cref="ConnectionStringNotFoundException">The connection string was not found</exception>
        /// <exception cref="NAMEException">The service returned an invalid JSON from the manifest endpoint</exception>
        /// <exception cref="VersionParsingException">The version from manifest cannot be parsed</exception>
        public override async Task <IEnumerable <DependencyVersion> > GetVersions()
        {
            string serviceConnectionString;

            if (!this._connectionStringProvider.TryGetConnectionString(out serviceConnectionString))
            {
                throw new ConnectionStringNotFoundException(this._connectionStringProvider.ToString());
            }

            var serviceUri = new Uri(serviceConnectionString);

            string jsonContents = await this.GetManifest(serviceUri.ToString().TrimEnd('/') + Constants.MANIFEST_ENDPOINT, true, serviceUri, this.HopNumber)
                                  .ConfigureAwait(false);

            DependencyVersion dependencyVersion;
            JsonNode          node;

            try
            {
                node = Json.Json.Parse(jsonContents);
                DependencyVersion.TryParse(node?["version"], out dependencyVersion);
                dependencyVersion.ManifestNode = node;
            }
            catch (Exception ex)
            {
                throw new NAMEException($"{SupportedDependencies.Service}: The service returned an invalid JSON from the manifest endpoint.", ex);
            }

            if (dependencyVersion == null)
            {
                throw new VersionParsingException(node?["version"], $"The version from manifest {node} cannot be parsed");
            }

            await this.GetDependantManifests(dependencyVersion).ConfigureAwait(false);

            return(new[] { dependencyVersion });
        }