Skip to content

Commit 2b2b5d3

Browse files
committed
feat: Add support on db side for example and default parameters
1 parent f08ab8d commit 2b2b5d3

6 files changed

Lines changed: 97 additions & 7 deletions

File tree

package-lock.json

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"license": "ISC",
4343
"type": "module",
4444
"dependencies": {
45-
"@codifycli/plugin-core": "1.0.1",
45+
"@codifycli/plugin-core": "1.1.0-beta5",
4646
"@codifycli/schemas": "1.0.0",
4747
"ajv": "^8.18.0",
4848
"ajv-formats": "^2.1.1",

scripts/deploy.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ if (!isBeta) {
3737

3838
async function uploadResources() {
3939
const CodifySchema = require('../dist/schemas.json');
40+
const Metadata: Array<Record<string, any>> = require('../dist/metadata.json');
41+
42+
const metadataByType = new Map(Metadata.map((m) => [m.type, m]));
4043

4144
const client = createClient(
4245
process.env.SUPABASE_URL!,
@@ -55,6 +58,7 @@ async function uploadResources() {
5558

5659
for (const resource of resources) {
5760
const type = resource.properties.type.const;
61+
const metadata = metadataByType.get(type);
5862

5963
console.log(`Adding resource ${type}`)
6064
const resourceRow = await client.from('registry_resources').upsert({
@@ -63,19 +67,28 @@ async function uploadResources() {
6367
plugin_name: pluginName,
6468
schema: JSON.stringify(resource),
6569
documentation_url: resource.$comment,
70+
allow_multiple: metadata?.allowMultiple ?? false,
71+
os: metadata?.operatingSystems ?? [],
72+
default_config: metadata?.defaultConfig ? JSON.stringify(metadata.defaultConfig) : null,
73+
example_config_1: metadata?.exampleConfigs?.example1 ? JSON.stringify(metadata.exampleConfigs.example1) : null,
74+
example_config_2: metadata?.exampleConfigs?.example2 ? JSON.stringify(metadata.exampleConfigs.example2) : null,
6675
}, { onConflict: ['type', 'plugin_id'] })
6776
.select()
6877
.throwOnError();
6978

7079
const { id: resourceId } = resourceRow.data![0];
7180

81+
const sensitiveParams: string[] = metadata?.sensitiveParameters ?? [];
82+
const allSensitive = sensitiveParams.includes('*');
83+
7284
const parameters = Object.entries(resource.properties)
7385
.filter(([k]) => k !== 'type')
7486
.map(([key, property]) => ({
75-
type: property.type,
87+
type: (property as any).type,
7688
name: key,
7789
resource_id: resourceId,
7890
schema: property,
91+
is_sensitive: allSensitive || sensitiveParams.includes(key),
7992
}))
8093

8194
await client.from('registry_resource_parameters')

src/resources/ssh/examples.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { ExampleConfigs } from '@codifycli/plugin-core';
2+
3+
export const exampleSshConfigs: ExampleConfigs = {
4+
example1: {
5+
title: 'Example git ssh setup',
6+
configs: [
7+
{
8+
"type": "ssh-key",
9+
"passphrase": ""
10+
},
11+
{
12+
"type": "ssh-config",
13+
"hosts": [{
14+
"Host": "github.com",
15+
"AddKeysToAgent": true,
16+
"UseKeychain": true,
17+
"IdentityFile": "~/.ssh/id_ed25519",
18+
"IgnoreUnknown": "UseKeychain"
19+
}]
20+
},
21+
{
22+
"type": "ssh-add",
23+
"path": "~/.ssh/id_ed25519",
24+
"appleUseKeychain": true,
25+
"os": ["macOS"],
26+
"dependsOn": ["ssh-config"]
27+
},
28+
{
29+
"type": "ssh-add",
30+
"path": "~/.ssh/id_ed25519",
31+
"os": ["linux"],
32+
"dependsOn": ["ssh-config"]
33+
},
34+
{
35+
"type": 'wait-github-ssh-key',
36+
"dependsOn": ["ssh-config"]
37+
},
38+
{
39+
"type": 'git-repository',
40+
"parentDirectory": '~/projects',
41+
"repositories": ['<Replace me here!>', '<Replace me here!>']
42+
}
43+
],
44+
description: 'Configures GitHub SSH access for cloning, pulling, and pushing. Generates a new id_ed25519 key and provides step-by-step guidance for uploading it to GitHub.'
45+
},
46+
}

src/resources/ssh/ssh-config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import path from 'node:path';
1111
import { FileUtils } from '../../utils/file-utils.js';
1212
import { SshConfigHostsParameter } from './ssh-config-hosts-parameter.js';
1313
import Schema from './ssh-config-schema.json';
14+
import { SshKeyConfig } from './ssh-key.js';
15+
import { exampleSshConfigs } from './examples.js';
1416

1517
export type SshConfigOptions = Partial<{
1618
Host: string;
@@ -32,10 +34,22 @@ export interface SshConfig extends StringIndexedObject {
3234
hosts: Array<Partial<SshConfigOptions>>;
3335
}
3436

37+
const defaultConfig: Partial<SshConfig> = {
38+
hosts: [{
39+
Host: "*",
40+
AddKeysToAgent: true,
41+
UseKeychain: true,
42+
IdentityFile: "~/.ssh/id_ed25519",
43+
IgnoreUnknown: "UseKeychain"
44+
}]
45+
}
46+
3547
export class SshConfigFileResource extends Resource<SshConfig> {
3648
getSettings(): ResourceSettings<SshConfig> {
3749
return {
3850
id: 'ssh-config',
51+
defaultConfig,
52+
exampleConfigs: exampleSshConfigs,
3953
operatingSystems: [OS.Darwin, OS.Linux],
4054
schema: Schema,
4155
isSensitive: true,

src/resources/ssh/ssh-key.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import path from 'node:path';
1414

1515
import { FileUtils } from '../../utils/file-utils.js';
1616
import Schema from './ssh-key-schema.json';
17+
import { exampleSshConfigs } from './examples.js';
1718

1819
export type SshKeyType = 'ecdsa' | 'ecdsa-sk' | 'ed25519' | 'ed25519-sk' | 'rsa';
1920

@@ -26,12 +27,19 @@ export interface SshKeyConfig extends StringIndexedObject {
2627
folder: string;
2728
}
2829

30+
const defaultConfig: Partial<SshKeyConfig> = {
31+
keyType: 'ed25519',
32+
passphrase: '',
33+
}
34+
2935
const SSH_KEYGEN_FINGERPRINT_REGEX = /^(\d+) (.*):(.*) (.*) \((.*)\)$/
3036

3137
export class SshKeyResource extends Resource<SshKeyConfig> {
3238
getSettings(): ResourceSettings<SshKeyConfig> {
3339
return {
3440
id: 'ssh-key',
41+
defaultConfig: defaultConfig,
42+
exampleConfigs: exampleSshConfigs,
3543
operatingSystems: [OS.Darwin, OS.Linux],
3644
schema: Schema,
3745
parameterSettings: {

0 commit comments

Comments
 (0)