Merge pull request #67 from jkaninda/oauth-middleware
chore: add default configuration file verification before generating …
This commit is contained in:
@@ -11,8 +11,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/jkaninda/goma-gat
|
||||
|
||||
FROM alpine:3.20.3
|
||||
ENV TZ=UTC
|
||||
ARG WORKDIR="/config"
|
||||
ARG CERTSDIR="${WORKDIR}/certs"
|
||||
ARG WORKDIR="/etc/goma/"
|
||||
ARG appVersion=""
|
||||
ARG user="goma"
|
||||
ENV VERSION=${appVersion}
|
||||
@@ -20,8 +19,8 @@ LABEL author="Jonas Kaninda"
|
||||
LABEL version=${appVersion}
|
||||
LABEL github="github.com/jkaninda/goma-gateway"
|
||||
|
||||
RUN mkdir -p ${WORKDIR} ${CERTSDIR} && \
|
||||
chmod a+rw ${WORKDIR} ${CERTSDIR}
|
||||
RUN mkdir -p ${WORKDIR} && \
|
||||
chmod a+rw ${WORKDIR}
|
||||
COPY --from=build /app/goma /usr/local/bin/goma
|
||||
RUN chmod a+x /usr/local/bin/goma && \
|
||||
ln -s /usr/local/bin/goma /usr/bin/goma
|
||||
|
||||
@@ -39,7 +39,7 @@ func (GatewayServer) Config(configFile string) (*GatewayServer, error) {
|
||||
c := &GatewayConfig{}
|
||||
err = yaml.Unmarshal(buf, c)
|
||||
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{
|
||||
ctx: nil,
|
||||
@@ -48,6 +48,27 @@ func (GatewayServer) Config(configFile string) (*GatewayServer, error) {
|
||||
}, nil
|
||||
}
|
||||
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...")
|
||||
initConfig(ConfigFile)
|
||||
logger.Info("Server configuration file is available at %s", ConfigFile)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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 serverName = "Goma"
|
||||
const gatewayName = "Goma Gateway"
|
||||
|
||||
Reference in New Issue
Block a user