Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@

<properties>
<version.io.termd>1.0.0-20150807</version.io.termd>
<version.pnc.common>0.6-SNAPSHOT</version.pnc.common>
<version.undertow-websockets-jsr>1.2.6.Final</version.undertow-websockets-jsr>
<version.junit>4.11</version.junit>
<version.org.slf4j>1.7.7</version.org.slf4j>
<version.commons-cli>1.3</version.commons-cli>
<version.jackson>2.5.4</version.jackson>
<version.jackson>2.5.3</version.jackson>

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why reducing version ?

Copy link
Author

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

<jdk.min.version>1.8</jdk.min.version>
<maven.min.version>3.2</maven.min.version>
Expand All @@ -45,6 +46,13 @@

<dependencyManagement>
<dependencies>

<dependency>
<artifactId>common</artifactId>
<groupId>org.jboss.pnc</groupId>
<version>${version.pnc.common}</version>
</dependency>

<dependency>
<groupId>io.termd</groupId>
<artifactId>termd-core</artifactId>
Expand Down Expand Up @@ -98,6 +106,12 @@
</dependencyManagement>

<dependencies>

<dependency>
<artifactId>common</artifactId>
<groupId>org.jboss.pnc</groupId>
</dependency>

<dependency>
<groupId>io.termd</groupId>
<artifactId>termd-core</artifactId>
Expand Down Expand Up @@ -403,15 +417,15 @@
</build>

<repositories>
<repository>
<!-- repository>
<id>jboss-snapshot</id>
<url>https://repository.jboss.org/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repository-->
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
Expand Down
40 changes: 35 additions & 5 deletions src/main/java/org/jboss/pnc/buildagent/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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.");
Expand All @@ -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);
}

Expand Down
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"));
Copy link
Owner

Choose a reason for hiding this comment

The 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 ?

Copy link
Author

Choose a reason for hiding this comment

The 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;
}

}
10 changes: 10 additions & 0 deletions src/main/resources/pnc-config.json
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}"
}
]
}