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)); } }
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()); }
public void WhenLicenseHasNoByolSuffix_ThenIsWindowsByolLicenseReturnsFalse() { var locator = LicenseLocator.FromString( "projects/windows-cloud/global/licenses/windows-2016"); Assert.IsFalse(locator.IsWindowsByolLicense()); }
public void WhenLicenseIsNotFromWindowsCloud_ThenIsWindowsLicenseReturnsFalse() { var locator = LicenseLocator.FromString( "projects/my-project/global/licenses/windows-10-enterprise-byol"); Assert.IsFalse(locator.IsWindowsLicense()); }
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()); }
public void WhenCreatedFromPath_ThenToStringReturnsPath() { var path = "projects/project-1/global/licenses/windows-10-enterprise-byol"; Assert.AreEqual( path, LicenseLocator.FromString(path).ToString()); }
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); }
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); }
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()); }
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( "/")); }
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); }
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; }
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())); }
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()); } }
public void AddLicenseAnnotation( ImageLocator image, LicenseLocator license) { this.LicenseAnnotations[image.ToString()] = ImageAnnotation.FromLicense(license); }
public static bool IsWindowsByolLicense(this LicenseLocator locator) => IsWindowsLicense(locator) && locator.Name.EndsWith("-byol");
public static bool IsWindowsLicense(this LicenseLocator locator) => locator.ProjectId == "windows-cloud";