Skip to content

Make --allow replace an upstream's configured allow-list - #67

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/allow-replaces-config-list
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/allow-replaces-config-list

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #48

What was wrong

TryApplyAllows wrote each --allow name=pattern flag to GitLfsCache:Upstreams:{name}:Repositories:{index}, starting at index 0. .NET configuration merges arrays by index across providers, so the flags replaced only the first N entries of a list that came from --config, appsettings.json or environment variables. Any entries at higher indices stayed in force.

With config ["studio/**", "**"] and --allow github=only/**, the bound list was ["only/**", "**"], so the proxy still allowed every repository.

Change

This implements the maintainer decision on the issue: --allow replaces the list.

  • TryParseAllows groups the flag patterns by upstream (case-insensitive, in the order typed) instead of writing configuration keys.
  • ReplaceAllowLists runs as a PostConfigure<GitLfsCacheOptions> step and assigns each named upstream's Repositories outright. It creates the upstream if configuration didn't declare it, which matches the old behaviour of an --upstream/--allow pair on the command line. Upstreams that no --allow names keep their configured list.
  • A post-configure step runs before options validation, so the existing "an upstream needs at least one pattern" check still applies to the final list.
  • README: the configuration section now says --allow replaces the configured list for the upstream it names, rather than adding to it.
  • --token-key is out of scope, as the decision says, and keeps its index-merge behaviour.

Tests

New GitLfsCache.Tests/Tool/AllowFlagTests.cs. The test project now references the tool project, whose AssemblyInfo.cs already grants InternalsVisibleTo for this purpose. The tests bind options the way the tool does: a JSON configuration file with the flags applied over it.

  • Acceptance criterion: config supplies 2 entries, --allow supplies 1, and the bound list is exactly that 1 entry.
  • Repeated flags (with mixed-case upstream names) keep every pattern, in order.
  • An upstream the flags don't name keeps its configured list.
  • A flag for an upstream missing from configuration adds that upstream.
  • With no flags, the configured list is unchanged.
  • Malformed entries are reported.

Checked both directions:

  • With ReplaceAllowLists changed back to overwrite-by-index (the old merge semantics), Allow_FewerPatternsThanConfigured_ReplacesTheConfiguredList fails.
  • With the fix, the full suite passes: 338/338.

🤖 Generated with Claude Code

https://claude.ai/code/session_015u9u95HXjY2mDagnzGzxK2


Generated by Claude Code

The --allow flags were written as Repositories:{index} configuration keys,
and configuration merges arrays by index. A flag therefore replaced only
the first entries of a list from --config, appsettings.json or the
environment, and left the rest in force: config ["studio/**", "**"] plus
--allow github=only/** still bound ["only/**", "**"].

The flags are now grouped per upstream and assigned in a post-configure
step, so an upstream named by --allow allows exactly the flag patterns.
Upstreams no flag names keep their configured list. The README now says
so.

Fixes #48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015u9u95HXjY2mDagnzGzxK2
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

2 participants