From ee633dc5dfdfde28401d0414bb33d0a052b752f1 Mon Sep 17 00:00:00 2001 From: Gavin Date: Thu, 29 Feb 2024 22:07:45 -0800 Subject: [PATCH 1/2] Log to stdout and fix fat / shadow jar Logging to standard out means we no longer need the JNA jar, which doesn't work when shadowed. Making a shadow jar vs. a fat jar means the dependencies in the jar won't collide with the dependencies in projects that use the shadow jar for testing. --- build.gradle | 22 ++++---- .../us/kbase/auth2/kbase/KBaseAuthConfig.java | 53 +++++++++++++++---- .../us/kbase/test/auth2/TestConfigurator.java | 8 +-- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index 4fff21ec..5b6b34e8 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { id 'war' id 'jacoco' id 'org.ajoberstar.grgit' version '4.1.1' + id 'com.github.johnrengelman.shadow' version '8.1.1' } repositories { @@ -94,28 +95,24 @@ task generateTemplateFileList { } } - -task fatTestJar(type: Jar) { +shadowJar { // Be careful when updating jars - you may want to set the duplicates strategy to WARN // to see if any of the jars are shadowing the others when building the fat jar, which // has been the case in the past duplicatesStrategy = DuplicatesStrategy.EXCLUDE dependsOn generateTemplateFileList - archiveAppendix = 'test-fat' - - // include source files + archiveAppendix = 'test-shadow' from sourceSets.test.output + configurations = [project.configurations.testRuntimeClasspath] - // include all jars - from { - configurations.testimpl.collect { it.isDirectory() ? it : zipTree(it) } - } - + enableRelocation true + relocationPrefix 'us.kbase.auth2.shadow' + + mergeServiceFiles() + // Include text files from the "templates" directory from('templates') { into JAR_TEMPLATE_DIR } from("$buildDir/" + TEMPLATE_LIST_FILE_NAME) { into JAR_TEMPLATE_DIR } - - with jar } task generateManageAuthScript { @@ -217,7 +214,6 @@ dependencies { 'syslog4j-0.9.46' ) // needed for syslog4j - implementation 'net.java.dev.jna:jna:3.4.0' implementation 'joda-time:joda-time:2.3' // ### Test ### diff --git a/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java b/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java index 81e709c8..7c403bcc 100644 --- a/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java +++ b/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.io.PrintWriter; import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Path; @@ -15,6 +16,7 @@ import java.util.regex.Pattern; import org.ini4j.Ini; +import org.productivity.java.syslog4j.SyslogIF; import org.slf4j.LoggerFactory; import us.kbase.auth2.lib.identity.IdentityProviderConfig; @@ -25,6 +27,7 @@ import us.kbase.auth2.service.exceptions.AuthConfigurationException; import us.kbase.common.service.JsonServerSyslog; import us.kbase.common.service.JsonServerSyslog.RpcInfo; +import us.kbase.common.service.JsonServerSyslog.SyslogOutput; public class KBaseAuthConfig implements AuthStartupConfig { @@ -85,16 +88,8 @@ public KBaseAuthConfig() throws AuthConfigurationException { public KBaseAuthConfig(final Path filepath, final boolean nullLogger) throws AuthConfigurationException { final Map cfg = getConfig(filepath); - final String ln = getString(KEY_LOG_NAME, cfg); - if (nullLogger) { - logger = new NullLogger(); - } else { - logger = new JsonServerSysLogAutoLogger(new JsonServerSyslog( - ln == null ? DEFAULT_LOG_NAME : ln, - //TODO KBASECOMMON allow null for the fake config prop arg - "thisisafakekeythatshouldntexistihope", - JsonServerSyslog.LOG_LEVEL_INFO, true)); - } + final String logname = getString(KEY_LOG_NAME, cfg); + logger = nullLogger ? new NullLogger() : buildLogger(logname); try { isTestModeEnabled = TRUE.equals(getString(KEY_TEST_MODE_ENABLED, cfg)); templateDir = Paths.get(getString(KEY_TEMPLATE_DIR, cfg, true)); @@ -125,6 +120,44 @@ public KBaseAuthConfig(final Path filepath, final boolean nullLogger) } } + private SLF4JAutoLogger buildLogger(final String logname) { + // Warning - this code is tested manually. Ensure + // logs are making it to stdout after changing + // TODO LOGGING just remove JsonServerSyslog altogether + // and get rid of Syslog4j. Not sure how much work this'd be + JsonServerSyslog.setStaticUseSyslog(false); + final JsonServerSyslog jssl = new JsonServerSyslog( + logname == null ? DEFAULT_LOG_NAME : logname, + null, + JsonServerSyslog.LOG_LEVEL_INFO, + true + ); + jssl.changeOutput(new SyslogOutput() { + + @Override + public void logToSystem( + final SyslogIF log, + final int level, + final String message) { + System.out.println(String.format( + "[Auth2] Lvl: %s Message: %s", level, message)); + } + + @Override + public PrintWriter logToFile( + final File f, + final PrintWriter pw, + final int level, + final String message) { + System.out.println( + "log to file called - this is not supported and not expected"); + return null; + } + + }); + return new JsonServerSysLogAutoLogger(jssl); + } + private static final String INVALID_CHARS_REGEX = "[^A-Z-]+"; private static final Pattern INVALID_CHARS = Pattern.compile(INVALID_CHARS_REGEX); diff --git a/src/test/java/us/kbase/test/auth2/TestConfigurator.java b/src/test/java/us/kbase/test/auth2/TestConfigurator.java index 437ef331..245d4d62 100644 --- a/src/test/java/us/kbase/test/auth2/TestConfigurator.java +++ b/src/test/java/us/kbase/test/auth2/TestConfigurator.java @@ -67,11 +67,13 @@ private static class TestLogger implements SLF4JAutoLogger { private final JsonServerSyslog logger; public TestLogger() { + JsonServerSyslog.setStaticUseSyslog(false); logger = new JsonServerSyslog( "AuthTestLogger", - //TODO CODE update kbase-common and pass null instead - "thisisafakekeythatshouldntexistihope", - JsonServerSyslog.LOG_LEVEL_INFO, true); + null, + JsonServerSyslog.LOG_LEVEL_INFO, + true + ); logger.changeOutput(new SyslogOutput() { @Override From 7cfb38472d7517c1828030bfd0dd8158edb23f86 Mon Sep 17 00:00:00 2001 From: Gavin Date: Tue, 5 Mar 2024 10:32:57 -0800 Subject: [PATCH 2/2] Bump version, add release notes --- RELEASE_NOTES.md | 6 ++++++ src/main/java/us/kbase/auth2/Version.java | 2 +- .../kbase/test/auth2/service/common/ServiceCommonTest.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f1048bdc..450137d6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,11 @@ # Authentication Service MKII release notes +## 0.7.0 + +* BACKWARDS INCOMPATIBILITY - the auth server now logs to stdout vs. syslog. +* The the `fatTestJar` Gradle task has been replaced with the `shadowJar` task, which builds + a shadowed version of the test fat jar. + ## 0.6.1 * Gradle has replaced Ant as the build tool. As a consequence, all the built artifacts diff --git a/src/main/java/us/kbase/auth2/Version.java b/src/main/java/us/kbase/auth2/Version.java index ef29049f..b90353b9 100644 --- a/src/main/java/us/kbase/auth2/Version.java +++ b/src/main/java/us/kbase/auth2/Version.java @@ -5,6 +5,6 @@ public class Version { /** The version of the KBase Auth2 service. */ - public static final String VERSION = "0.6.1"; + public static final String VERSION = "0.7.0"; } diff --git a/src/test/java/us/kbase/test/auth2/service/common/ServiceCommonTest.java b/src/test/java/us/kbase/test/auth2/service/common/ServiceCommonTest.java index 9d8b9eb0..350e8987 100644 --- a/src/test/java/us/kbase/test/auth2/service/common/ServiceCommonTest.java +++ b/src/test/java/us/kbase/test/auth2/service/common/ServiceCommonTest.java @@ -47,7 +47,7 @@ public class ServiceCommonTest { public static final String SERVICE_NAME = "Authentication Service"; - public static final String SERVER_VER = "0.6.1"; + public static final String SERVER_VER = "0.7.0"; public static final String GIT_ERR = "Missing git commit file gitcommit, should be in us.kbase.auth2";