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
8 changes: 8 additions & 0 deletions hasura/metadata/actions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,10 @@ type Query {
telemetryStats(includeSelf: Boolean): TelemetryStats!
}

type Mutation {
testDownload: TestDownloadResponse
}

type Mutation {
testUpload: TestUploadResponse
}
Expand Down Expand Up @@ -1380,6 +1384,10 @@ type TelemetryStats {
countries: [TelemetryCountryCount!]!
}

type TestDownloadResponse {
error: String
}

type TestUploadResponse {
error: String
}
Expand Down
8 changes: 8 additions & 0 deletions hasura/metadata/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,13 @@ actions:
forward_client_headers: true
permissions:
- role: administrator
- name: testDownload
definition:
kind: synchronous
handler: '{{HASURA_GRAPHQL_ACTIONS_HOOK}}'
forward_client_headers: true
permissions:
- role: administrator
- name: testUpload
definition:
kind: synchronous
Expand Down Expand Up @@ -2066,6 +2073,7 @@ custom_types:
- name: TelemetryUtilityTypeCount
- name: TelemetryUtilitySourceCount
- name: TelemetryStats
- name: TestDownloadResponse
- name: TestUploadResponse
- name: GetTestUploadResponse
- name: ApiKeyResponse
Expand Down
29 changes: 29 additions & 0 deletions src/s3/s3.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ export class S3Controller {
}
}

// Reads back the file testUpload wrote, the way a download is served: through
// a presigned link. The browser can't do this itself, since most buckets
// don't allow the panel's site to read them directly.
@HasuraAction()
public async testDownload() {
try {
const response = await fetch(
await this.s3.getPresignedUrl("hello.txt", undefined, 60, "get"),
);

if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}

if (!(await response.text()).startsWith("world")) {
throw new Error(
"the test file came back different from what was written",
);
}

return {};
} catch (error) {
this.logger.error(`Failed to download file from S3: ${error.message}`);
return {
error: error.message,
};
}
}

@HasuraAction()
public async getTestUploadLink() {
try {
Expand Down
Loading