Skip to content

Bug / Feature Request: Add brace expansion, extended glob matching, and 'globstar' matching to user/project environment variable repo patterns #15744

Closed
@kenibrewer

Description

@kenibrewer

There are other feature request and bugs that have been submitted related to this problem, but none of them encompass the full set of issues that could be solved by implementing a proper solution. I'm going to attempt to consolidate all those into one issue.

Is your feature request related to a problem? Please describe

Currently the environment variable RepoPattern only supports simple repo structures of the type "/" and simple glob matching where a glob takes the place of one of those two variables. The lack of support for more complex repo structures and advanced matching introduces the following problems.

  1. Environment variable scopes are broken in any multi-level Gitlab repo.

Setting SECRET_KEY = XYZ with the scope company/* will not be loaded in a Gitlab repo of the structure company/subgroup/testrepo.

  1. Environment variables need to be managed in a redundant manner.

If I would like SECRET_KEY = XYZ available in the repos company/db and company/frontend but not company/public I would need to create two different environment variables and remember to change both of them instead of setting an environment variable with the pattern company/{db,frontend}.

  1. Environment variables cannot be excluded from domains using NOT logic.

I would like SECRET_KEY = XYZ credentials to be available in any dev environment matches the pattern company/!(internship*)

Describe the behaviour you'd like

Environment variable matching patterns should support the full set of glob-style matching features that developers expect including:

  • Globstar ** matching
  • Matching at multiple repo layers deep
  • Brace expansion, {a,b}
  • NOT matching with !

Describe alternatives you've considered

  • Manually running eval $(gp env -e) after workspace creation can load variables with the basic pattern company/* in nested Gitlab repos
  • There is no alternative for matching at deeper gitlab nested repos.
  • Alternatives for brace expansion include managing redundant ENV variables for each separate context.
  • There is no alternative the lack of negate matching.

Related Issues

The following pre-existing issues would be solved by this feature/request:

Two attempted fixes that were merged but did not actually solve the issue:

Additional context

There is an inconsistency between what environment variables that get loaded during workspace creation/launch and which environment variables get loaded by eval $(gp env -e)

I have not tested whether project environment variables are subject to the same problems and limitations.

Possible Implementation Notes:

The easiest way to enable full advanced glob pattern matching is probably by using switching the WorkspaceEnvVarAccessGuard to use minimatch.

The score function would need to be changed to resolved environment variable conflicts at any layer of depth. Perhaps a function where the score added for an exact match at a given level of depth is 2^(22-depth). (Gitlab supports up to 20 layers of nested subgroups). With this score function higher score would have priority.

The various places that use splitRepositoryPattern like this one would need to be modified.

Additional tests like these ones should be added to test for proper multi-level repo pattern scoping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    meta: staleThis issue/PR is stale and will be closed soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions