10
10
import org .apache .commons .io .FileUtils ;
11
11
import org .apache .commons .lang .StringUtils ;
12
12
13
+ import javax .annotation .CheckForNull ;
14
+ import javax .annotation .Nonnull ;
13
15
import java .io .File ;
14
16
import java .io .IOException ;
15
17
import java .nio .charset .StandardCharsets ;
@@ -27,7 +29,7 @@ public class DockerConfigFile {
27
29
private static final TypeReference <Map <String , AuthConfig >> CONFIG_MAP_TYPE = new TypeReference <Map <String , AuthConfig >>() {
28
30
};
29
31
30
- @ JsonProperty ()
32
+ @ JsonProperty
31
33
private final Map <String , AuthConfig > auths ;
32
34
33
35
public DockerConfigFile () {
@@ -38,6 +40,7 @@ private DockerConfigFile(Map<String, AuthConfig> authConfigMap) {
38
40
auths = authConfigMap ;
39
41
}
40
42
43
+ @ Nonnull
41
44
public Map <String , AuthConfig > getAuths () {
42
45
return auths ;
43
46
}
@@ -46,7 +49,8 @@ void addAuthConfig(AuthConfig config) {
46
49
auths .put (config .getRegistryAddress (), config );
47
50
}
48
51
49
- public AuthConfig resolveAuthConfig (String hostname ) {
52
+ @ CheckForNull
53
+ public AuthConfig resolveAuthConfig (@ CheckForNull String hostname ) {
50
54
if (StringUtils .isEmpty (hostname ) || AuthConfig .DEFAULT_SERVER_ADDRESS .equals (hostname )) {
51
55
return auths .get (AuthConfig .DEFAULT_SERVER_ADDRESS );
52
56
}
@@ -70,6 +74,7 @@ public AuthConfig resolveAuthConfig(String hostname) {
70
74
return null ;
71
75
}
72
76
77
+ @ Nonnull
73
78
public AuthConfigurations getAuthConfigurations () {
74
79
final AuthConfigurations authConfigurations = new AuthConfigurations ();
75
80
for (Map .Entry <String , AuthConfig > authConfigEntry : auths .entrySet ()) {
@@ -112,7 +117,13 @@ public String toString() {
112
117
return "DockerConfigFile [auths=" + auths + "]" ;
113
118
}
114
119
115
- public static DockerConfigFile loadConfig (File dockerConfigPath ) throws IOException {
120
+ @ Nonnull
121
+ public static DockerConfigFile loadConfig (@ CheckForNull String dockerConfigPath ) throws IOException {
122
+ // no any configs, but for empty auths return non null object
123
+ if (dockerConfigPath == null ) {
124
+ return new DockerConfigFile ();
125
+ }
126
+
116
127
//parse new docker config file format
117
128
DockerConfigFile dockerConfig = loadCurrentConfig (dockerConfigPath );
118
129
@@ -136,8 +147,9 @@ public static DockerConfigFile loadConfig(File dockerConfigPath) throws IOExcept
136
147
return dockerConfig ;
137
148
}
138
149
139
- private static DockerConfigFile loadCurrentConfig (File dockerConfigPath ) throws IOException {
140
- File dockerCfgFile = new File (dockerConfigPath , File .separator + DOCKER_CFG );
150
+ @ CheckForNull
151
+ private static DockerConfigFile loadCurrentConfig (@ CheckForNull String dockerConfigPath ) throws IOException {
152
+ File dockerCfgFile = new File (dockerConfigPath , DOCKER_CFG );
141
153
142
154
if (!dockerCfgFile .exists () || !dockerCfgFile .isFile ()) {
143
155
return null ;
@@ -150,8 +162,9 @@ private static DockerConfigFile loadCurrentConfig(File dockerConfigPath) throws
150
162
}
151
163
}
152
164
153
- private static DockerConfigFile loadLegacyConfig (File dockerConfigPath ) throws IOException {
154
- File dockerLegacyCfgFile = new File (dockerConfigPath , File .separator + DOCKER_LEGACY_CFG );
165
+ @ CheckForNull
166
+ private static DockerConfigFile loadLegacyConfig (String dockerConfigPath ) throws IOException {
167
+ File dockerLegacyCfgFile = new File (dockerConfigPath , DOCKER_LEGACY_CFG );
155
168
156
169
if (!dockerLegacyCfgFile .exists () || !dockerLegacyCfgFile .isFile ()) {
157
170
return null ;
0 commit comments