Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/build-external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ jobs:
${{ runner.os }}-
- name: Run maven build
run: mvn install -PprettierCheck -Dprettier.nodePath=node -Dprettier.npmPath=npm
- name: codecov
uses: codecov/codecov-action@v5
with:
files: ./**/target/site/jacoco/jacoco.xml
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
${{ runner.os }}-maven-
${{ runner.os }}-

- name: Run maven build
run: mvn verify -s .github/workflows/settings.xml -PprettierCheck -Dprettier.nodePath=node -Dprettier.npmPath=npm
- name: Sonar Scan
Expand All @@ -47,6 +46,10 @@ jobs:
-Dsonar.projectName=${SONAR_PROJECT_NAME} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.token=${SONAR_TOKEN}
- name: codecov
uses: codecov/codecov-action@v5
with:
files: ./**/target/site/jacoco/jacoco.xml
- name: Upload artifact
uses: actions/[email protected]
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ jobs:
-Dsonar.projectName=${SONAR_PROJECT_NAME} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.token=${SONAR_TOKEN}
- name: codecov
uses: codecov/codecov-action@v5
with:
files: ./**/target/site/jacoco/jacoco.xml
- name: Upload artifact
uses: actions/[email protected]
with:
Expand Down
187 changes: 187 additions & 0 deletions gbfs-validator-java-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.entur.gbfs</groupId>
<artifactId>gbfs-validator-java-parent</artifactId>
<version>2.0.57-SNAPSHOT</version>
</parent>

<artifactId>gbfs-validator-java-cli</artifactId>
<packaging>jar</packaging>
<name>GBFS Validator CLI</name>
<description>Command-line interface for GBFS validation</description>
<url>https://github.com/entur/gbfs-validator-java</url>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<picocli.version>4.7.7</picocli.version>
<jackson.version>2.15.2</jackson.version>
<junit.version>5.10.2</junit.version>
<jacoco-maven-plugin.version>0.8.13</jacoco-maven-plugin.version>
<!-- empty argLine property, the value is set up by Jacoco during unit tests execution -->
<argLine></argLine>
</properties>

<dependencies>
<!-- Internal dependencies -->
<dependency>
<groupId>org.entur.gbfs</groupId>
<artifactId>gbfs-validator-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.entur.gbfs</groupId>
<artifactId>gbfs-validator-java-loader</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Picocli for CLI parsing -->
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>${picocli.version}</version>
</dependency>

<!-- Jackson for JSON output -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- SLF4J simple logger for CLI (runtime only) -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.17</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.35.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- Compiler with Picocli annotation processor -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>${picocli.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
</compilerArgs>
</configuration>
</plugin>

<!-- Maven Shade Plugin for executable uber-JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.entur.gbfs.validator.cli.GbfsValidatorCli</mainClass>
</transformer>
</transformers>
<finalName>gbfs-validator-cli</finalName>
<filters>
<filter>
<!-- Exclude signature files -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>

<!-- Jacoco for code coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules />
</configuration>
</execution>
</executions>
</plugin>

<!-- Surefire for tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.entur.gbfs.validator.cli;

import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;

public class AuthOptions {

@Option(
names = { "--auth-type" },
description = "Authentication type: basic, bearer, or oauth"
)
AuthType authType;

@ArgGroup(exclusive = false)
BasicAuthOptions basicAuth;

@ArgGroup(exclusive = false)
BearerAuthOptions bearerAuth;

@ArgGroup(exclusive = false)
OAuthOptions oauthOptions;

public static class BasicAuthOptions {

@Option(
names = { "--username" },
description = "Username for Basic Authentication",
required = true
)
String username;

@Option(
names = { "--password" },
description = "Password for Basic Authentication",
required = true
)
String password;
}

public static class BearerAuthOptions {

@Option(
names = { "--token" },
description = "Bearer token",
required = true
)
String token;
}

public static class OAuthOptions {

@Option(
names = { "--client-id" },
description = "OAuth client ID",
required = true
)
String clientId;

@Option(
names = { "--client-secret" },
description = "OAuth client secret",
required = true
)
String clientSecret;

@Option(
names = { "--token-url" },
description = "OAuth token endpoint URL",
required = true
)
String tokenUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.entur.gbfs.validator.cli;

public enum AuthType {
BASIC,
BEARER,
OAUTH,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.entur.gbfs.validator.cli;

import org.entur.gbfs.validator.loader.auth.Authentication;
import org.entur.gbfs.validator.loader.auth.BasicAuth;
import org.entur.gbfs.validator.loader.auth.BearerTokenAuth;
import org.entur.gbfs.validator.loader.auth.OAuthClientCredentialsGrantAuth;

public class AuthenticationHandler {

public static Authentication buildAuthentication(AuthOptions authOptions) {
if (authOptions == null || authOptions.authType == null) {
return null;
}

return switch (authOptions.authType) {
case BASIC -> {
if (authOptions.basicAuth == null) {
throw new IllegalArgumentException(
"Basic auth selected but --username and --password not provided"
);
}
yield new BasicAuth(
authOptions.basicAuth.username,
authOptions.basicAuth.password
);
}
case BEARER -> {
if (authOptions.bearerAuth == null) {
throw new IllegalArgumentException(
"Bearer auth selected but --token not provided"
);
}
yield new BearerTokenAuth(authOptions.bearerAuth.token);
}
case OAUTH -> {
if (authOptions.oauthOptions == null) {
throw new IllegalArgumentException(
"OAuth auth selected but credentials not provided"
);
}
yield new OAuthClientCredentialsGrantAuth(
authOptions.oauthOptions.clientId,
authOptions.oauthOptions.clientSecret,
authOptions.oauthOptions.tokenUrl
);
}
};
}
}
Loading