[ZEPPELIN-1376] Add proxy credentials information for dependencies repo

This commit is contained in:
DuyHai DOAN 2016-08-26 16:49:33 +02:00 committed by doanduyhai
parent a9e7bc381a
commit 6f2b6f8e24
7 changed files with 75 additions and 7 deletions

View file

@ -72,7 +72,7 @@ public abstract class AbstractDependencyResolver {
}
}
public void addRepo(String id, String url, boolean snapshot, Authentication auth) {
public void addRepo(String id, String url, boolean snapshot, Authentication auth, Proxy proxy) {
synchronized (repos) {
delRepo(id);
RemoteRepository rr = new RemoteRepository(id, "default", url);
@ -81,6 +81,7 @@ public abstract class AbstractDependencyResolver {
RepositoryPolicy.UPDATE_POLICY_DAILY,
RepositoryPolicy.CHECKSUM_POLICY_WARN));
rr.setAuthentication(auth);
rr.setProxy(proxy);
repos.add(rr);
}
}

View file

@ -16,7 +16,11 @@
*/
package org.apache.zeppelin.dep;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import org.sonatype.aether.repository.Authentication;
import org.sonatype.aether.repository.Proxy;
/**
*
*
@ -27,6 +31,11 @@ public class Repository {
private String url;
private String username = null;
private String password = null;
private String proxyProtocol = "HTTP";
private String proxyHost = null;
private Integer proxyPort = null;
private String proxyLogin = null;
private String proxyPassword = null;
public Repository(String id){
this.id = id;
@ -77,4 +86,16 @@ public class Repository {
}
return auth;
}
public Proxy getProxy() {
if (isNotBlank(proxyHost) && proxyPort != null) {
if (isNotBlank(proxyLogin)) {
return new Proxy(proxyProtocol, proxyHost, proxyPort,
new Authentication(proxyLogin, proxyPassword));
} else {
return new Proxy(proxyProtocol, proxyHost, proxyPort, null);
}
}
return null;
}
}

View file

@ -202,7 +202,7 @@ public class InterpreterRestApi {
try {
Repository request = gson.fromJson(message, Repository.class);
interpreterFactory.addRepository(request.getId(), request.getUrl(), request.isSnapshot(),
request.getAuthentication());
request.getAuthentication(), request.getProxy());
logger.info("New repository {} added", request.getId());
} catch (Exception e) {
logger.error("Exception in InterpreterRestApi while adding repository ", e);

View file

@ -508,7 +508,12 @@
url: '',
snapshot: false,
username: '',
password: ''
password: '',
proxyProtocol: 'HTTP',
proxyHost: '',
proxyPort: null,
proxyLogin: '',
proxyPassword: ''
};
};

View file

@ -65,7 +65,9 @@ limitations under the License.
popover-html-unsafe="<label>URL: </label>
{{repo.url}}<br>
<label>Username: </label>
{{repo.authentication.username}}">
{{repo.authentication.username}}<br>
<label>Proxy host: </label>
{{repo.proxy.host}}">
<span class="fa fa-database"></span>
{{repo.id}}&nbsp;
<span ng-if="!isDefaultRepository(repo.id)" class="fa fa-close blackOpc"

View file

@ -62,6 +62,44 @@ limitations under the License.
<input type="password" class="form-control" id="repoPassword" ng-model="newRepoSetting.password" />
</div>
</div>
<hr/>
<div class="center-block"><h4>Proxy Settings (optional)</h4></div>
<br/>
<div class="form-group">
<div class="col-sm-10">
<label class="control-label col-sm-2" for="proxyProtocol1">Protocol</label>
<label class="radio-inline">
<input type="radio" name="proxyProtocol" id="proxyProtocol1" value="HTTP" ng-model="newRepoSetting.proxyProtocol"/> HTTP
</label>
<label class="radio-inline">
<input type="radio" name="proxyProtocol" id="proxyProtocol2" value="HTTPS" ng-model="newRepoSetting.proxyProtocol"/> HTTPS
</label>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="proxyHost">Host</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="proxyHost" ng-model="newRepoSetting.proxyHost" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="proxyPort">Port</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="proxyPort" ng-model="newRepoSetting.proxyPort" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="proxyLogin">Login</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="proxyLogin" ng-model="newRepoSetting.proxyLogin" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="proxyPassword">Password</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="proxyPassword" ng-model="newRepoSetting.proxyPassword" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit"

View file

@ -62,6 +62,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.aether.RepositoryException;
import org.sonatype.aether.repository.Authentication;
import org.sonatype.aether.repository.Proxy;
import org.sonatype.aether.repository.RemoteRepository;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
@ -1307,9 +1308,9 @@ public class InterpreterFactory implements InterpreterGroupFactory {
return this.interpreterRepositories;
}
public void addRepository(String id, String url, boolean snapshot, Authentication auth)
throws IOException {
depResolver.addRepo(id, url, snapshot, auth);
public void addRepository(String id, String url, boolean snapshot, Authentication auth,
Proxy proxy) throws IOException {
depResolver.addRepo(id, url, snapshot, auth, proxy);
saveToFile();
}