Skip to content

Commit

Permalink
Add support for kubernetes (#41)
Browse files Browse the repository at this point in the history
* add basic k8s info

* add k8s

* add clusters

* unbase64

* add null check

* fix encrypt

* more

* fix things

* add cluster

* fix types

* longer key

* use nacl

* add nacl

* update

* add keys

* fix things

* add config syncing

* release: v0.0.70-pre.1732232823462

* add an echo

* add clusters list

* fix

* add clusters

* add cluster details

* clean cred

* fix

* release: v0.0.70-pre.1732315142968

* release: v0.0.71-pre.1732315608791

* fix

* udpate

* release: v0.0.71-pre.1732316035899

* fix

* release: v0.0.71-pre.1732317365533

* add .kubedir

* release: v0.0.71-pre.1732317531748

* insecure tls verify for the moment

* add sell
  • Loading branch information
Flaque authored Nov 26, 2024
1 parent 5838860 commit b0be010
Show file tree
Hide file tree
Showing 21 changed files with 1,637 additions and 154 deletions.
29 changes: 27 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ elif [ $# -eq 0 ]; then
SF_BINARY_URL=$github_repo/releases/latest/download/sf-$target.zip
else
VERSION=$1
echo "Downloading version $VERSION"
SF_BINARY_URL=$github_repo/releases/download/$VERSION/sf-$target.zip
fi

Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"dev": "IS_DEVELOPMENT_CLI_ENV=true deno run src/index.ts",
"devv": "IS_DEVELOPMENT_CLI_ENV=true deno run --allow-all src/index.ts",
"release": "deno run --allow-all src/scripts/release.ts",
"prod": "deno run --allow-all src/index.ts",
"schema": "npx openapi-typescript https://api.sfcompute.com/docs/json -o src/schema.ts"
Expand Down Expand Up @@ -28,13 +28,16 @@
"parse-duration": "^1.1.0",
"react": "^18.3.1",
"semver": "^7.6.3",
"tiny-invariant": "^1.3.3"
"tiny-invariant": "^1.3.3",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"yaml": "^2.6.1"
},
"devDependencies": {
"@types/semver": "^7.5.8"
},
"peerDependencies": {
"typescript": "^5.6.2"
},
"version": "0.0.71"
"version": "0.0.71-pre.1732317531748"
}
4 changes: 2 additions & 2 deletions src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { paths } from "./schema.ts"; // generated by openapi-typescript

let __client: Client<paths, `${string}/${string}`> | undefined;

export const apiClient = async () => {
export const apiClient = async (token?: string) => {
if (__client) {
return __client;
}
Expand All @@ -13,7 +13,7 @@ export const apiClient = async () => {
__client = createClient<paths>({
baseUrl: config.api_url,
headers: {
Authorization: `Bearer ${await getAuthToken()}`,
Authorization: `Bearer ${token ?? (await getAuthToken())}`,
"Content-Type": "application/json",
},
});
Expand Down
179 changes: 90 additions & 89 deletions src/helpers/test/units.test.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,95 @@
import { describe, expect, test } from "bun:test";
import {
assert,
assertEquals,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import {
type Cents,
centsToDollarsFormatted,
priceWholeToCents,
} from "../units";

describe("units", () => {
test("price whole to cents", () => {
const inputToExpectedValids = [
// formatted as USD
["$0", 0],
["$1", 100],
["$10", 10_00],
["$100", 100_00],

["$0.0", 0],
["$0.00", 0],
["$0.000", 0],

["$1.0", 100],
["$1.00", 100],
["$1.000", 100],

["$1.23", 123],
["$1.234", 123.4],

// formatted as numbers
["0", 0],
["1", 100],
["10", 10_00],
["100", 100_00],

["1.23", 123],
["1.234", 123.4],

// nested quotes (double)
['"$0"', 0],
['"$1"', 100],
['"$10"', 10_00],
['"0"', 0],
['"1"', 100],
['"10"', 10_00],

// nested quotes (single)
["'$0'", 0],
["'$1'", 100],
["'$10'", 10_00],
["'$0'", 0],
["'$1'", 100],
["'$10'", 10_00],
];

for (const [input, centsExpected] of inputToExpectedValids) {
const { cents, invalid } = priceWholeToCents(input);

expect(cents).not.toBeNull();
expect(cents).toEqual(centsExpected as number);
expect(invalid).toBe(false);
}

const invalidPrices = [null, undefined, [], {}];
for (const input of invalidPrices) {
const { cents, invalid } = priceWholeToCents(input as any);

expect(cents).toBeNull();
expect(invalid).toBeTrue();
}
});

test("cents to dollars formatted", () => {
const inputToExpectedValids = [
// whole
[0, "$0.00"],
[100, "$1.00"],
[10_00, "$10.00"],
[100_00, "$100.00"],

[9_99, "$9.99"],

// with cents
[1, "$0.01"],
[2, "$0.02"],
[10, "$0.10"],
[90, "$0.90"],
];

for (const [input, expected] of inputToExpectedValids) {
const result = centsToDollarsFormatted(input as Cents);

expect(result).toEqual(expected as string);
}
});
} from "../units.ts";

Deno.test("price whole to cents", () => {
const inputToExpectedValids = [
// formatted as USD
["$0", 0],
["$1", 100],
["$10", 10_00],
["$100", 100_00],

["$0.0", 0],
["$0.00", 0],
["$0.000", 0],

["$1.0", 100],
["$1.00", 100],
["$1.000", 100],

["$1.23", 123],
["$1.234", 123.4],

// formatted as numbers
["0", 0],
["1", 100],
["10", 10_00],
["100", 100_00],

["1.23", 123],
["1.234", 123.4],

// nested quotes (double)
['"$0"', 0],
['"$1"', 100],
['"$10"', 10_00],
['"0"', 0],
['"1"', 100],
['"10"', 10_00],

// nested quotes (single)
["'$0'", 0],
["'$1'", 100],
["'$10'", 10_00],
["'$0'", 0],
["'$1'", 100],
["'$10'", 10_00],
];

for (const [input, centsExpected] of inputToExpectedValids) {
const { cents, invalid } = priceWholeToCents(input);

assertEquals(cents !== null, true);
assertEquals(cents, centsExpected);
assert(invalid === false);
}

const invalidPrices = [null, undefined, [], {}];
for (const input of invalidPrices) {
const { cents, invalid } = priceWholeToCents(input as any);

assertEquals(cents, null);
assertEquals(invalid, true);
}
});

Deno.test("cents to dollars formatted", () => {
const inputToExpectedValids = [
// whole
[0, "$0.00"],
[100, "$1.00"],
[10_00, "$10.00"],
[100_00, "$100.00"],

[9_99, "$9.99"],

// with cents
[1, "$0.01"],
[2, "$0.02"],
[10, "$0.10"],
[90, "$0.90"],
];

for (const [input, expected] of inputToExpectedValids) {
const result = centsToDollarsFormatted(input as Cents);

assertEquals(result, expected);
}
});
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { registerSSH } from "./lib/ssh.ts";
import { registerTokens } from "./lib/tokens.ts";
import { registerDown, registerUp } from "./lib/updown.tsx";
import { registerUpgrade } from "./lib/upgrade.ts";
import { registerClusters } from "./lib/clusters/clusters.tsx";
import { checkVersion } from "./checkVersion.ts";

const program = new Command();
Expand All @@ -30,14 +31,15 @@ registerLogin(program);
registerBuy(program);
registerOrders(program);
registerContracts(program);
registerInstances(program);
registerSSH(program);
// registerInstances(program);
// registerSSH(program);
registerSell(program);
registerBalance(program);
registerTokens(program);
registerUpgrade(program);
registerUp(program);
registerDown(program);
registerClusters(program);

// (development commands)
registerDev(program);
Expand Down
Loading

0 comments on commit b0be010

Please sign in to comment.