Skip to content

Commit 0948279

Browse files
committed
feat: Bumped library version. New transformations type
1 parent 1b9ab1b commit 0948279

File tree

14 files changed

+71
-72
lines changed

14 files changed

+71
-72
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"ajv": "^8.12.0",
2424
"ajv-formats": "^2.1.1",
2525
"semver": "^7.6.0",
26-
"codify-plugin-lib": "1.0.132",
26+
"codify-plugin-lib": "1.0.136",
2727
"codify-schemas": "1.0.63",
2828
"chalk": "^5.3.0",
2929
"debug": "^4.3.4",

src/resources/asdf/asdf-global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class AsdfGlobalResource extends Resource<AsdfGlobalConfig> {
1818
id: 'asdf-global',
1919
dependencies: ['asdf', 'asdf-plugin'],
2020
schema: AsdfGlobalSchema,
21-
import: {
21+
importAndDestroy:{
2222
requiredParameters: ['plugin'],
2323
refreshKeys: ['plugin', 'version'],
2424
defaultRefreshValues: {

src/resources/asdf/asdf-install.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
2525
dependencies: ['asdf'],
2626
schema: AsdfInstallSchema,
2727
parameterSettings: {
28-
directory: { type: 'directory', inputTransformation: (input) => untildify(input) },
28+
directory: { type: 'directory' },
2929
versions: { type: 'array' }
3030
},
31-
import: {
31+
importAndDestroy:{
3232
requiredParameters: ['directory'],
3333
refreshKeys: ['directory']
3434
},

src/resources/asdf/asdf-local.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,13 @@ export class AsdfLocalResource extends Resource<AsdfLocalConfig> {
3333
dependencies: ['asdf', 'asdf-plugin'],
3434
schema: AsdfLocalSchema,
3535
parameterSettings: {
36-
directory: {
37-
inputTransformation: (input) => untildify(input),
38-
},
39-
directories: {
40-
type: 'array',
41-
canModify: true,
42-
inputTransformation: (input) => input.map((i: any) => untildify(i)),
43-
},
36+
directory: { type: 'directory' },
37+
directories: { type: 'array', canModify: true, itemType: 'directory' },
4438
version: {
4539
canModify: true,
4640
}
4741
},
48-
import: {
42+
importAndDestroy:{
4943
requiredParameters: ['plugin', 'directory'],
5044
refreshKeys: ['plugin', 'version', 'directory'],
5145
defaultRefreshValues: {

src/resources/aws-cli/profile/aws-profile.ts

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

1515
import { SpawnStatus, codifySpawn } from '../../../utils/codify-spawn.js';
1616
import Schema from './aws-profile-schema.json'
17-
import { CSVCredentialsParameter } from './csv-credentials-parameter.js';
17+
import { CSVCredentialsTransformation } from './csv-credentials-transformation.js';
1818

1919
export interface AwsProfileConfig extends StringIndexedObject {
2020
awsAccessKeyId: string;
@@ -37,24 +37,25 @@ export class AwsProfileResource extends Resource<AwsProfileConfig> {
3737
parameterSettings: {
3838
awsAccessKeyId: { canModify: true },
3939
awsSecretAccessKey: { canModify: true },
40+
csvCredentials: { type: 'setting' }, // Type setting means it won't be included in the plan calculation
4041
output: { default: 'json', canModify: true },
4142
profile: { default: 'default', canModify: true },
4243
metadataServiceNumAttempts: { canModify: true },
4344
metadataServiceTimeout: { canModify: true },
4445
},
45-
inputTransformation: CSVCredentialsParameter.transform,
46-
import: {
46+
transformation: CSVCredentialsTransformation,
47+
importAndDestroy:{
4748
refreshKeys: ['output', 'profile', 'awsAccessKeyId', 'awsSecretAccessKey', 'region'],
4849
requiredParameters: ['profile']
4950
}
5051
};
5152
}
5253

5354
override async validate(parameters: Partial<AwsProfileConfig>): Promise<void> {
54-
if (parameters.csvCredentials
55-
&& (parameters.awsAccessKeyId || parameters.awsSecretAccessKey)) {
56-
throw new Error('Csv credentials cannot be added together with awsAccessKeyId or awsSecretAccessKey')
57-
}
55+
// if (parameters.csvCredentials
56+
// && (parameters.awsAccessKeyId || parameters.awsSecretAccessKey)) {
57+
// throw new Error('Csv credentials cannot be added together with awsAccessKeyId or awsSecretAccessKey')
58+
// }
5859
}
5960

6061
override async refresh(parameters: Partial<AwsProfileConfig>): Promise<Partial<AwsProfileConfig> | null> {

src/resources/aws-cli/profile/csv-credentials-parameter.ts renamed to src/resources/aws-cli/profile/csv-credentials-transformation.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { type InputTransformation } from 'codify-plugin-lib';
12
import * as fsSync from 'node:fs';
23
import * as fs from 'node:fs/promises';
34
import path from 'node:path';
45

56
import { untildify } from '../../../utils/untildify.js';
67
import { AwsProfileConfig } from './aws-profile.js';
78

8-
export const CSVCredentialsParameter = {
9-
10-
async transform(input: Partial<AwsProfileConfig>): Promise<Partial<AwsProfileConfig>> {
9+
export const CSVCredentialsTransformation: InputTransformation = {
10+
async to(input: Partial<AwsProfileConfig>): Promise<Partial<AwsProfileConfig>> {
1111
if (!input.csvCredentials) {
1212
return input;
1313
}
@@ -30,13 +30,17 @@ export const CSVCredentialsParameter = {
3030
throw new Error(`File ${csvPath} is not properly formatted. It must be a csv in the format: awsAccessKeyId, awsSecretAccessKey`);
3131
}
3232

33-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
34-
const { csvCredentials: _, awsAccessKeyId: __, awsSecretAccessKey: ___, ...restOfParameters } = input;
35-
3633
return {
37-
...restOfParameters,
34+
...input,
3835
awsAccessKeyId,
3936
awsSecretAccessKey,
4037
};
4138
},
39+
40+
from(output: Partial<AwsProfileConfig>): Partial<AwsProfileConfig> {
41+
delete output.awsAccessKeyId
42+
delete output.awsSecretAccessKey
43+
44+
return output;
45+
}
4246
};

src/resources/git/clone/git-clone.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class GitCloneResource extends Resource<GitCloneConfig> {
2525
directory: { type: 'directory' },
2626
autoVerifySSH: { type: 'setting', default: true },
2727
},
28-
import: {
28+
importAndDestroy:{
2929
requiredParameters: ['directory']
3030
},
3131
dependencies: [
@@ -99,6 +99,7 @@ export class GitCloneResource extends Resource<GitCloneConfig> {
9999

100100
override async destroy(plan: DestroyPlan<GitCloneConfig>): Promise<void> {
101101
// Do nothing here. We don't want to destroy a user's repository.
102+
// TODO: change this to skip the destroy only if the user's repo has pending changes (check via git)
102103
throw new Error(`The git-clone resource is not designed to delete folders.
103104
Please delete ${plan.currentConfig.directory ?? (plan.currentConfig.parentDirectory! + this.extractBasename(plan.currentConfig.repository))} manually and re-apply`);
104105
}

src/resources/scripting/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class FileResource extends Resource<FileConfig> {
2222
contents: { canModify: true },
2323
onlyCreate: { type: 'boolean' }
2424
},
25-
import: {
25+
importAndDestroy:{
2626
requiredParameters: ['path']
2727
}
2828
}

src/resources/shell/path/path-resource.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,11 @@ export class PathResource extends Resource<PathConfig> {
3030
id: 'path',
3131
schema: Schema,
3232
parameterSettings: {
33-
path: {
34-
type: 'directory',
35-
inputTransformation: (value) => {
36-
const escapedPath = untildify(value);
37-
return path.resolve(escapedPath)
38-
}
39-
},
40-
paths: {
41-
canModify: true,
42-
type: 'array',
43-
isElementEqual: 'directory',
44-
inputTransformation: (values) =>
45-
values.map((value: string) => {
46-
const escapedPath = untildify(value);
47-
return path.resolve(escapedPath)
48-
}
49-
)
50-
},
33+
path: { type: 'directory' },
34+
paths: { canModify: true, type: 'array', itemType: 'directory' },
5135
prepend: { default: false }
5236
},
53-
import: {
37+
importAndDestroy:{
5438
refreshKeys: ['paths'],
5539
defaultRefreshValues: {
5640
paths: []

src/resources/ssh/ssh-config-hosts-parameter.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,28 @@ export class SshConfigHostsParameter extends StatefulParameter<SshConfig, SshCon
3333
filterInStatelessMode(desired, current) {
3434
return current.filter((c) => desired.some((d) => SshConfigHostsParameter.isHostObjectSame(c, d)))
3535
},
36-
inputTransformation: (hosts: SshConfigOptions[]) => hosts.map((h) => Object.fromEntries(
37-
Object.entries(h)
38-
.map(([k, v]) => [
39-
k,
40-
typeof v === 'boolean'
41-
? (v ? 'yes' : 'no') // The file takes 'yes' or 'no' instead of booleans
42-
: v,
43-
])
44-
)
45-
)
36+
transformation: {
37+
to: (hosts: SshConfigOptions[]) => hosts.map((h) => Object.fromEntries(
38+
Object.entries(h)
39+
.map(([k, v]) => [
40+
k,
41+
typeof v === 'boolean'
42+
? (v ? 'yes' : 'no') // The file takes 'yes' or 'no' instead of booleans
43+
: v,
44+
])
45+
)
46+
),
47+
from: (hosts: SshConfigOptions[]) => hosts.map((h) => Object.fromEntries(
48+
Object.entries(h)
49+
.map(([k, v]) => [
50+
k,
51+
v === 'yes' || v === 'no'
52+
? (v === 'yes') // The file takes 'yes' or 'no' instead of booleans
53+
: v,
54+
])
55+
)
56+
),
57+
}
4658
}
4759
}
4860

0 commit comments

Comments
 (0)