Skip to content

Commit 2fece29

Browse files
committed
Add validation for registry_credentials
1 parent ad29ffd commit 2fece29

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

repo2docker/engine.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
from abc import ABC, abstractmethod
88

9-
from traitlets import Dict, default
9+
from traitlets import Dict, TraitError, default, validate
1010
from traitlets.config import LoggingConfigurable
1111

1212
# Based on https://docker-py.readthedocs.io/en/4.2.0/containers.html
@@ -176,6 +176,15 @@ def _registry_credentials_default(self):
176176
raise
177177
return {}
178178

179+
@validate("registry_credentials")
180+
def _registry_credentials_validate(self, proposal):
181+
"""
182+
Validate form of registry credentials
183+
"""
184+
new = proposal["value"]
185+
if len({"registry", "username", "password"} & new.keys()) != 3:
186+
raise TraitError("registry_credentials must have keys 'registry', 'username' and 'password'")
187+
179188
string_output = True
180189
"""
181190
Whether progress events should be strings or an object.

tests/unit/test_engine.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
from traitlets import TraitError
3+
from repo2docker.engine import ContainerEngine
4+
5+
6+
def test_registry_credentials():
7+
e = ContainerEngine(parent=None)
8+
9+
# This should be fine
10+
e.registry_credentials = {"registry": "something", "username": "something", "password": "something"}
11+
12+
with pytest.raises(TraitError):
13+
e.registry_credentials = {"hi": "bye"}

0 commit comments

Comments
 (0)