Ejemplo n.º 1
0
 internal static ImageAnnotation FromLicense(LicenseLocator license)
 {
     if (license != null && license.IsWindowsByolLicense())
     {
         return(new ImageAnnotation(
                    OperatingSystemTypes.Windows,
                    LicenseTypes.Byol));
     }
     else if (license != null && license.IsWindowsLicense())
     {
         return(new ImageAnnotation(
                    OperatingSystemTypes.Windows,
                    LicenseTypes.Spla));
     }
     else if (license != null)
     {
         return(new ImageAnnotation(
                    OperatingSystemTypes.Linux,
                    LicenseTypes.Unknown));
     }
     else
     {
         return(new ImageAnnotation(
                    OperatingSystemTypes.Unknown,
                    LicenseTypes.Unknown));
     }
 }
Ejemplo n.º 2
0
        public void WhenLicenseHasByolSuffix_ThenIsWindowsByolLicenseReturnsTrue()
        {
            var locator = LicenseLocator.FromString(
                "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-10-enterprise-byol");

            Assert.IsTrue(locator.IsWindowsByolLicense());
        }
Ejemplo n.º 3
0
        public void WhenLicenseHasNoByolSuffix_ThenIsWindowsByolLicenseReturnsFalse()
        {
            var locator = LicenseLocator.FromString(
                "projects/windows-cloud/global/licenses/windows-2016");

            Assert.IsFalse(locator.IsWindowsByolLicense());
        }
Ejemplo n.º 4
0
        public void WhenLicenseIsNotFromWindowsCloud_ThenIsWindowsLicenseReturnsFalse()
        {
            var locator = LicenseLocator.FromString(
                "projects/my-project/global/licenses/windows-10-enterprise-byol");

            Assert.IsFalse(locator.IsWindowsLicense());
        }
Ejemplo n.º 5
0
        public void WhenReferencesAreEquivalent_ThenGetHasCodeIsSame()
        {
            var ref1 = new LicenseLocator("proj", "windows-10-enterprise-byol");
            var ref2 = new LicenseLocator("proj", "windows-10-enterprise-byol");

            Assert.AreEqual(ref1.GetHashCode(), ref2.GetHashCode());
        }
Ejemplo n.º 6
0
        public void WhenCreatedFromPath_ThenToStringReturnsPath()
        {
            var path = "projects/project-1/global/licenses/windows-10-enterprise-byol";

            Assert.AreEqual(
                path,
                LicenseLocator.FromString(path).ToString());
        }
Ejemplo n.º 7
0
        public void WhenQualifiedByGoogleapisHost_FromStringReturnsObject()
        {
            var ref1 = LicenseLocator.FromString(
                "https://www.googleapis.com/compute/v1/projects/windows-cloud/global/licenses/windows-10-enterprise-byol");

            Assert.AreEqual("licenses", ref1.ResourceType);
            Assert.AreEqual("windows-10-enterprise-byol", ref1.Name);
            Assert.AreEqual("windows-cloud", ref1.ProjectId);
        }
Ejemplo n.º 8
0
        public void WhenPathIsValid_FromStringReturnsObject()
        {
            var ref1 = LicenseLocator.FromString(
                "projects/project-1/global/licenses/windows-10-enterprise-byol");

            Assert.AreEqual("licenses", ref1.ResourceType);
            Assert.AreEqual("windows-10-enterprise-byol", ref1.Name);
            Assert.AreEqual("project-1", ref1.ProjectId);
        }
Ejemplo n.º 9
0
        public void WhenCreatedFromUrl_ThenToStringReturnsPath()
        {
            var path = "projects/project-1/global/licenses/windows-10-enterprise-byol";

            Assert.AreEqual(
                path,
                LicenseLocator.FromString(
                    "https://www.googleapis.com/compute/v1/" + path).ToString());
        }
Ejemplo n.º 10
0
 public void WhenPathInvalid_FromStringThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => LicenseLocator.FromString(
                                           "projects/project-1/notglobal/licenses/windows-10-enterprise-byol"));
     Assert.Throws <ArgumentException>(() => LicenseLocator.FromString(
                                           "/project-1/global/licenses/windows-10-enterprise-byol"));
     Assert.Throws <ArgumentException>(() => LicenseLocator.FromString(
                                           "/"));
 }
Ejemplo n.º 11
0
        public void WhenReferencesAreEquivalent_ThenEqualsReturnsTrue()
        {
            var ref1 = new LicenseLocator("proj", "windows-10-enterprise-byol");
            var ref2 = new LicenseLocator("proj", "windows-10-enterprise-byol");

            Assert.IsTrue(ref1.Equals(ref2));
            Assert.IsTrue(ref1.Equals((object)ref2));
            Assert.IsTrue(ref1 == ref2);
            Assert.IsFalse(ref1 != ref2);
        }
Ejemplo n.º 12
0
 public Program(UriCorrector uriCorrector, LicenseLocator licenseLocator, IFileSystem fileSystem,
                ProjectDependencyResolver projectDependencyResolver, LicenseDownloader licenseDownloader, IReporter reporter)
 {
     _uriCorrector              = uriCorrector;
     _licenseLocator            = licenseLocator;
     _fileSystem                = fileSystem;
     _projectDependencyResolver = projectDependencyResolver;
     _downloader                = licenseDownloader;
     _reporter = reporter;
 }
Ejemplo n.º 13
0
        public void TestEqualsNull()
        {
            var ref1 = new LicenseLocator("proj", "windows-10-enterprise-byol");

            Assert.IsFalse(ref1.Equals(null));
            Assert.IsFalse(ref1.Equals((object)null));
            Assert.IsFalse(ref1 == null);
            Assert.IsFalse(null == ref1);
            Assert.IsTrue(ref1 != null);
            Assert.IsTrue(null != ref1);
        }
 private static bool IsWindowsInstanceByLicense(Instance instance)
 {
     // For an instance to be a valid Windows instance, at least one of the disks
     // has to have an associated Windows license. This is also true for
     // BYOL'ed instances.
     return(instance.Disks
            .EnsureNotNull()
            .Where(d => d.Licenses != null)
            .SelectMany(d => d.Licenses)
            .EnsureNotNull()
            .Any(l => LicenseLocator.FromString(l).IsWindowsLicense()));
 }
Ejemplo n.º 15
0
        private static LicenseLocator TryGetRelevantLicenseFromImage(Image imageInfo)
        {
            var locators = imageInfo.Licenses
                           .EnsureNotNull()
                           .Select(license => LicenseLocator.FromString(license));

            // Images can contain more than one license, and liceses like
            // "/compute/v1/projects/compute-image-tools/global/licenses/virtual-disk-import"
            // are not helpful here. So do some filtering.
            if (locators.FirstOrDefault(l => l.IsWindowsByolLicense()) is LicenseLocator byolLocator)
            {
                return(byolLocator);
            }
            else if (locators.FirstOrDefault(l => l.IsWindowsLicense()) is LicenseLocator winLocator)
            {
                return(winLocator);
            }
            else
            {
                return(locators.FirstOrDefault());
            }
        }
Ejemplo n.º 16
0
 public void AddLicenseAnnotation(
     ImageLocator image,
     LicenseLocator license)
 {
     this.LicenseAnnotations[image.ToString()] = ImageAnnotation.FromLicense(license);
 }
Ejemplo n.º 17
0
 public static bool IsWindowsByolLicense(this LicenseLocator locator)
 => IsWindowsLicense(locator) && locator.Name.EndsWith("-byol");
Ejemplo n.º 18
0
 public static bool IsWindowsLicense(this LicenseLocator locator)
 => locator.ProjectId == "windows-cloud";