Skip to content

feat: auto create credentials.yaml#1340

Open
doc-han wants to merge 2 commits intorelease/nextfrom
1261-cli-auto-create-credentialsyaml
Open

feat: auto create credentials.yaml#1340
doc-han wants to merge 2 commits intorelease/nextfrom
1261-cli-auto-create-credentialsyaml

Conversation

@doc-han
Copy link
Copy Markdown
Collaborator

@doc-han doc-han commented Mar 30, 2026

Short Description

This PR adds a feature where a credentials.yaml file is auto generated during the pull (openfn project pull <project-id>).

Fixes #1261

Implementation Details

  • It picks up all referenced credentials from the project yaml file and then generate the credetnials.yaml or .json file from it.

QA Notes

List any considerations/cases/advice for testing/QA here.

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Release branch checklist

Delete this section if this is not a release PR.

If this IS a release branch:

  • Run pnpm changeset version from root to bump versions
  • Run pnpm install
  • Commit the new version numbers
  • Run pnpm changeset tag to generate tags
  • Push tags git push --tags

Tags may need updating if commits come in after the tags are first generated.

@doc-han doc-han linked an issue Mar 30, 2026 that may be closed by this pull request
@github-project-automation github-project-automation bot moved this to New Issues in Core Mar 30, 2026
@doc-han doc-han requested a review from josephjclark March 30, 2026 08:20
};
const { configuration } = job;
// picking credential
if (typeof configuration === 'string' && configuration.trim()) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling configuration.trim() here?

Oh, you're testing if it's not an empty string

Maybe we should rely on the Project class to do this validation for us, and then we can just assume that credentials is falsy or a string? It'll make this code a lot tidier

typeof configuration === 'object' &&
!Array.isArray(configuration) &&
typeof configuration[CREDENTIALS_KEY] === 'string' &&
(configuration[CREDENTIALS_KEY] as string).trim()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Having a bit of a hard time with this but the CREDENTIALS_KEY stuff shouldn't be in the project file. It's only used by execute as a hack to update the user's credential.

Unless you've seen a clear use-case where this is needed, I think we can cut it.

import { CREDENTIALS_KEY } from '../execute/apply-credential-map';
import type { Logger } from '../util/logger';

export function collectCredentialReferences(project: Project): string[] {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe findCredentialIds is a clearer name?

const absolutePath = path.resolve(workspacePath, credentialsPath);
let existing: Record<string, unknown> = {};

if (fs.existsSync(absolutePath)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Not really happy about all this validation being buried down here. If it's not an exact duplicate of the code in execute/handler.ts, it's going to be super close

Maybe we can create a loadCredentialMap util file which is re-used? Then we just have one technique to load the credential map

@github-project-automation github-project-automation bot moved this from New Issues to In review in Core Mar 30, 2026
@josephjclark josephjclark changed the base branch from main to release/next March 31, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

CLI: auto-create credentials.yaml

3 participants