Skip to content

Commit

Permalink
VCI-902: download manifest (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro committed Jul 31, 2024
1 parent a54d4f2 commit 20126b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ private static void CopyPlatformDirectory(AbsolutePath platformDirectory, Absolu
SaveCloudToken(apiKey);
});

public Target CloudDownloadManifest => _ => _
.Executes(async () =>
{
var cloudClient = new VirtoCloudClient(CloudUrl, await GetCloudTokenAsync());
var manifest = await cloudClient.GetManifest(EnvironmentName, SaaSOrganizationName);
File.WriteAllText(string.IsNullOrWhiteSpace(Manifest) ? Path.Combine(Directory.GetCurrentDirectory(), $"{EnvironmentName}.yml") : Manifest, manifest);
});

private async Task<string> GetCloudTokenAsync()
{
if (!string.IsNullOrEmpty(CloudToken))
Expand Down
16 changes: 16 additions & 0 deletions src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@ public async Task<CloudEnvironment> GetEnvironmentAsync(string environmentName,
var env = JsonExtensions.GetJson<CloudEnvironment>(responseContent);
return env;
}

public async Task<string> GetManifest(string environmentName, string orgName = null)
{
var relativeUri = string.IsNullOrWhiteSpace(orgName) ? $"api/saas/environments/{environmentName}/manifest" : $"api/saas/environments/manifest/{orgName}/{environmentName}";
var response = await _client.SendAsync(new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(relativeUri, UriKind.Relative)
});
if (!response.IsSuccessStatusCode)
{
Assert.Fail($"{response.ReasonPhrase}: {await response.Content.ReadAsStringAsync()}");
}

return await response.Content.ReadAsStringAsync();
}
}

0 comments on commit 20126b5

Please sign in to comment.