Merge pull request #67 from jkaninda/oauth-middleware

chore: add default configuration file verification before generating …
This commit is contained in:
2024-11-07 16:01:51 +01:00
committed by GitHub
3 changed files with 26 additions and 6 deletions

View File

@@ -11,8 +11,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/jkaninda/goma-gat
FROM alpine:3.20.3 FROM alpine:3.20.3
ENV TZ=UTC ENV TZ=UTC
ARG WORKDIR="/config" ARG WORKDIR="/etc/goma/"
ARG CERTSDIR="${WORKDIR}/certs"
ARG appVersion="" ARG appVersion=""
ARG user="goma" ARG user="goma"
ENV VERSION=${appVersion} ENV VERSION=${appVersion}
@@ -20,8 +19,8 @@ LABEL author="Jonas Kaninda"
LABEL version=${appVersion} LABEL version=${appVersion}
LABEL github="github.com/jkaninda/goma-gateway" LABEL github="github.com/jkaninda/goma-gateway"
RUN mkdir -p ${WORKDIR} ${CERTSDIR} && \ RUN mkdir -p ${WORKDIR} && \
chmod a+rw ${WORKDIR} ${CERTSDIR} chmod a+rw ${WORKDIR}
COPY --from=build /app/goma /usr/local/bin/goma COPY --from=build /app/goma /usr/local/bin/goma
RUN chmod a+x /usr/local/bin/goma && \ RUN chmod a+x /usr/local/bin/goma && \
ln -s /usr/local/bin/goma /usr/bin/goma ln -s /usr/local/bin/goma /usr/bin/goma

View File

@@ -39,7 +39,7 @@ func (GatewayServer) Config(configFile string) (*GatewayServer, error) {
c := &GatewayConfig{} c := &GatewayConfig{}
err = yaml.Unmarshal(buf, c) err = yaml.Unmarshal(buf, c)
if err != nil { if err != nil {
return nil, fmt.Errorf("error parsing yaml %q: %w", configFile, err) return nil, fmt.Errorf("parsing the configuration file %q: %w", configFile, err)
} }
return &GatewayServer{ return &GatewayServer{
ctx: nil, ctx: nil,
@@ -48,6 +48,27 @@ func (GatewayServer) Config(configFile string) (*GatewayServer, error) {
}, nil }, nil
} }
logger.Error("Configuration file not found: %v", configFile) logger.Error("Configuration file not found: %v", configFile)
// Check a default file
if util.FileExists(ConfigFile) {
buf, err := os.ReadFile(ConfigFile)
if err != nil {
return nil, err
}
logger.Info("Using configuration file: %s", ConfigFile)
util.SetEnv("GOMA_CONFIG_FILE", configFile)
c := &GatewayConfig{}
err = yaml.Unmarshal(buf, c)
if err != nil {
return nil, fmt.Errorf("parsing the configuration file %q: %w", ConfigFile, err)
}
return &GatewayServer{
ctx: nil,
gateway: c.GatewayConfig,
middlewares: c.Middlewares,
}, nil
}
logger.Info("Generating new configuration file...") logger.Info("Generating new configuration file...")
initConfig(ConfigFile) initConfig(ConfigFile)
logger.Info("Server configuration file is available at %s", ConfigFile) logger.Info("Server configuration file is available at %s", ConfigFile)

View File

@@ -1,6 +1,6 @@
package pkg package pkg
const ConfigFile = "/config/goma.yml" // Default configuration file const ConfigFile = "/etc/goma/goma.yml" // Default configuration file
const accessControlAllowOrigin = "Access-Control-Allow-Origin" // Cors const accessControlAllowOrigin = "Access-Control-Allow-Origin" // Cors
const serverName = "Goma" const serverName = "Goma"
const gatewayName = "Goma Gateway" const gatewayName = "Goma Gateway"