Skip to content

Commit 185ecfa

Browse files
authored
CLI: fix credentials on deploy --beta (#1172)
* project: fix an issue loading openfn props in from-fs * fix tests * changeset * version: cli@1.20.2
1 parent 44a4a59 commit 185ecfa

File tree

15 files changed

+126
-46
lines changed

15 files changed

+126
-46
lines changed

packages/cli/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @openfn/cli
22

3+
## 1.20.2
4+
5+
### Patch Changes
6+
7+
- 6766d96: Fixed an issue where credentials can get dropped in `deploy --beta`
8+
- Updated dependencies [6766d96]
9+
- @openfn/project@0.9.2
10+
311
## 1.20.1
412

513
### Patch Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/cli",
3-
"version": "1.20.1",
3+
"version": "1.20.2",
44
"description": "CLI devtools for the OpenFn toolchain",
55
"engines": {
66
"node": ">=18",

packages/cli/src/deploy/beta.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,28 @@ import Project from '@openfn/project';
44
import { DeployConfig, deployProject } from '@openfn/deploy';
55
import type { Logger } from '../util/logger';
66
import { Opts } from '../options';
7+
import { loadAppAuthConfig } from '../projects/util';
78

89
export type DeployOptionsBeta = Required<
910
Pick<
1011
Opts,
11-
'beta' | 'command' | 'log' | 'logJson' | 'apiKey' | 'endpoint' | 'path'
12+
| 'beta'
13+
| 'command'
14+
| 'log'
15+
| 'logJson'
16+
| 'apiKey'
17+
| 'endpoint'
18+
| 'path'
19+
| 'workspace'
1220
>
1321
>;
1422

1523
export async function handler(options: DeployOptionsBeta, logger: Logger) {
16-
const { OPENFN_API_KEY } = process.env;
17-
18-
const { endpoint } = options;
19-
20-
const config: Partial<DeployConfig> = {
21-
apiKey: options.apiKey,
22-
};
23-
24-
if (!options.apiKey && OPENFN_API_KEY) {
25-
logger.info('Using OPENFN_API_KEY environment variable');
26-
config.apiKey = OPENFN_API_KEY;
27-
}
24+
const config = loadAppAuthConfig(options, logger);
2825

2926
// TMP use options.path to set the directory for now
3027
// We'll need to manage this a bit better
31-
const project = await Project.from('fs', { root: options.path || '.' });
32-
// Why is there an id on openfn here?
33-
console.log({ openfn: project.openfn });
34-
28+
const project = await Project.from('fs', { root: options.workspace || '.' });
3529
// TODO: work out if there's any diff
3630

3731
// generate state for the provisioner
@@ -41,7 +35,7 @@ export async function handler(options: DeployOptionsBeta, logger: Logger) {
4135
logger.debug(JSON.stringify(state, null, 2));
4236

4337
// TODO not totally sold on endpoint handling right now
44-
config.endpoint = endpoint || project.openfn?.endpoint;
38+
config.endpoint ??= project.openfn?.endpoint!;
4539

4640
logger.info('Sending project to app...');
4741

packages/cli/src/deploy/command.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import yargs from 'yargs';
2-
import { build, ensure } from '../util/command-builders';
2+
import { build, ensure, override } from '../util/command-builders';
33
import { Opts } from '../options';
44
import * as o from '../options';
55

@@ -26,6 +26,8 @@ const options = [
2626
o.logJson,
2727
o.projectPath,
2828
o.statePath,
29+
30+
override(o.workspace, { hidden: true }),
2931
];
3032

3133
const deployCommand: yargs.CommandModule<DeployOptions> = {

packages/project/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @openfn/project
22

3+
## 0.9.2
4+
5+
### Patch Changes
6+
7+
- 6766d96: Fixed an issue where credentials can get dropped in `deploy --beta`
8+
39
## 0.9.1
410

511
### Patch Changes

packages/project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/project",
3-
"version": "0.9.1",
3+
"version": "0.9.2",
44
"description": "Read, serialize, replicate and sync OpenFn projects",
55
"scripts": {
66
"test": "pnpm ava",

packages/project/src/Workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Workflow {
9090
return this;
9191
}
9292

93-
// Get properties on any step or edge by id
93+
// Get properties on any step or edge by id or uuid
9494
get(id: string): WithMeta<l.Step | l.Trigger | l.StepEdge> {
9595
const item = this.index.edges[id] || this.index.steps[id];
9696
if (!item) {

packages/project/src/parse/from-fs.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ export const parseProject = async (options: FromFsConfig) => {
7575
fileType === 'yaml' ? yamlToJson(candidate) : JSON.parse(candidate);
7676
if (wf.id && Array.isArray(wf.steps)) {
7777
// load settings from the state file
78-
const wfState: any = (state && state.getWorkflow(wf.id)) ?? {};
79-
wf.openfn = {
80-
uuid: wfState.openfn?.uuid ?? null,
81-
// TODO do we need to transfer more stuff? Options maybe?
82-
};
78+
const wfState = state?.getWorkflow(wf.id);
79+
80+
wf.openfn = Object.assign({}, wfState?.openfn, {
81+
uuid: wfState?.openfn?.uuid ?? null,
82+
});
8383

8484
//console.log('Loading workflow at ', filePath); // TODO logger.debug
8585
for (const step of wf.steps) {
86+
// This is the saved, remote view of the step
87+
// TODO if the id has changed, how do we track?
88+
const stateStep = wfState?.get(step.id);
8689
if (step.expression && step.expression.endsWith('.js')) {
8790
const dir = path.dirname(filePath);
8891
const exprPath = path.join(dir, step.expression);
@@ -94,12 +97,7 @@ export const parseProject = async (options: FromFsConfig) => {
9497
// throw?
9598
}
9699
}
97-
// check the state file for a matching uuid
98-
// TODO this isn't quite right - what if there are other openfn keys to write?
99-
// We need to return not just the UUID, but all the openfn keys
100-
// TODO do we need to slugify the id here? Not really tbh?
101-
const uuid = state?.getUUID(wf.id, step.id) ?? null;
102-
step.openfn = { uuid };
100+
step.openfn = Object.assign({}, stateStep?.openfn);
103101

104102
// Now track UUIDs for edges against state
105103
for (const target in step.next || {}) {

packages/project/test/fixtures/sample-v1-project.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Provisioner } from '@openfn/lexicon/lightning';
2+
import { cloneDeep } from 'lodash-es';
23

34
const state: Provisioner.Project = {
45
id: 'e16c5f09-f0cb-4ba7-a4c2-73fcb2f29d00',
@@ -55,3 +56,11 @@ const state: Provisioner.Project = {
5556
};
5657

5758
export default state;
59+
60+
const withCreds = cloneDeep(state);
61+
Object.assign(withCreds.workflows[0].jobs[0], {
62+
project_credential_id: 'p',
63+
keychain_credential_id: 'k',
64+
});
65+
66+
export { withCreds };

packages/project/test/fixtures/sample-v2-project.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const json: SerializedProject = {
1616
{
1717
name: 'b',
1818
id: 'b',
19-
openfn: { uuid: 3 },
19+
openfn: { uuid: 3, project_credential_id: 'x' },
2020
expression: 'fn()',
2121
adaptor: 'common',
2222
},
@@ -50,6 +50,7 @@ workflows:
5050
id: b
5151
openfn:
5252
uuid: 3
53+
project_credential_id: x
5354
expression: fn()
5455
adaptor: common
5556
- id: trigger

0 commit comments

Comments
 (0)