-
Couldn't load subscription status.
- Fork 10
Ncl 1033 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ncl 1033 #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,17 +18,21 @@ | |
|
|
||
| package org.jboss.pnc.buildagent; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Optional; | ||
|
|
||
| import org.apache.commons.cli.CommandLine; | ||
| import org.apache.commons.cli.CommandLineParser; | ||
| import org.apache.commons.cli.DefaultParser; | ||
| import org.apache.commons.cli.HelpFormatter; | ||
| import org.apache.commons.cli.Option; | ||
| import org.apache.commons.cli.Options; | ||
| import org.apache.commons.cli.ParseException; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.Optional; | ||
| import org.jboss.pnc.buildagent.moduleconfig.BuildAgentModuleConfig; | ||
| import org.jboss.pnc.common.Configuration; | ||
| import org.jboss.pnc.common.json.ConfigurationParseException; | ||
| import org.jboss.pnc.common.json.moduleprovider.BAConfigProvider; | ||
|
|
||
| /** | ||
| * @author <a href="mailto:[email protected]">Matej Lazar</a> | ||
|
|
@@ -37,7 +41,8 @@ public class Main { | |
| private static final String DEFAULT_HOST = "localhost"; | ||
| private static final String DEFAULT_PORT = "8080"; | ||
|
|
||
| public static void main(String[] args) throws ParseException, BuildAgentException, InterruptedException { | ||
| public static void main(String[] args) throws ParseException, BuildAgentException, InterruptedException, | ||
| ConfigurationParseException, Exception { | ||
| Options options = new Options(); | ||
| options.addOption("b", true, "Address to bind. When not specified " + DEFAULT_HOST + " is used as default."); | ||
| options.addOption("p", true, "Port to bind. When not specified " + DEFAULT_PORT + " is used as default."); | ||
|
|
@@ -63,6 +68,31 @@ public static void main(String[] args) throws ParseException, BuildAgentExceptio | |
| } else { | ||
| logPath = Optional.empty(); | ||
| } | ||
|
|
||
| // use configuration here | ||
| Configuration configuration = new Configuration(); | ||
| BuildAgentModuleConfig config = configuration | ||
| .getModuleConfig(new BAConfigProvider<BuildAgentModuleConfig>(BuildAgentModuleConfig.class)); | ||
| String ba_oauth_username = config.getUsername(); | ||
| String ba_oauth_password = config.getPassword(); | ||
| String baseRestURL = config.getBaseAuthUrl(); | ||
|
|
||
| if(ba_oauth_password == null || | ||
| ba_oauth_username == null || | ||
| ba_oauth_password.equals("") || | ||
| ba_oauth_username.equals("")) { | ||
| throw new Exception("Wrong configuration"); | ||
| } | ||
|
|
||
| // TODO OAuth2 releated code here | ||
| System.out.println(">>> BA configuration <<<"); | ||
| System.out.println(">>> BA username: " + ba_oauth_username); | ||
| String print_pwd = "not given"; | ||
| if(ba_oauth_password.length() > 0 ) { | ||
| print_pwd = "given ****"; | ||
| } | ||
| System.out.println(">>> BA password: " + print_pwd); | ||
|
|
||
| new BuildAgent().start(host, port, logPath, null); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * JBoss, Home of Professional Open Source. | ||
| * Copyright 2014 Red Hat, Inc., and individual contributors | ||
| * as indicated by the @author tags. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.jboss.pnc.buildagent.moduleconfig; | ||
|
|
||
| import org.jboss.pnc.common.json.AbstractModuleConfig; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
|
|
||
| public class BuildAgentModuleConfig extends AbstractModuleConfig{ | ||
| private String username; | ||
| private String password; | ||
| private String baseAuthUrl; | ||
|
|
||
| public BuildAgentModuleConfig(@JsonProperty("username") String username, | ||
| @JsonProperty("password")String password, @JsonProperty("baseAuthUrl")String baseAuthUrl) { | ||
| super(); | ||
| this.username = username; | ||
| this.password = password; | ||
| this.baseAuthUrl = baseAuthUrl; | ||
| } | ||
|
|
||
| public String getUsername() { | ||
| return username; | ||
| } | ||
| public void setUsername(String username) { | ||
| this.username = username; | ||
| } | ||
| public String getPassword() { | ||
| return password; | ||
| } | ||
| public void setPassword(String password) { | ||
| this.password = password; | ||
| } | ||
|
|
||
| public String getBaseAuthUrl() { | ||
| return baseAuthUrl; | ||
| } | ||
|
|
||
| public void setBaseAuthUrl(String baseAuthUrl) { | ||
| this.baseAuthUrl = baseAuthUrl; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "AuthenticationModuleConfig [username=HIDDEN, password=" + password + ", baseAuthUrl=" + baseAuthUrl +"]"; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package org.jboss.pnc.common.json.moduleprovider; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.jboss.pnc.buildagent.moduleconfig.BuildAgentModuleConfig; | ||
| import org.jboss.pnc.common.json.AbstractModuleConfig; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.jsontype.NamedType; | ||
|
|
||
| public class BAConfigProvider <T extends AbstractModuleConfig> implements ConfigProvider<T> { | ||
|
|
||
| private List<ProviderNameType<T>> moduleConfigs; | ||
| private Class<T> type; | ||
|
|
||
| public BAConfigProvider(Class<T> type) { | ||
| this.type = type; | ||
| moduleConfigs = new ArrayList<>(); | ||
| moduleConfigs.add(new ProviderNameType(BuildAgentModuleConfig.class,"build-agent-config")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linkage between class (BuildAgentModuleConfig.class) and module name ("build-agent-config") seems the only module specific bits in this class. Can't we move other methods to an abstract class ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will check it out |
||
| } | ||
|
|
||
| /* (non-Javadoc) | ||
| * @see org.jboss.pnc.common.json.moduleprovider.ConfigProviderN#registerProvider(com.fasterxml.jackson.databind.ObjectMapper) | ||
| */ | ||
| @Override | ||
| public void registerProvider(ObjectMapper mapper) { | ||
| for (ProviderNameType<T> providerNameType : moduleConfigs) { | ||
| mapper.registerSubtypes(new NamedType(providerNameType.getType(), providerNameType.getTypeName())); | ||
| } | ||
| } | ||
|
|
||
| /* (non-Javadoc) | ||
| * @see org.jboss.pnc.common.json.moduleprovider.ConfigProviderN#getModuleConfigs() | ||
| */ | ||
| @Override | ||
| public List<ProviderNameType<T>> getModuleConfigs() { | ||
| return moduleConfigs; | ||
| } | ||
|
|
||
| /* (non-Javadoc) | ||
| * @see org.jboss.pnc.common.json.moduleprovider.ConfigProviderN#addModuleConfig(org.jboss.pnc.common.json.moduleprovider.ProviderNameType) | ||
| */ | ||
| @Override | ||
| public void addModuleConfig(ProviderNameType<T> providerNameType) { | ||
| this.moduleConfigs.add(providerNameType); | ||
| } | ||
|
|
||
| public Class<T> getType() { | ||
| return type; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "@class":"ModuleConfigJson","name":"pnc-config", | ||
| "configs":[ | ||
| { | ||
| "@module-config":"build-agent-config", | ||
| "username":"${env.BA_OAUTH_USERNAME}", | ||
| "password":"${env.BA_OAUTH_PASSWORD}" | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why reducing version ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could not get it work, but managed now -> so moving back to 2.5.4 in the next commit