Skip to content

expose remote config loading - #648

Open
rishiz27 wants to merge 4 commits into
developfrom
rzarkar/literal-remote-config-loader
Open

rishiz27 wants to merge 4 commits into
developfrom
rzarkar/literal-remote-config-loader

Conversation

@rishiz27

Copy link
Copy Markdown

this exposes the existing remote config fetch as LoadRemoteRef so policy-bot can load the repo policy and shared parent separately, then combine them in a later change.

it returns the file contents without following another remote reference or falling back to an org default. it uses the same client selection, private-remotes setting, caching, cancellation and error handling we already have.

also rejects malformed repo references that could change the request URL before any installation lookup or fetch.

@changelog-app

changelog-app Bot commented Oct 15, 2026

Copy link
Copy Markdown

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

expose remote config loading

Check the box to generate changelog(s)

  • Generate changelog entry

Comment thread appconfig/appconfig.go Outdated
if part == "." || part == ".." || url.PathEscape(part) != part {
return "", "", fmt.Errorf("invalid remote value: %s", r.Remote)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While this is reasonable as a hardening measure, I don't think its required and it could impact all callers. Maybe this could be its own PR and swapped to be applied as one of the optional functions for each client? Alternatively, only in the new LoadRemoteRef func?

Comment thread appconfig/appconfig.go Outdated
Comment on lines +174 to +183
// LoadRemoteRef returns a literal file without parsing references or searching
// other paths or owner defaults. Path and ref defaults are defined by [RemoteRef].
// Missing files are errors; empty files retain their source metadata.
//
// clientOwner must be client's original installation owner, not a loaded file's
// owner. It is trusted caller context. See [WithPrivateRemotes] for cross-owner
// access and its information disclosure warning.
//
// On load errors, Config identifies the remote file, with a ref once resolved.
// An invalid remote repository value returns an empty Config and an error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a bit hard to follow, maybe:

// LoadRemoteRef loads the file identified by remote. Unlike LoadConfig, it
// does not follow remote references, try other paths, or fall back to owner
// defaults. A missing file is an error.
//
// clientOwner is the owner of the installation for that client.
// It determines whether WithPrivateRemotes selects a different installation.

Comment thread appconfig/remote_test.go Outdated
} else if err != nil {
t.Fatal(err)
}
if calls != 1 || cfg.IsUndefined() || len(cfg.Content) != 0 || cfg.Source != "remote/config@main" || cfg.Path != "first.yml" || !cfg.IsRemote {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes it hard to understand what failed. These should be split up.

Comment thread appconfig/remote_test.go
}
})
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think most of this testing is already covered by appconfig_test.go, so could be removed. I'd reduce it to one table test of about three cases (the literal content returned unparsed, missing file is an error, ref defaults to the default branch), and add it as cases in appconfig_test.go using the response player.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants