Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/e2e/__tests__/checks-empty-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { describe, it, expect } from 'vitest'

import { runChecklyCli } from '../run-checkly'

const apiKey: string | undefined = config.get('emptyApiKey')
const accountId: string | undefined = config.get('emptyAccountId')
const apiKey: string | undefined = config.has('emptyApiKey') ? config.get('emptyApiKey') : undefined
const accountId: string | undefined = config.has('emptyAccountId') ? config.get('emptyAccountId') : undefined

describe.skipIf(!apiKey || !accountId)('checks commands on empty account', () => {
it('should show "No checks found." for checks list', async () => {
Expand Down
21 changes: 21 additions & 0 deletions packages/cli/src/rest/assets.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios'
import type { AxiosInstance } from 'axios'

// eslint-disable-next-line no-restricted-syntax
Expand Down Expand Up @@ -103,6 +104,8 @@ export default class Assets {
case AssetType.LOG: {
if (isCheckResultAssetsV1(asset) && asset.logPath) {
key = asset.logPath
} else if (isCheckResultAssetsV2(asset)) {
return this.getAssetsV2(assetType, asset)
} else if (isCheckResultAssetsV3(asset) && asset.logPath) {
key = asset.clickHouseId
}
Expand All @@ -111,6 +114,8 @@ export default class Assets {
case AssetType.CHECK_RUN_DATA: {
if (isCheckResultAssetsV1(asset) && asset.checkRunDataPath) {
key = asset.checkRunDataPath
} else if (isCheckResultAssetsV2(asset)) {
return this.getAssetsV2(assetType, asset)
} else if (isCheckResultAssetsV3(asset)) {
key = asset.clickHouseId
break
Expand All @@ -126,6 +131,22 @@ export default class Assets {
return response.data
}

private async getAssetsV2 (assetType: AssetType, asset: CheckResultAssetsV2): Promise<any> {
const entryName = assetType === AssetType.LOG ? 'logs.txt' : 'check-run-data.json'
const entry = asset.entries.find(e => e.name === entryName)
if (!entry) {
return
}

const presignedUrl = await this.getAssetsLink(asset.region, asset.key)
const response = await axios.get(presignedUrl, {
headers: { Range: `bytes=${entry.start}-${entry.end}` },
responseType: 'text',
})

return JSON.parse(response.data)
}

async getAssetsLink (region: string, key: string): Promise<any> {
const response = await this.api.get<string>(
`/next/assets/${AssetType.CHECK_RUN_DATA}/${region}/${encodeURIComponent(key)}/redirect?link=true`)
Expand Down
Loading