def create_upstream_registry(self) -> UpstreamRegistryConfig:
    endpoint_url = URL(self._environ['NP_REGISTRY_UPSTREAM_URL'])
    project = self._environ['NP_REGISTRY_UPSTREAM_PROJECT']
    max_catalog_entries = int(self._environ.get('NP_REGISTRY_UPSTREAM_MAX_CATALOG_ENTRIES', UpstreamRegistryConfig.max_catalog_entries))
    upstream_type = UpstreamType(self._environ.get('NP_REGISTRY_UPSTREAM_TYPE', UpstreamType.OAUTH.value))
    upstream: dict[(str, Any)] = dict(endpoint_url=endpoint_url, project=project, max_catalog_entries=max_catalog_entries, type=upstream_type)
    if (upstream_type == UpstreamType.OAUTH):
        upstream.update(dict(token_endpoint_url=URL(self._environ['NP_REGISTRY_UPSTREAM_TOKEN_URL']), token_service=self._environ['NP_REGISTRY_UPSTREAM_TOKEN_SERVICE'], token_endpoint_username=self._environ['NP_REGISTRY_UPSTREAM_TOKEN_USERNAME'], token_endpoint_password=self._environ['NP_REGISTRY_UPSTREAM_TOKEN_PASSWORD']))
        if ('NP_REGISTRY_UPSTREAM_TOKEN_REGISTRY_SCOPE' in self._environ):
            upstream['token_registry_catalog_scope'] = self._environ['NP_REGISTRY_UPSTREAM_TOKEN_REGISTRY_SCOPE']
        if ('NP_REGISTRY_UPSTREAM_TOKEN_REPO_SCOPE_ACTIONS' in self._environ):
            upstream['token_repository_scope_actions'] = self._environ['NP_REGISTRY_UPSTREAM_TOKEN_REPO_SCOPE_ACTIONS']
    if (upstream_type == UpstreamType.BASIC):
        basic_username = self._environ.get('NP_REGISTRY_UPSTREAM_BASIC_USERNAME')
        if (basic_username is not None):
            upstream['basic_username'] = basic_username
        basic_password = self._environ.get('NP_REGISTRY_UPSTREAM_BASIC_PASSWORD')
        if (basic_password is not None):
            upstream['basic_password'] = basic_password
    return UpstreamRegistryConfig(**upstream)
def create_upstream_registry(self) -> UpstreamRegistryConfig:
    endpoint_url = URL(self._environ['NP_REGISTRY_UPSTREAM_URL'])
    project = self._environ['NP_REGISTRY_UPSTREAM_PROJECT']
    max_catalog_entries = int(self._environ.get('NP_REGISTRY_UPSTREAM_MAX_CATALOG_ENTRIES', UpstreamRegistryConfig.max_catalog_entries))
    upstream_type = UpstreamType(self._environ.get('NP_REGISTRY_UPSTREAM_TYPE', UpstreamType.OAUTH.value))
    upstream: dict[(str, Any)] = dict(endpoint_url=endpoint_url, project=project, max_catalog_entries=max_catalog_entries, type=upstream_type)
    if (upstream_type == UpstreamType.OAUTH):
        upstream.update(dict(token_endpoint_url=URL(self._environ['NP_REGISTRY_UPSTREAM_TOKEN_URL']), token_service=self._environ['NP_REGISTRY_UPSTREAM_TOKEN_SERVICE'], token_endpoint_username=self._environ['NP_REGISTRY_UPSTREAM_TOKEN_USERNAME'], token_endpoint_password=self._environ['NP_REGISTRY_UPSTREAM_TOKEN_PASSWORD']))
        if ('NP_REGISTRY_UPSTREAM_TOKEN_REGISTRY_SCOPE' in self._environ):
            upstream['token_registry_catalog_scope'] = self._environ['NP_REGISTRY_UPSTREAM_TOKEN_REGISTRY_SCOPE']
        if ('NP_REGISTRY_UPSTREAM_TOKEN_REPO_SCOPE_ACTIONS' in self._environ):
            upstream['token_repository_scope_actions'] = self._environ['NP_REGISTRY_UPSTREAM_TOKEN_REPO_SCOPE_ACTIONS']
    if (upstream_type == UpstreamType.BASIC):
        basic_username = self._environ.get('NP_REGISTRY_UPSTREAM_BASIC_USERNAME')
        if (basic_username is not None):
            upstream['basic_username'] = basic_username
        basic_password = self._environ.get('NP_REGISTRY_UPSTREAM_BASIC_PASSWORD')
        if (basic_password is not None):
            upstream['basic_password'] = basic_password
    return UpstreamRegistryConfig(**upstream)