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
5 changes: 2 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "Codefresh Support Package",
"image": "denoland/deno:1.46.3",
"image": "denoland/deno:2.0.3",
"onCreateCommand": "apt-get update && apt-get install git zip -y",
"customizations": {
"vscode": {
"settings": {
"deno.enable": true,
"deno.lint": true,
"deno.unstable": false
"deno.lint": true
},
"extensions": [
"denoland.vscode-deno",
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Pull requests are the best way to propose changes to the codebase. We actively w

## Any contributions you make will be under the MIT Software License

In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers
the project. Feel free to contact the maintainers if that's a concern.
In short, when you submit code changes, your submissions are understood to be under the same
[MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if
that's a concern.

## Development

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ chmod +x cf-support
1. Go the the [Latest](https://github.com/codefresh-support/codefresh-support-package/releases/latest) release.
1. Download the cf-support_windows_x86_64.zip file
1. Run the `.exe` file via CMD or PowerShell

## Exit Codes

- 10 - Failed to get codefresh credentials. Please set the enviroment variables (CF_API_KEY and CF_BASE_URL) or make sure you have a valid codefresh config file.
- 20 - Failed to Create Demo Pipeline / Project or Failed to run Demo Pipeline.
- 30 - Failed to Delete Demo Pipeline / Project
- 40 - Invalid Runtime Type. ex: Selecting On-Prem for a SaaS Account.
4 changes: 2 additions & 2 deletions ci/codefresh.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0"
version: '1.0'

stages:
- Clone
Expand All @@ -20,7 +20,7 @@ steps:
title: Compiling
stage: Build
arguments:
image: denoland/deno:alpine-1.46.3
image: denoland/deno:alpine-2.0.3
commands:
- cf_export VERSION=$(cat VERSION)
- deno task compile
Expand Down
25 changes: 16 additions & 9 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
{
"fmt": {
"indentWidth": 2,
"lineWidth": 160,
"lineWidth": 120,
"singleQuote": true,
"semiColons": true,
"exclude": [".devcontainer/**"]
"exclude": [
".devcontainer/**",
"README.md",
"ci/**"
]
},
"tasks": {
"pre-compile": "rm -rf ./bin && mkdir ./bin",
"compile:linux": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_linux_x86_64 --target=x86_64-unknown-linux-gnu ./src/main.js",
"compile:windows": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_windows_x86_64 --target=x86_64-pc-windows-msvc ./src/main.js",
"compile:apple": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_x86_64 --target=x86_64-apple-darwin ./src/main.js",
"compile:apple_arm64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_arm64 --target=aarch64-apple-darwin ./src/main.js",
"compile:linux": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_linux_x86_64 --target=x86_64-unknown-linux-gnu ./src/main.ts",
"compile:windows": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_windows_x86_64 --target=x86_64-pc-windows-msvc ./src/main.ts",
"compile:apple": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_x86_64 --target=x86_64-apple-darwin ./src/main.ts",
"compile:apple_arm64": "deno compile --config=./deno.json --allow-env --allow-read --allow-write --allow-net --unsafely-ignore-certificate-errors --allow-run --output=./bin/cf-support_darwin_arm64 --target=aarch64-apple-darwin ./src/main.ts",
"compile": "deno task pre-compile && deno task compile:linux && deno task compile:windows && deno task compile:apple && deno task compile:apple_arm64"
},
"imports": {
"@cloudydeno/kubernetes-apis": "jsr:@cloudydeno/kubernetes-apis@^0.5.1",
"@cliffy/table": "jsr:@cliffy/table@1.0.0-rc.7",
"@cloudydeno/kubernetes-apis": "jsr:@cloudydeno/kubernetes-apis@^0.5.2",
"@cloudydeno/kubernetes-client": "jsr:@cloudydeno/kubernetes-client@^0.7.3",
"@fakoua/zip-ts": "jsr:@fakoua/zip-ts@^1.3.1",
"@std/yaml": "jsr:@std/yaml@^1.0.5"
"@std/encoding": "jsr:@std/encoding@^1.0.5",
"@std/yaml": "jsr:@std/yaml@^1.0.5",
"pako": "npm:pako@^2.1.0"
}
}
}
105 changes: 0 additions & 105 deletions src/codefresh.js

This file was deleted.

52 changes: 52 additions & 0 deletions src/codefresh/codefresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { parse } from '../deps.ts';

enum ContextKeys {
Token = 'token',
Url = 'url',
}

interface Context {
[ContextKeys.Token]: string;
[ContextKeys.Url]: string;
}

interface CodefreshConfig {
contexts: {
[key: string]: Context;
};
'current-context': string;
}

async function readConfigFile() {
const configPath = Deno.build.os === 'windows'
? `${Deno.env.get('USERPROFILE')}/.cfconfig`
: `${Deno.env.get('HOME')}/.cfconfig`;
const configFileContent = await Deno.readTextFile(configPath);
return parse(configFileContent) as CodefreshConfig;
}

async function getCodefreshCredentials(envVar: string, configKey: ContextKeys) {
const envValue = Deno.env.get(envVar);
if (envValue) {
return envValue;
}

try {
const cfConfig = await readConfigFile();
return cfConfig.contexts[cfConfig['current-context']][configKey];
} catch (error) {
console.error('Failed to get Codefresh credentials:', error);
console.error(
'Please set the environment variables (CF_API_KEY and CF_BASE_URL) or make sure you have a valid Codefresh config file.',
);
Deno.exit(10);
}
}

export async function autoDetectCodefreshClient() {
const headers = {
Authorization: await getCodefreshCredentials('CF_API_KEY', ContextKeys.Token),
};
const baseUrl = `${await getCodefreshCredentials('CF_BASE_URL', ContextKeys.Url)}/api`;
return { headers, baseUrl };
}
13 changes: 13 additions & 0 deletions src/codefresh/gitops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { fetchAndSaveData, prepareAndCleanup, RuntimeType, selectNamespace } from '../deps.ts';

export async function gitopsRuntime() {
try {
const namespace = await selectNamespace();
console.log(`\nGathering data in "${namespace}" namespace for the GitOps Runtime.`);
await fetchAndSaveData(RuntimeType.gitops, namespace);
console.log('\nData Gathered Successfully.');
await prepareAndCleanup();
} catch (error) {
console.error(`Error gathering GitOps runtime data:`, error);
}
}
64 changes: 64 additions & 0 deletions src/codefresh/onprem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { fetchAndSaveData, prepareAndCleanup, RuntimeType, selectNamespace, writeCodefreshFiles } from '../deps.ts';

async function getAllAccounts(config: { headers: { Authorization: string }; baseUrl: string }) {
const response = await fetch(`${config.baseUrl}/admin/accounts`, {
method: 'GET',
headers: config.headers,
});
const accounts = await response.json();
await writeCodefreshFiles(accounts, 'onPrem-accounts');
}

async function getAllRuntimes(config: { headers: { Authorization: string }; baseUrl: string }) {
const response = await fetch(`${config.baseUrl}/admin/runtime-environments`, {
method: 'GET',
headers: config.headers,
});
const onPremRuntimes = await response.json();
await writeCodefreshFiles(onPremRuntimes, 'onPrem-runtimes');
}

async function getTotalUsers(config: { headers: { Authorization: string }; baseUrl: string }) {
const response = await fetch(`${config.baseUrl}/admin/user?limit=1&page=1`, {
method: 'GET',
headers: config.headers,
});
const users = await response.json();
await writeCodefreshFiles({ total: users.total }, 'onPrem-totalUsers');
}

async function getSystemFeatureFlags(config: { headers: { Authorization: string }; baseUrl: string }) {
const response = await fetch(`${config.baseUrl}/admin/features`, {
method: 'GET',
headers: config.headers,
});
const onPremSystemFF = await response.json();
await writeCodefreshFiles(onPremSystemFF, 'onPrem-systemFeatureFlags');
}

export async function onPrem(config: { headers: { Authorization: string }; baseUrl: string }) {
if (config.baseUrl === 'https://g.codefresh.io/api') {
console.error(
`\nCannot gather On-Prem data for Codefresh SaaS. Please select either ${RuntimeType.pipelines} or ${RuntimeType.gitops}.`,
);
console.error(
'If you need to gather data for Codefresh On-Prem, please update your ./cfconfig conext (or Envs) to point to an On-Prem instance.',
);
Deno.exit(40);
}
try {
const namespace = await selectNamespace();
console.log(`\nGathering data in "${namespace}" namespace for Codefresh On-Prem.`);
await fetchAndSaveData(RuntimeType.onprem, namespace);
await Promise.all([
getAllAccounts(config),
getAllRuntimes(config),
getTotalUsers(config),
getSystemFeatureFlags(config),
]);
console.log('\nData Gathered Successfully.');
await prepareAndCleanup();
} catch (error) {
console.error(`Error gathering On-Prem data:`, error);
}
}
Loading