Skip to content

Commit

Permalink
RHCLOUD 33050 - GitHub actions pipeline w/ Linting (#18)
Browse files Browse the repository at this point in the history
* Update to follow googles checkstyle style

Signed-off-by: Jonathan Marcantonio <[email protected]>

* Fail build when lint is violated

Signed-off-by: Jonathan Marcantonio <[email protected]>

* Relint src/main files

Signed-off-by: Jonathan Marcantonio <[email protected]>

* Lint src/test files

Signed-off-by: Jonathan Marcantonio <[email protected]>

* Format new files with checkstyle lint

Signed-off-by: Jonathan Marcantonio <[email protected]>

---------

Signed-off-by: Jonathan Marcantonio <[email protected]>
  • Loading branch information
lennysgarage authored Aug 30, 2024
1 parent e5225ac commit a0738b3
Show file tree
Hide file tree
Showing 15 changed files with 676 additions and 214 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
java-version: '21'
distribution: 'zulu'
cache: maven
- name: Build and test with Maven
run: ./mvnw -B package --file pom.xml
- name: Build, test, and run linter with Maven
run: ./mvnw -B package --file pom.xml # package runs validate, compile, test & package
380 changes: 380 additions & 0 deletions google_checks.xml

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,35 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.4.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.17.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>google_checks.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<violationSeverity>warning</violationSeverity>
<linkXRef>false</linkXRef>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.nicoulaj.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
public class AuthnConfigConverter {

public static AuthenticationConfig convert(Config.AuthenticationConfig authnConfig) {
if(authnConfig == null) {
if (authnConfig == null) {
return null;
}
AuthenticationConfig convertedAuthnConfig;
if(authnConfig.clientCredentialsConfig().isPresent()) {
Config.OIDCClientCredentialsConfig oidcClientCredentialsConfig = authnConfig.clientCredentialsConfig().get();
if (authnConfig.clientCredentialsConfig().isPresent()) {
Config.OIDCClientCredentialsConfig oidcClientCredentialsConfig =
authnConfig.clientCredentialsConfig().get();

convertedAuthnConfig = new OIDCClientCredentialsAuthenticationConfig();
var convertedOidcClientCredentialsConfig = new OIDCClientCredentialsConfig();
convertedOidcClientCredentialsConfig.setIssuer(oidcClientCredentialsConfig.issuer());
convertedOidcClientCredentialsConfig.setClientId(oidcClientCredentialsConfig.clientId());
convertedOidcClientCredentialsConfig.setClientSecret(oidcClientCredentialsConfig.clientSecret());
convertedOidcClientCredentialsConfig.setScope(oidcClientCredentialsConfig.scope());
convertedOidcClientCredentialsConfig.setOidcClientCredentialsMinterImplementation(oidcClientCredentialsConfig.oidcClientCredentialsMinterImplementation());
convertedOidcClientCredentialsConfig.setOidcClientCredentialsMinterImplementation(
oidcClientCredentialsConfig.oidcClientCredentialsMinterImplementation());

((OIDCClientCredentialsAuthenticationConfig)convertedAuthnConfig).setCredentialsConfig(convertedOidcClientCredentialsConfig);
((OIDCClientCredentialsAuthenticationConfig) convertedAuthnConfig).setCredentialsConfig(
convertedOidcClientCredentialsConfig);
} else {
convertedAuthnConfig = new AuthenticationConfig();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ RelationsGrpcClientsManager getManager(Config config) {
var authnEnabled = config.authenticationConfig().map(t -> !t.mode().equals(AuthMode.DISABLED)).orElse(false);

if (isSecureClients) {
if(authnEnabled) {
if (authnEnabled) {
return RelationsGrpcClientsManager.forSecureClients(targetUrl, config.authenticationConfig().get());
}
return RelationsGrpcClientsManager.forSecureClients(targetUrl);
}

if(authnEnabled) {
if (authnEnabled) {
return RelationsGrpcClientsManager.forInsecureClients(targetUrl, config.authenticationConfig().get());
}
return RelationsGrpcClientsManager.forInsecureClients(targetUrl);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/project_kessel/relations/client/CheckClient.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.project_kessel.relations.client;

import org.project_kessel.api.relations.v1beta1.KesselCheckServiceGrpc;
import org.project_kessel.api.relations.v1beta1.CheckRequest;
import org.project_kessel.api.relations.v1beta1.CheckResponse;
import io.grpc.Channel;
import io.grpc.stub.StreamObserver;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.operators.multi.processors.UnicastProcessor;
import org.project_kessel.clients.KesselClient;

import java.util.logging.Logger;
import org.project_kessel.api.relations.v1beta1.CheckRequest;
import org.project_kessel.api.relations.v1beta1.CheckResponse;
import org.project_kessel.api.relations.v1beta1.KesselCheckServiceGrpc;
import org.project_kessel.clients.KesselClient;

public class CheckClient extends KesselClient<KesselCheckServiceGrpc.KesselCheckServiceStub, KesselCheckServiceGrpc.KesselCheckServiceBlockingStub> {
public class CheckClient extends KesselClient<KesselCheckServiceGrpc.KesselCheckServiceStub,
KesselCheckServiceGrpc.KesselCheckServiceBlockingStub> {
private static final Logger logger = Logger.getLogger(CheckClient.class.getName());

CheckClient(Channel channel) {
Expand All @@ -23,6 +23,10 @@ public void check(CheckRequest request,
asyncStub.check(request, responseObserver);
}

public CheckResponse check(CheckRequest request) {
return blockingStub.check(request);
}

public Uni<CheckResponse> checkUni(CheckRequest request) {
final UnicastProcessor<CheckResponse> responseProcessor = UnicastProcessor.create();

Expand All @@ -48,8 +52,4 @@ public void onCompleted() {

return uni;
}

public CheckResponse check(CheckRequest request) {
return blockingStub.check(request);
}
}
11 changes: 8 additions & 3 deletions src/main/java/org/project_kessel/relations/client/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;
import org.project_kessel.clients.authn.AuthenticationConfig.AuthMode;

import java.util.Optional;
import org.project_kessel.clients.authn.AuthenticationConfig.AuthMode;

/**
* Interface for injecting config into container managed beans.
Expand All @@ -17,6 +16,7 @@
public interface Config {
@WithDefault("false")
boolean isSecureClients();

String targetUrl();

@WithName("authn")
Expand All @@ -25,17 +25,22 @@ public interface Config {
interface AuthenticationConfig {
@WithDefault("disabled")
AuthMode mode();

@WithName("client")
Optional<OIDCClientCredentialsConfig> clientCredentialsConfig();
}

interface OIDCClientCredentialsConfig {
interface OIDCClientCredentialsConfig {
String issuer();

@WithName("id")
String clientId();

@WithName("secret")
String clientSecret();

Optional<String[]> scope();

Optional<String> oidcClientCredentialsMinterImplementation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import io.grpc.stub.StreamObserver;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.operators.multi.processors.UnicastProcessor;
import org.project_kessel.api.relations.v1beta1.*;
import org.project_kessel.clients.KesselClient;

import java.util.Iterator;
import java.util.logging.Logger;
import org.project_kessel.api.relations.v1beta1.LookupSubjectsResponse;
import org.project_kessel.api.relations.v1beta1.LookupSubjectsRequest;
import org.project_kessel.api.relations.v1beta1.LookupResourcesResponse;
import org.project_kessel.api.relations.v1beta1.LookupResourcesRequest;
import org.project_kessel.api.relations.v1beta1.KesselLookupServiceGrpc;
import org.project_kessel.clients.KesselClient;

public class LookupClient extends KesselClient<KesselLookupServiceGrpc.KesselLookupServiceStub,KesselLookupServiceGrpc.KesselLookupServiceBlockingStub> {
public class LookupClient extends KesselClient<KesselLookupServiceGrpc.KesselLookupServiceStub,
KesselLookupServiceGrpc.KesselLookupServiceBlockingStub> {
private static final Logger logger = Logger.getLogger(LookupClient.class.getName());

LookupClient(Channel channel) {
Expand All @@ -21,7 +25,12 @@ public void lookupSubjects(LookupSubjectsRequest request, StreamObserver<LookupS
asyncStub.lookupSubjects(request, responseObserver);
}

public void lookupResources(LookupResourcesRequest request, StreamObserver<LookupResourcesResponse> responseObserver) {
public Iterator<LookupSubjectsResponse> lookupSubjects(LookupSubjectsRequest request) {
return blockingStub.lookupSubjects(request);
}

public void lookupResources(LookupResourcesRequest request,
StreamObserver<LookupResourcesResponse> responseObserver) {
asyncStub.lookupResources(request, responseObserver);
}

Expand Down Expand Up @@ -55,10 +64,6 @@ public void onCompleted() {
return multi;
}

public Iterator<LookupSubjectsResponse> lookupSubjects(LookupSubjectsRequest request) {
return blockingStub.lookupSubjects(request);
}

public Multi<LookupSubjectsResponse> lookupSubjectsMulti(LookupSubjectsRequest request) {
final UnicastProcessor<LookupSubjectsResponse> responseProcessor = UnicastProcessor.create();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
package org.project_kessel.relations.client;

import org.project_kessel.api.relations.v1beta1.KesselTupleServiceGrpc;
import org.project_kessel.api.relations.v1beta1.CreateTuplesRequest;
import org.project_kessel.api.relations.v1beta1.ReadTuplesRequest;
import org.project_kessel.api.relations.v1beta1.DeleteTuplesRequest;
import org.project_kessel.api.relations.v1beta1.CreateTuplesResponse;
import org.project_kessel.api.relations.v1beta1.ReadTuplesResponse;
import org.project_kessel.api.relations.v1beta1.DeleteTuplesResponse;
import io.grpc.Channel;
import io.grpc.stub.StreamObserver;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.operators.multi.processors.UnicastProcessor;
import org.project_kessel.clients.KesselClient;

import java.util.Iterator;
import org.project_kessel.api.relations.v1beta1.CreateTuplesRequest;
import org.project_kessel.api.relations.v1beta1.CreateTuplesResponse;
import org.project_kessel.api.relations.v1beta1.DeleteTuplesRequest;
import org.project_kessel.api.relations.v1beta1.DeleteTuplesResponse;
import org.project_kessel.api.relations.v1beta1.KesselTupleServiceGrpc;
import org.project_kessel.api.relations.v1beta1.ReadTuplesRequest;
import org.project_kessel.api.relations.v1beta1.ReadTuplesResponse;
import org.project_kessel.clients.KesselClient;

public class RelationTuplesClient extends KesselClient<KesselTupleServiceGrpc.KesselTupleServiceStub, KesselTupleServiceGrpc.KesselTupleServiceBlockingStub> {
public class RelationTuplesClient extends KesselClient<KesselTupleServiceGrpc.KesselTupleServiceStub,
KesselTupleServiceGrpc.KesselTupleServiceBlockingStub> {
RelationTuplesClient(Channel channel) {
super(KesselTupleServiceGrpc.newStub(channel), KesselTupleServiceGrpc.newBlockingStub(channel));
}

/**
*
*/
public void createTuples(CreateTuplesRequest request,
StreamObserver<CreateTuplesResponse> responseObserver) {
asyncStub.createTuples(request, responseObserver);
}

/**
*
*/
public void readTuples(ReadTuplesRequest request,
StreamObserver<ReadTuplesResponse> responseObserver) {
asyncStub.readTuples(request, responseObserver);
public CreateTuplesResponse createTuples(CreateTuplesRequest request) {
return blockingStub.createTuples(request);
}

/**
*
*/
public void deleteTuples(DeleteTuplesRequest request,
StreamObserver<DeleteTuplesResponse> responseObserver) {
asyncStub.deleteTuples(request, responseObserver);
public void readTuples(ReadTuplesRequest request,
StreamObserver<ReadTuplesResponse> responseObserver) {
asyncStub.readTuples(request, responseObserver);
}

/**
*
*/
public CreateTuplesResponse createTuples(CreateTuplesRequest request) {
return blockingStub.createTuples(request);
public Iterator<ReadTuplesResponse> readTuples(ReadTuplesRequest request) {
return blockingStub.readTuples(request);
}

/**
*
*/
public Iterator<ReadTuplesResponse> readTuples(ReadTuplesRequest request) {
return blockingStub.readTuples(request);
public void deleteTuples(DeleteTuplesRequest request,
StreamObserver<DeleteTuplesResponse> responseObserver) {
asyncStub.deleteTuples(request, responseObserver);
}

/**
*
*/
public DeleteTuplesResponse deleteTuples(DeleteTuplesRequest request) {
return blockingStub.deleteTuples(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@
import org.project_kessel.clients.KesselClientsManager;

public class RelationsGrpcClientsManager extends KesselClientsManager {
private static final String CHANNEL_MANAGER_KEY = RelationsGrpcClientsManager.class.getName();

private RelationsGrpcClientsManager(Channel channel) {
super(channel);
}

private static final String CHANNEL_MANAGER_KEY = RelationsGrpcClientsManager.class.getName();

public static RelationsGrpcClientsManager forInsecureClients(String targetUrl) {
return new RelationsGrpcClientsManager(ChannelManager.getInstance(CHANNEL_MANAGER_KEY).forInsecureClients(targetUrl));
return new RelationsGrpcClientsManager(
ChannelManager.getInstance(CHANNEL_MANAGER_KEY).forInsecureClients(targetUrl));
}

public static RelationsGrpcClientsManager forInsecureClients(String targetUrl, Config.AuthenticationConfig authnConfig) throws RuntimeException {
return new RelationsGrpcClientsManager(ChannelManager.getInstance(CHANNEL_MANAGER_KEY).forInsecureClients(targetUrl, AuthnConfigConverter.convert(authnConfig)));
public static RelationsGrpcClientsManager forInsecureClients(String targetUrl,
Config.AuthenticationConfig authnConfig)
throws RuntimeException {
return new RelationsGrpcClientsManager(ChannelManager.getInstance(CHANNEL_MANAGER_KEY)
.forInsecureClients(targetUrl, AuthnConfigConverter.convert(authnConfig)));
}

public static RelationsGrpcClientsManager forSecureClients(String targetUrl) {
return new RelationsGrpcClientsManager(ChannelManager.getInstance(CHANNEL_MANAGER_KEY).forSecureClients(targetUrl));
return new RelationsGrpcClientsManager(
ChannelManager.getInstance(CHANNEL_MANAGER_KEY).forSecureClients(targetUrl));
}

public static RelationsGrpcClientsManager forSecureClients(String targetUrl, Config.AuthenticationConfig authnConfig) {
return new RelationsGrpcClientsManager(ChannelManager.getInstance(CHANNEL_MANAGER_KEY).forSecureClients(targetUrl, AuthnConfigConverter.convert(authnConfig)));
public static RelationsGrpcClientsManager forSecureClients(String targetUrl,
Config.AuthenticationConfig authnConfig) {
return new RelationsGrpcClientsManager(ChannelManager.getInstance(CHANNEL_MANAGER_KEY)
.forSecureClients(targetUrl, AuthnConfigConverter.convert(authnConfig)));
}

public static void shutdownAll() {
Expand Down
Loading

0 comments on commit a0738b3

Please sign in to comment.