~skiqqy/apiCosmic

f0383ca4ea24112ff74654349fac6f197a9a442f — Stephen Cochrane 11 months ago b138eea
Solid Base

Tidied up pom, and added axes dep for security.

POM now contains the bare essentials for web app.
TODO:
    - Add lib cosmic
    - Implement @Resource config bean suppplier which uses comfy manager
      to fetch lib cosmic Module configs
      * This will allow cosmic API to detect any cosmic modules that
        get added at runtime, hence allowing us to choose at runtime
        which API's we want to expose
    - Implement 'jobs' endpoint
        - tl;dr: POST (possible long running) jobs, get results at a
          later time via a callback url
M pom.xml => pom.xml +22 -8
@@ 5,8 5,8 @@
    <modelVersion>4.0.0</modelVersion>

    <groupId>xyz.skiqqy.cosmic</groupId>
    <artifactId>apiCosmic</artifactId>
    <version>1.0.0</version>
    <artifactId>api</artifactId>
    <version>0.0.1</version>

    <repositories>
        <repository>


@@ 26,6 26,20 @@
    </properties>

    <dependencies>
        <!-- Skiqqy deps -->
        <dependency>
            <groupId>xyz.skiqqy.axes</groupId>
            <artifactId>axes</artifactId>
            <version>2.0.0-alpha</version>
        </dependency>

        <!-- Spring deps -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>3.0.3</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>


@@ 34,12 48,6 @@
        </dependency>

        <dependency>
            <groupId>xyz.skiqqy.jopts</groupId>
            <artifactId>jopts</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.19.0</version>


@@ 55,6 63,12 @@
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>3.0.3</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>

A scripts/init-test-container.sh => scripts/init-test-container.sh +51 -0
@@ 0,0 1,51 @@
#!/usr/bin/env bash

contd=$(command -v podman) # Use podman by default

if [ -z "$contd" ]
then
	contd=$(command -v docker)
	[ -z "$contd" ] && { echo 'Please install podman/docker'; return 1; }
fi

# If we cannot find a postgres img, then pull latest from dockerhub
if [ "$($contd images | grep -c postgres)" -eq 0 ]
then
    $contd pull docker.io/library/postgres:latest
fi

if ! command -v psql > /dev/null 2>&1
then
    echo "This script has a dependency on the tool 'psql' and it was not found."
    exit 1
fi

port=8199
pgpass=localhost:$port:test:test:test
export PGPASSFILE="$HOME/.pgpass"
if [ ! -f "$HOME/.pgpass" ]
then
    echo "$pgpass" > "$HOME/.pgpass"
elif ! grep "$pgpass" "$HOME/.pgpass" > /dev/null
then
    echo "$pgpass" >> "$HOME/.pgpass"
fi
chmod 600 "$HOME/.pgpass"

echo "Creating container, using $contd"
$contd stop xyz.skiqqy.axes 2> /dev/null
$contd run \
    -p "$port:5432" \
    --rm \
    --name xyz.skiqqy.axes \
    -e POSTGRES_USER=test \
    -e POSTGRES_PASSWORD=test \
    -d postgres

# Wait for the container to start
while ! psql -p 8199 -h localhost -c 'select 1;' test test > /dev/null 2>&1
do
    echo 'Waiting for container...'
    sleep 1
done
echo 'Container is ready!'

M src/main/java/xyz/skiqqy/cosmic/Main.java => src/main/java/xyz/skiqqy/cosmic/Main.java +6 -10
@@ 1,17 1,13 @@
package xyz.skiqqy.cosmic;

import xyz.skiqqy.jopts.JOpts;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan("xyz.skiqqy")
public class Main {
    private static final Logger log = LogManager.getLogger(Main.class);
    public static void main(String... argv) {
        JOpts jo = new JOpts(new String[][] {
                new String[] {"h,-help", "Shows this message"}
            },
            argv
        );
        if (jo.is("h")) System.out.print(jo.usage());
		SpringApplication.run(Main.class, argv);
    }
}

A src/main/resources/application.properties => src/main/resources/application.properties +1 -0
@@ 0,0 1,1 @@
debug=true

A src/main/resources/axes.properties => src/main/resources/axes.properties +7 -0
@@ 0,0 1,7 @@
hibernate.show.sql=true
hibernate.current.session.context.class=thread
jdbc.url=jdbc:postgresql://localhost:8199/test
jdbc.user=test
jdbc.pass=test
jdbc.max.idle=1
jdbc.initial.size=2

M src/main/resources/log4j2.properties => src/main/resources/log4j2.properties +2 -2
@@ 1,7 1,7 @@
# This is just a starter config, and should be changed where needed.
# Extra logging related to initialization of Log4j
# Set to debug or trace if log4j initialization is failing
status = warn
status = debug
# Name of the configuration
name = ConsoleLogConfigDemo



@@ 12,6 12,6 @@ appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t :: %c] - %m%n

# Root logger level
rootLogger.level = all
rootLogger.level = debug
# Root logger referring to console appender
rootLogger.appenderRef.stdout.ref = consoleLogger