//--------------------------------------------------------------------- // Loading. //--------------------------------------------------------------------- public async static Task <InstanceDetailsModel> LoadAsync( InstanceLocator instanceLocator, IComputeEngineAdapter computeEngineAdapter, IInventoryService inventoryService, CancellationToken token) { var instance = await computeEngineAdapter .GetInstanceAsync( instanceLocator, token) .ConfigureAwait(false); var project = await computeEngineAdapter .GetProjectAsync( instanceLocator.ProjectId, token) .ConfigureAwait(false); var osInfo = await inventoryService.GetInstanceInventoryAsync( instanceLocator, token) .ConfigureAwait(false); return(new InstanceDetailsModel( project, instance, osInfo)); }
public CredentialsService(IServiceProvider serviceProvider) { this.jobService = serviceProvider.GetService <IJobService>(); this.eventService = serviceProvider.GetService <IEventService>(); this.authService = serviceProvider.GetService <IAuthorizationAdapter>(); this.computeEngineAdapter = serviceProvider.GetService <IComputeEngineAdapter>(); }
//--------------------------------------------------------------------- // Loading. //--------------------------------------------------------------------- public async static Task <InstanceDetailsModel> LoadAsync( InstanceLocator instanceLocator, IComputeEngineAdapter adapter, CancellationToken token) { var instance = await adapter .GetInstanceAsync( instanceLocator, token) .ConfigureAwait(false); var guestAttributes = await adapter .GetGuestAttributesAsync( instanceLocator, GuestOsInfo.GuestAttributePath, token) .ConfigureAwait(false); var guestAttributesList = guestAttributes?.QueryValue?.Items; return(new InstanceDetailsModel( instance, guestAttributesList != null ? GuestOsInfo.FromGuestAttributes(guestAttributesList) : null)); }
public ReportBuilder( IAuditLogAdapter auditLogAdapter, IAuditLogStorageSinkAdapter auditExportAdapter, IComputeEngineAdapter computeEngineAdapter, AuditLogSources sources, IEnumerable <string> projectIds, DateTime startDate) { var now = DateTime.UtcNow; if (startDate >= now) { throw new ArgumentException("Invalid start date"); } else if ((now - startDate).TotalDays > MaxPeriod) { throw new ArgumentException("Start date is too far in the past"); } this.sources = sources; this.projectIds = projectIds; this.auditLogAdapter = auditLogAdapter; this.auditExportAdapter = auditExportAdapter; this.computeEngineAdapter = computeEngineAdapter; this.builder = new InstanceSetHistoryBuilder(startDate, now); }
public async Task LoadLicenseAnnotationsAsync( IComputeEngineAdapter computeEngineAdapter, CancellationToken cancellationToken) { await LicenseLoader.LoadLicenseAnnotationsAsync( this, computeEngineAdapter, cancellationToken); }
//--------------------------------------------------------------------- // Ctor. //--------------------------------------------------------------------- public AuthorizedKeyService( IAuthorizationAdapter authorizationAdapter, IComputeEngineAdapter computeEngineAdapter, IResourceManagerAdapter resourceManagerAdapter, IOsLoginService osLoginService) { this.authorizationAdapter = authorizationAdapter; this.computeEngineAdapter = computeEngineAdapter; this.resourceManagerAdapter = resourceManagerAdapter; this.osLoginService = osLoginService; }
public static async Task LoadLicenseAnnotationsAsync( ReportArchive annotatedSet, IComputeEngineAdapter computeEngineAdapter, CancellationToken cancellationToken) { foreach (var image in annotatedSet.History.Instances .Where(i => i.Image != null) .Select(i => i.Image) .Distinct()) { try { Image imageInfo = await computeEngineAdapter .GetImageAsync(image, cancellationToken) .ConfigureAwait(false); // 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. var license = TryGetRelevantLicenseFromImage(imageInfo); annotatedSet.AddLicenseAnnotation( image, license); TraceSources.IapDesktop.TraceVerbose("License for {0} is {1}", image, license); } catch (ResourceNotFoundException) when(image.ProjectId == "windows-cloud") { // That image might not exist anymore, but we know it's // a Windows SPLA image. annotatedSet.AddLicenseAnnotation( image, OperatingSystemTypes.Windows, LicenseTypes.Spla); TraceSources.IapDesktop.TraceVerbose( "License for {0} could not be found, but must be Windows/SPLA", image); } catch (ResourceNotFoundException e) { // Unknown or inaccessible image, skip. TraceSources.IapDesktop.TraceWarning( "License for {0} could not be found: {0}", image, e); } catch (ResourceAccessDeniedException e) { // Unknown or inaccessible image, skip. TraceSources.IapDesktop.TraceWarning( "License for {0} could not be accessed: {0}", image, e); } } }
public async static Task <InstancePropertiesInspectorModel> LoadAsync( InstanceLocator instanceLocator, IComputeEngineAdapter computeEngineAdapter, IInventoryService inventoryService, CancellationToken token) { var instance = await computeEngineAdapter .GetInstanceAsync( instanceLocator, token) .ConfigureAwait(false); var project = await computeEngineAdapter .GetProjectAsync( instanceLocator.ProjectId, token) .ConfigureAwait(false); // // Reading OS inventory data can fail because of a // `compute.disableGuestAttributesAccess` constraint. // GuestOsInfo osInfo; try { osInfo = await inventoryService.GetInstanceInventoryAsync( instanceLocator, token) .ConfigureAwait(false); } catch (Exception e) when(e.Unwrap() is GoogleApiException apiEx && apiEx.IsConstraintViolation()) { TraceSources.IapDesktop.TraceWarning( "Failed to load OS inventory data: {0}", e); // Proceed with empty data. osInfo = null; } return(new InstancePropertiesInspectorModel( project, instance, osInfo)); } }
public async static Task <SerialOutputModel> LoadAsync( IComputeEngineAdapter adapter, InstanceLocator instanceLocator, ushort portNumber, CancellationToken token) { // The serial port log can contain VT100 control sequences, but // they are limited to trivial command such as "clear screen". // As there is not much value in preserving these, use an // AnsiTextReader to filter out all escape sequences. var stream = new AnsiTextReader( adapter.GetSerialPortOutput(instanceLocator, portNumber)); var model = new SerialOutputModel(stream); // Read all existing output. while (await model.ReadAndBufferAsync(token).ConfigureAwait(false) != string.Empty) { } return(model); }
public InventoryService(IComputeEngineAdapter computeEngineAdapter) { this.computeEngineAdapter = computeEngineAdapter; }