Skip to content

Commit

Permalink
Simplify credentials lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Jul 12, 2024
1 parent 0f17ca8 commit b2790ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ interface RegistryCredentialsProvider {
*/
RegistryCredentials getDefaultCredentials(String registry)

/**
* Provides the default credentials for the specified container
*
* @param container
* A container name e.g. docker.io/library/ubuntu.
* @return
* A {@link RegistryCredentials} object holding the credentials for the specified container or {@code null}
* if not credentials can be found
*/
RegistryCredentials getDefaultCredentials(ContainerPath container)

/**
Expand All @@ -56,4 +65,21 @@ interface RegistryCredentialsProvider {
*/
RegistryCredentials getUserCredentials(ContainerPath container, PlatformId identity)

/**
* Provides the credentials for the specified container. When the platform identity is provider
* this is equivalent to #getUserCredentials.
*
* @param container
* A container name e.g. docker.io/library/ubuntu.
* @param identity
* The platform identity of the user submitting the request
* @return
* A {@link RegistryCredentials} object holding the credentials for the specified container or {@code null}
* if not credentials can be found
*/
default RegistryCredentials getCredentials(ContainerPath container, PlatformId identity) {
return !identity
? getDefaultCredentials(container)
: getUserCredentials(container, identity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ class RegistryProxyService {
}

protected RegistryCredentials getCredentials(RoutePath route) {
final result = !route.identity
? credentialsProvider.getDefaultCredentials(route)
: credentialsProvider.getUserCredentials(route, route.identity)
final result = credentialsProvider.getCredentials(route, route.identity)
log.debug "Credentials for route path=${route.targetContainer}; identity=${route.identity} => ${result}"
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class ContainerInspectServiceImpl implements ContainerInspectService {
// skip this index host because it has already be added to the list
continue
}
final creds = !identity
? credentialsProvider.getDefaultCredentials(path)
: credentialsProvider.getUserCredentials(path, identity)
final creds = credentialsProvider.getCredentials(path, identity)
log.debug "Build credentials for repository: $repo => $creds"
if( !creds ) {
// skip this host because there are no credentials
Expand Down Expand Up @@ -177,9 +175,7 @@ class ContainerInspectServiceImpl implements ContainerInspectService {
else if( item instanceof InspectRepository ) {
final path = ContainerCoordinates.parse(item.getImage())

final creds = !identity
? credentialsProvider.getDefaultCredentials(path)
: credentialsProvider.getUserCredentials(path, identity)
final creds = credentialsProvider.getCredentials(path, identity)
log.debug "Config credentials for repository: ${item.getImage()} => $creds"

final entry = fetchConfig0(path, creds).config?.entrypoint
Expand Down Expand Up @@ -219,9 +215,7 @@ class ContainerInspectServiceImpl implements ContainerInspectService {
ContainerSpec containerSpec(String containerImage, PlatformId identity) {
final path = ContainerCoordinates.parse(containerImage)

final creds = !identity
? credentialsProvider.getDefaultCredentials(path)
: credentialsProvider.getUserCredentials(path, identity)
final creds = credentialsProvider.getCredentials(path, identity)
log.debug "Inspect credentials for repository: ${containerImage} => $creds"

final client = client0(path, creds)
Expand Down

0 comments on commit b2790ee

Please sign in to comment.