-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
307 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { api, ApiError } from './api'; | ||
import { HttpResponse } from './types'; | ||
|
||
export type Profile = { | ||
username?: string; | ||
email: string; | ||
projects?: { | ||
code: string; | ||
name: string; | ||
}[]; | ||
}; | ||
|
||
export async function profile({ | ||
withProjects, | ||
auth, | ||
}: { | ||
auth?: { apiUrl: string; credentials: string }; | ||
withProjects?: boolean; | ||
} = {}): Promise<Profile> { | ||
const { body } = await api<HttpResponse<Profile>>({ | ||
method: 'get', | ||
auth, | ||
path: `/profile`, | ||
query: withProjects | ||
? { | ||
withProjects, | ||
} | ||
: undefined, | ||
}); | ||
|
||
if (!body.payload) { | ||
throw new ApiError(401, { error: 'username is missing' }); | ||
} | ||
|
||
return body.payload; | ||
} | ||
|
||
export async function listProjects() { | ||
const { projects, ...rest } = await profile({ withProjects: true }); | ||
|
||
return projects || []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,53 @@ | ||
import { api } from './api'; | ||
import { HttpResponse, SecretsListResponse } from './types'; | ||
|
||
export async function listSecrets(): Promise<SecretsListResponse> { | ||
export async function listSecrets({ projectCode }: { projectCode?: string }): Promise<SecretsListResponse> { | ||
const { body } = await api<HttpResponse<SecretsListResponse>>({ | ||
method: 'get', | ||
path: '/secrets', | ||
query: { | ||
projectCode, | ||
}, | ||
path: `/secrets`, | ||
}); | ||
return body.payload; | ||
} | ||
|
||
export async function removeSecret(name: string): Promise<SecretsListResponse> { | ||
export async function removeSecret({ | ||
name, | ||
projectCode, | ||
}: { | ||
name: string; | ||
projectCode?: string; | ||
}): Promise<SecretsListResponse> { | ||
const { body } = await api<HttpResponse<SecretsListResponse>>({ | ||
method: 'delete', | ||
path: `/secrets/${name}`, | ||
method: 'put', | ||
path: `/secrets`, | ||
data: { | ||
projectCode, | ||
secrets: [{ action: 'DELETE', name }], | ||
}, | ||
}); | ||
|
||
return body.payload; | ||
} | ||
|
||
export async function setSecret(secrets: Record<string, string>): Promise<SecretsListResponse> { | ||
export async function setSecret({ | ||
name, | ||
value, | ||
projectCode, | ||
}: { | ||
name: string; | ||
value: string; | ||
projectCode?: string; | ||
}): Promise<SecretsListResponse> { | ||
const { body } = await api<HttpResponse<SecretsListResponse>>({ | ||
method: 'patch', | ||
method: 'put', | ||
path: `/secrets`, | ||
data: { secrets: secrets }, | ||
data: { | ||
projectCode, | ||
secrets: [{ action: 'UPDATE', name, value }], | ||
}, | ||
}); | ||
|
||
return body.payload; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.