Skip to content

Commit 97a2830

Browse files
author
Theophilus Okwugwuni
authored
[GPS-400] setup (#1)
* generate client * setup ci * fix ci * add check workflow * update check action * update readme * add error handling to readme * remove dry-run
1 parent ef1d8e7 commit 97a2830

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+7336
-0
lines changed

.github/workflows/check.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Check
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
13+
- name: Install Node.js
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
registry-url: https://registry.npmjs.org
18+
19+
- uses: pnpm/action-setup@v2
20+
name: Install pnpm
21+
with:
22+
version: 9
23+
run_install: false
24+
25+
- name: Get pnpm store directory
26+
id: pnpm-cache-dir-path
27+
run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
28+
29+
- uses: actions/cache@v4
30+
name: Setup pnpm cache
31+
with:
32+
path: ${{ steps.pnpm-cache-dir-path.outputs.dir }}
33+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
34+
restore-keys: |
35+
${{ runner.os }}-pnpm-store
36+
37+
- name: Install dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- run: pnpm build

.github/workflows/release.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ["*"]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Install Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: 20
18+
registry-url: https://registry.npmjs.org
19+
20+
- uses: pnpm/action-setup@v2
21+
name: Install pnpm
22+
with:
23+
version: 9
24+
run_install: false
25+
26+
- name: Get pnpm store directory
27+
id: pnpm-cache-dir-path
28+
run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
29+
30+
- uses: actions/cache@v4
31+
name: Setup pnpm cache
32+
with:
33+
path: ${{ steps.pnpm-cache-dir-path.outputs.dir }}
34+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
35+
restore-keys: |
36+
${{ runner.os }}-pnpm-store
37+
38+
- name: Install dependencies
39+
run: pnpm install --frozen-lockfile
40+
41+
- name: Build
42+
run: pnpm build
43+
44+
- name: Publish
45+
run: pnpm publish --access public --no-git-checks
46+
env:
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
132+
.DS_Store

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

README.md

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Genesis Cloud JavaScript Client
2+
3+
The JavaScript library for the [Genesis Cloud](http://genesiscloud.com) API offers an easy way to manage resources like instances, volumes, snapshots, filesystems, floating IPs, security groups and more in your JavaScript or TypeScript applications.
4+
5+
## Installation
6+
7+
You can install the Genesis Cloud SDK using your preferred node package manager:
8+
9+
```bash
10+
npm install @genesiscloud/genesiscloud-js
11+
# or
12+
yarn add @genesiscloud/genesiscloud-js
13+
# or
14+
pnpm add @genesiscloud/genesiscloud-js
15+
```
16+
17+
## Configuration
18+
19+
Before you start, you'll need to configure the client with your Genesis Cloud API token. You can generate your API token from the [Genesis Cloud console](https://console.genesiscloud.com/dashboard).
20+
21+
Here's how to configure the SDK:
22+
23+
```typescript
24+
const genesiscloud = new GenesisCloudClient({
25+
TOKEN: process.env.GENESISCLOUD_TOKEN,
26+
});
27+
```
28+
29+
## Examples
30+
31+
### Error handling
32+
33+
Error handling can be done using the try/catch with the async/await syntax. The Genesis Cloud errors are of [this format](/src/core/ApiError.ts).
34+
35+
```typescript
36+
try {
37+
const instance = await genesiscloud.instances.createInstance({
38+
requestBody: {
39+
// ...
40+
},
41+
});
42+
//... do something with instance
43+
} catch (error) {
44+
if (error instanceof ApiError) {
45+
const { code, message } = error.body;
46+
// ... handle genesiscloud error
47+
} else {
48+
// ... handle other errors
49+
}
50+
}
51+
```
52+
53+
### Managing Instances
54+
55+
Listing Instances:
56+
57+
```typescript
58+
const { instances } = await genesiscloud.instances.listInstances({
59+
page: 1,
60+
perPage: 100,
61+
});
62+
```
63+
64+
Creating a new Instance:
65+
66+
```typescript
67+
const instance = await genesiscloud.instances.createInstance({
68+
requestBody: {
69+
name: "test instance",
70+
hostname: "test instance",
71+
type: "vcpu-192_memory-1920g_nvidia-h100-sxm5-8",
72+
image: "ubuntu-ml-nvidia-pytorch",
73+
region: "NORD-NO-KRS-1",
74+
ssh_keys: ["ssh_key_id_here"],
75+
},
76+
});
77+
```
78+
79+
Updating an Instance:
80+
81+
```typescript
82+
const updatedInstance = await genesiscloud.instances.updateInstance({
83+
instanceId: "your_instance_id",
84+
requestBody: {
85+
name: "New Instance Name",
86+
volumes: ["volume_id_here"],
87+
},
88+
});
89+
```
90+
91+
Deleting an Instance:
92+
93+
```typescript
94+
await genesiscloud.instances.deleteInstance({
95+
instanceId: "your_instance_id",
96+
});
97+
```
98+
99+
### Managing Volumes
100+
101+
Creating a Volume
102+
103+
```typescript
104+
const volume = await genesiscloud.volumes.createVolume({
105+
requestBody: {
106+
name: "volume name",
107+
description: "volume description",
108+
type: "ssd",
109+
size: 10, // in GiB
110+
region: "NORD-NO-KRS-1",
111+
},
112+
});
113+
```
114+
115+
Deleting a Volume
116+
117+
```typescript
118+
await genesiscloud.volumes.deleteVolume({
119+
volumeId: "your_volume_id",
120+
});
121+
```
122+
123+
### Managing Snapshots
124+
125+
Creating a Snapshot from an instance:
126+
127+
```typescript
128+
const snapshot = await genesiscloud.instances.createInstanceSnapshot({
129+
instanceId: "your_instance_id",
130+
requestBody: {
131+
name: "Test snapshot",
132+
},
133+
});
134+
```
135+
136+
Deleting a Snapshot:
137+
138+
```typescript
139+
await genesiscloud.snapshots.deleteSnapshot({
140+
snapshotId: "your_snapshot_id",
141+
});
142+
```
143+
144+
### Managing SSH Keys
145+
146+
Listing SSH Keys:
147+
148+
```typescript
149+
const sshKeys = await genesiscloud.sshKeys.listSshKeys({});
150+
```
151+
152+
Creating an SSH Key:
153+
154+
```typescript
155+
const sshKey = await genesiscloud.sshKeys.createSshKey({
156+
requestBody: {
157+
name: "test key",
158+
value: "ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXX...",
159+
},
160+
});
161+
```
162+
163+
Deleting an SSH Key:
164+
165+
```typescript
166+
await genesiscloud.sshKeys.deleteSshKey({
167+
sshKeyId: "your-ssh-key-id",
168+
});
169+
```
170+
171+
For more detailed information on the Genesis Cloud API refer to the [Genesis Cloud API documentation](https://developers.genesiscloud.com/).

0 commit comments

Comments
 (0)