Skip to content

Commit

Permalink
feat(gateways): change path of gateways, following Ravel changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisbouchez committed Jan 16, 2025
1 parent 8acf239 commit af9c7ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
17 changes: 8 additions & 9 deletions src/gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,37 @@ export type Gateway = {

export type CreateGatewayPayload = {
name: string;
fleet: string;
target_port: number;
};

export class Gateways {
constructor(private caller: ClientCaller) {}

create(payload: CreateGatewayPayload) {
create(fleet: string, payload: CreateGatewayPayload) {
return this.caller.call<Gateway>({
path: `/gateways`,
path: `/fleets/${fleet}/gateways`,
method: 'POST',
payload,
});
}

list(fleet?: string) {
list(fleet: string) {
return this.caller.call<Array<Gateway>>({
path: `/gateways?fleet=${fleet}`,
path: `/fleets/${fleet}/gateways`,
method: 'GET',
});
}

get(gateway: string) {
get(fleet: string, gateway: string) {
return this.caller.call<Gateway>({
path: `/gateways/${gateway}`,
path: `/fleets/${fleet}/gateways/${gateway}`,
method: 'GET',
});
}

delete(gateway: string) {
delete(fleet: string, gateway: string) {
return this.caller.call({
path: `/gateways/${gateway}`,
path: `/fleets/${fleet}/gateways/${gateway}`,
method: 'DELETE',
expectNoResponseData: true,
});
Expand Down
24 changes: 19 additions & 5 deletions src/machines.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientCaller } from './client';
import { ClientCaller, FetchErrorWithPayload } from './client';
import { Filesystem } from './filesystem';

export class Machine {
Expand Down Expand Up @@ -114,7 +114,21 @@ export class Machines {

const response = await fetch(url, { method: 'GET' });
if (!response.ok) {
throw new Error(`Failed to fetch NDJSON stream: ${response.statusText}`);
let data: any;
try {
data = await response.json();
} catch {
throw new FetchErrorWithPayload(
`Failed to fetch NDJSON stream: ${response.status} (${response.statusText})`,
{
url: url.toString(),
}
);
}
throw new FetchErrorWithPayload(
`Failed to fetch NDJSON stream: ${response.status} (${response.statusText})`,
{ ...data, url: url.toString() }
);
}

const reader = response.body?.getReader();
Expand Down Expand Up @@ -181,10 +195,10 @@ export class Machines {
timeoutInSeconds?: number
): Promise<void> {
return this.caller.call({
method: 'POST',
path: `/fleets/${fleet}/machines/${machine}/stop`,
method: 'GET',
path: `/fleets/${fleet}/machines/${machine}/wait`,
expectNoResponseData: true,
queryParams: { status, timeoutInSeconds },
queryParams: { status, timeout: timeoutInSeconds },
});
}
}
Expand Down

0 comments on commit af9c7ff

Please sign in to comment.