public Task <ImageDownloadInfo> GetAgentVersionDownloadInfo(GetImageDownloadInfoRequest request, CancellationToken cancellationToken = new CancellationToken()) { return(_client.MakeJsonRequestAsync <ImageDownloadInfo>( cancellationToken, HttpMethod.Post, ResourceUris.AgentDownloadInfo, headers: _tokenFactory.CreateRequestHeaders(), request: request)); }
public IActionResult Post([FromBody] GetImageDownloadInfoRequest request) { //Ensure that the application version exists and that the device has access to it. using (var connection = _connectionFactory.CreateAndOpen()) { var agentVersion = connection.Get <AgentVersion>(request.Id); if (agentVersion == null) { return(NotFound(new Error($"Unable to find agent version {request.Id}"))); } var device = connection.Get <Device>(DeviceId); if (device == null) { return(NotFound(new Error("Unable to find device"))); } var application = connection.Get <Application>(device.ApplicationId); if (application == null) { return(NotFound(new Error($"Unable to find application '{device.ApplicationId}'."))); } var deviceType = connection.Get <DeviceType>(application.DeviceTypeId); if (deviceType == null) { return(NotFound(new Error($"Unable to find device type '{application.DeviceTypeId}'."))); } var response = new ImageDownloadInfo() { ImageId = agentVersion.ImageId, Registry = _registryConfig.RegistryHost, AuthToken = null, //TODO: This is where the auth token will go Repository = _repositoryNameFactory.Agent, Name = agentVersion.Name, }; //TODO: Add a device event for getting this token return(Ok(response)); } }
public IActionResult Post([FromBody] GetImageDownloadInfoRequest request) { //Ensure that the application version exists and that the device has access to it. using (var connection = _connectionFactory.CreateAndOpen()) { var applicationVersion = connection.Get <ApplicationVersion>(request.Id); if (applicationVersion == null) { return(NotFound()); } var device = connection.Get <Device>(DeviceId); if (device == null) { return(NotFound()); } if (device.ApplicationId != applicationVersion.ApplicationId) { return(BadRequest()); } //Verify that the device has access to this *specific* version. var application = connection.Get <Application>(device.ApplicationId); if (application.ApplicationVersionId != request.Id && device.ApplicationVersionId != request.Id) { return(BadRequest()); } var response = new ImageDownloadInfo() { ImageId = applicationVersion.ImageId, Registry = _registryConfig.RegistryHost, AuthToken = null, //TODO: This is where the auth token will go Repository = _repositoryNameFactory.FromApplication(device.ApplicationId), Name = applicationVersion.Name, }; //TODO: Add a device event for getting this token return(Ok(response)); } }
private async Task DownloadImageAsync(IDockerClient dockerClient, VersionReference versionReference, CancellationToken cancellationToken) { var versionRequest = new GetImageDownloadInfoRequest() { Id = versionReference.Id }; Logger.Information("Getting application download information for version {ImageId}...", versionReference.ImageId); //Get the download info var downloadInfo = await _deviceApiClient.ApplicationDownloadInfo.GetApplicationVersionDownloadInfo(versionRequest, cancellationToken); string fromImage = $"{downloadInfo.Registry}/{downloadInfo.Repository}:{downloadInfo.Name}"; //Dowlnoad it! Logger.Information("Downloading with fromImage = '{FromImage}'...", fromImage); var imageCreateParameters = new ImagesCreateParameters { FromImage = fromImage }; var authConfig = new AuthConfig() { }; //Do the donwload!!!!! await dockerClient.Images.CreateImageAsync( imageCreateParameters, authConfig, new Progress <JSONMessage>(m => Console.WriteLine($"\tCreateImageProgress: {m.ProgressMessage}")), cancellationToken); Logger.Information("Application image {ImageId} downloaded.", versionReference.ImageId); }