Skip to content

Extension Framework - Make env name optional in EnvironmentService #6732

@JeffreyCA

Description

@JeffreyCA

Problem

EnvironmentService methods have inconsistent env_name handling:

  • GetValue, SetValue, GetValues require explicit env_name (fail if empty)
  • GetConfig, SetConfig, etc. always use default environment (can't target other envs)

Solution

All methods should optionally accept env_name: use specified env if provided, fall back to default if empty.

Changes

1. Proto: Add env_name to Config request messages

In grpc/proto/environment.proto, add env_name as field 1 (shifting existing fields) to:

  • GetConfigRequest
  • GetConfigStringRequest
  • GetConfigSectionRequest
  • SetConfigRequest
  • UnsetConfigRequest

Mirror changes in extensions/microsoft.azd.extensions/internal/resources/languages/proto/environment.proto.

2. Implementation: Add resolver helper

In internal/grpcserver/environment_service.go, add:

func (s *environmentService) resolveEnvironment(ctx context.Context, envName string) (*environment.Environment, error) {
    if envName == "" {
        return s.currentEnvironment(ctx)
    }
    envManager, err := s.lazyEnvManager.GetValue()
    if err != nil {
        return nil, err
    }
    return envManager.Get(ctx, envName)
}

3. Update all methods to use resolveEnvironment()

Replace direct envManager.Get(ctx, req.EnvName) and s.currentEnvironment(ctx) calls with s.resolveEnvironment(ctx, req.EnvName) in:

  • GetValue
  • SetValue
  • GetValues
  • GetConfig
  • GetConfigString
  • GetConfigSection
  • SetConfig
  • UnsetConfig

4. Regenerate protos and update tests

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions