Add support for pull credentials on builds and build triggers
This commit is contained in:
parent
1fc3c922a9
commit
2006917e03
17 changed files with 355 additions and 37 deletions
|
@ -33,6 +33,13 @@ def get_job_config(build_obj):
|
|||
|
||||
|
||||
def trigger_view(trigger):
|
||||
def user_view(user):
|
||||
return {
|
||||
'name': user.username,
|
||||
'kind': 'user',
|
||||
'is_robot': user.robot,
|
||||
}
|
||||
|
||||
if trigger and trigger.uuid:
|
||||
config_dict = get_trigger_config(trigger)
|
||||
build_trigger = BuildTrigger.get_trigger_for_service(trigger.service.name)
|
||||
|
@ -41,7 +48,8 @@ def trigger_view(trigger):
|
|||
'config': config_dict,
|
||||
'id': trigger.uuid,
|
||||
'connected_user': trigger.connected_user.username,
|
||||
'is_active': build_trigger.is_active(config_dict)
|
||||
'is_active': build_trigger.is_active(config_dict),
|
||||
'pull_user': user_view(trigger.pull_user) if trigger.pull_user else None
|
||||
}
|
||||
|
||||
return None
|
||||
|
@ -88,6 +96,29 @@ class RepositoryBuildList(RepositoryParamResource):
|
|||
'type': 'string',
|
||||
'description': 'Subdirectory in which the Dockerfile can be found',
|
||||
},
|
||||
'pull_credentials': {
|
||||
'type': 'object',
|
||||
'description': 'Credentials used by the builder when pulling images',
|
||||
'required': [
|
||||
'username',
|
||||
'password',
|
||||
'registry'
|
||||
],
|
||||
'properties': {
|
||||
'username': {
|
||||
'type': 'string',
|
||||
'description': 'The username for the pull'
|
||||
},
|
||||
'password': {
|
||||
'type': 'string',
|
||||
'description': 'The password for the pull'
|
||||
},
|
||||
'registry': {
|
||||
'type': 'string',
|
||||
'description': 'The registry hostname for the pull'
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -116,6 +147,7 @@ class RepositoryBuildList(RepositoryParamResource):
|
|||
|
||||
dockerfile_id = request_json['file_id']
|
||||
subdir = request_json['subdirectory'] if 'subdirectory' in request_json else ''
|
||||
pull_credentials = request_json.get('pull_credentials', None)
|
||||
|
||||
# Check if the dockerfile resource has already been used. If so, then it
|
||||
# can only be reused if the user has access to the repository for which it
|
||||
|
@ -130,7 +162,8 @@ class RepositoryBuildList(RepositoryParamResource):
|
|||
repo = model.get_repository(namespace, repository)
|
||||
display_name = user_files.get_file_checksum(dockerfile_id)
|
||||
|
||||
build_request = start_build(repo, dockerfile_id, ['latest'], display_name, subdir, True)
|
||||
build_request = start_build(repo, dockerfile_id, ['latest'], display_name, subdir, True,
|
||||
pull_credentials=pull_credentials)
|
||||
|
||||
resp = build_status_view(build_request, True)
|
||||
repo_string = '%s/%s' % (namespace, repository)
|
||||
|
|
Reference in a new issue