Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config parameterization fix #317

Merged
merged 5 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions codegen-cli/src/main/java/com/networknt/codegen/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fizzed.rocker.runtime.RockerRuntime;
import com.jsoniter.JsonIterator;
import com.jsoniter.any.Any;
import com.networknt.codegen.rest.YAMLFileParameterizer;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Set;
import static java.io.File.separator;

/**
* Created by steve on 24/04/17.
Expand All @@ -40,10 +38,13 @@ public class Cli {

@Parameter(names={"--help", "-h"}, help = true)
private boolean help;

@Parameter(names={"--reload", "-r"}, description = "Specifies whether rocker hot-reloading should be enabled or not. Default is false."+
"If this is set to true, the file 'rocker-compiler.conf' must be available in the classpath.")
private boolean reload;
"If this is set to true, the file 'rocker-compiler.conf' must be available in the classpath.")
private boolean reload;

@Parameter(names={"--parameterize", "-p"}, description = "The location of configuration files that need to be parameterized.")
String parameterizationDir;

public static void main(String ... argv) throws Exception {
try {
Expand All @@ -65,7 +66,7 @@ public void run(JCommander jCommander) throws Exception {
jCommander.usage();
return;
}

RockerRuntime.getInstance().setReloading(reload);

System.out.printf("%s %s %s %s\n", framework, model, config, output);
Expand Down Expand Up @@ -101,6 +102,9 @@ public void run(JCommander jCommander) throws Exception {
anyConfig = JsonIterator.deserialize(Files.readAllBytes(Paths.get(config)));
}
}
if(parameterizationDir != null) {
YAMLFileParameterizer.rewriteAll(parameterizationDir, output + separator + YAMLFileParameterizer.DEFAULT_DEST_DIR, anyConfig.asMap().get(YAMLFileParameterizer.GENERATE_ENV_VARS).asMap());
}
generator.generate(output, anyModel, anyConfig);
System.out.println("A project has been generated successfully in " + output + " folder. Have fun!!!");
} else {
Expand All @@ -112,3 +116,4 @@ public void run(JCommander jCommander) throws Exception {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,19 @@ public void generate(final String targetPath, Object model, Any config) throws I
// exclusion list for Config module
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "config.yml", templates.rest.openapi.config.template(config));

transfer(targetPath, ("src.main.resources.config").replace(".", separator), "audit.yml", templates.rest.auditYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "body.yml", templates.rest.bodyYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "info.yml", templates.rest.infoYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "correlation.yml", templates.rest.correlationYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "metrics.yml", templates.rest.metricsYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "sanitizer.yml", templates.rest.sanitizerYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "traceability.yml", templates.rest.traceabilityYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "health.yml", templates.rest.healthYml.template());

// values.yml file, transfer only if explicitly set in the config.json
if (generateValuesYml) {
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "values.yml", templates.rest.openapi.values.template());
}

//always copy resources
YAMLFileParameterizer.copyResources(YAMLFileParameterizer.DEFAULT_RESOURCE_LOCATION, targetPath + separator + YAMLFileParameterizer.DEFAULT_DEST_DIR);

if (config.keys().contains(YAMLFileParameterizer.GENERATE_ENV_VARS)) {
YAMLFileParameterizer.rewriteAll(targetPath + separator + YAMLFileParameterizer.DEFAULT_DEST_DIR, config.get(YAMLFileParameterizer.GENERATE_ENV_VARS).asMap());
}
}
// routing handler
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "handler.yml",
Expand Down
3 changes: 0 additions & 3 deletions light-rest-4j/src/main/resources/handlerconfig/body.yml

This file was deleted.

20 changes: 0 additions & 20 deletions light-rest-4j/src/main/resources/handlerconfig/metrics.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
enabled: true

# Enable mask
mask: true
mask: ${audit.mask:true}

# Output response status code
statusCode: true
statusCode: ${audit.statusCode:true}

# Output response time
responseTime: true
responseTime: ${audit.responseTime:true}

# audit only on error responses; by default log for any return status code
# if true, audit at error level if status code >= 400
# log level is controlled by logLevel
auditOnError: false
auditOnError: ${audit.auditOnError:false}

# log level; by default set to info
logLevelIsError: false
logLevelIsError: ${audit.logLevelIsError:false}


# Output header elements. You can add more if you want.
Expand All @@ -42,7 +42,7 @@ audit:
# Client Id in scope/access token, this is optional
- scope_client_id

# Request endpoint uri@method.
# Request endpoint uri@*@*@method.
- endpoint

# Service ID assigned to the service, this is optional and must be set by the service in its implementation
Expand All @@ -53,3 +53,4 @@ audit:

# Response payload, this is optional and must be set by the service in its implementation
- response

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Enable body parse flag
enabled: ${body.enabled:true}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ tls:
# trust store contains certifictes that server needs. Enable if tls is used.
loadTrustStore: true
# trust store location can be specified here or system properties javax.net.ssl.trustStore and password javax.net.ssl.trustStorePassword
trustStore: client.truststore
trustStore: ${client.trustStore:client.truststore}
# key store contains client key and it should be loaded if two-way ssl is uesed.
loadKeyStore: false
# key store location
keyStore: client.keystore
keyStore: ${client.keyStore:server.keystore}
# settings for OAuth2 server communication
oauth:
# OAuth 2.0 token endpoint configuration
Expand All @@ -24,7 +24,7 @@ oauth:
# if scope token is not expired but in renew windown, we need slow retry delay.
earlyRefreshRetryDelay: 4000
# token server url. The default port number for token service is 6882.
server_url: https://localhost:6882
server_url: ${client.server_url:https://localhost:6882}
# token service unique id for OAuth 2.0 provider
serviceId: com.networknt.oauth2-token-1.0.0
# set to true if the oauth2 provider supports HTTP/2
Expand All @@ -34,7 +34,7 @@ oauth:
# token endpoint for authorization code grant
uri: "/oauth2/token"
# client_id for authorization code grant flow. client_secret is in secret.yml
client_id: f7d42348-c647-4efb-a52d-4c5787421e72
client_id: ${client.client_id:f7d42348-c647-4efb-a52d-4c5787421e72}
# the web server uri that will receive the redirected authorization code
redirect_uri: https://localhost:8080/authorization_code
# optional scope, default scope in the client registration will be used if not defined.
Expand All @@ -55,20 +55,20 @@ oauth:
# token endpoint for refresh token grant
uri: "/oauth2/token"
# client_id for refresh token grant flow. client_secret is in secret.yml
client_id: f7d42348-c647-4efb-a52d-4c5787421e72
client_id: ${client.client_id:f7d42348-c647-4efb-a52d-4c5787421e72}
# optional scope, default scope in the client registration will be used if not defined.
scope:
- petstore.r
- petstore.w
# light-oauth2 key distribution endpoint configuration
key:
# key distribution server url
server_url: https://localhost:6886
server_url: ${client.server_url:https://localhost:6882}
# the unique service id for key distribution service
serviceId: com.networknt.oauth2-key-1.0.0
# the path for the key distribution endpoint
uri: "/oauth2/key"
# client_id used to access key distribution service. It can be the same client_id with token service or not.
client_id: f7d42348-c647-4efb-a52d-4c5787421e72
client_id: ${client.client_id:f7d42348-c647-4efb-a52d-4c5787421e72}
# set to true if the oauth2 provider supports HTTP/2
enableHttp2: true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Correlation Id Handler Configuration
---
# If enabled is true, the handler will be injected into the request and response chain.
enabled: true
enabled: ${correlation.enabled:true}

# If set to true, it will auto-generate the correlationID if it is not provided in the request
autogenCorrelationID: true
autogenCorrelationID: ${correlation.autogenCorrelationID:true}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Server health endpoint that can output OK to indicate the server is alive

# true to enable this middleware handler.
enabled: true
enabled: ${health.enabled:true}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Server info endpoint that can output environment and component along with configuration

# Indicate if the server info is enable or not.
enableServerInfo: true
enableServerInfo: ${info.enableServerInfo:true}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# Metrics handler configuration

# If metrics handler is enabled or not
enabled: ${metrics.enabled:false}

# influxdb protocal can be http, https
influxdbProtocol: ${metrics.influxdbProtocol:http}
# influxdb hostname
influxdbHost: ${metrics.influxdbHost:localhost}
# influxdb port number
influxdbPort: ${metrics.influxdbPort:8086}
# influxdb database name
influxdbName: ${metrics.influxdbName:metrics}
# influxdb user
influxdbUser: ${metrics.influxdbUser:admin}
# influx db password
influxdbPass: ${metrics.influxdbPass:admin}
# report and reset metrics in minutes.
reportInMinutes: ${metrics.reportInMinutes:1}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# loaded for backward compatibility.
---
# Enable JWT verification flag.
enableVerifyJwt: false
enableVerifyJwt: ${openapi-security.enableVerifyJwt:false}

# Enable JWT scope verification. Only valid when enableVerifyJwt is true.
enableVerifyScope: true
enableVerifyScope: ${openapi-security.enableVerifyScope:true}

# User for test only. should be always be false on official environment.
enableMockJwt: false
enableMockJwt: ${openapi-security.enableMockJwt:false}

# JWT signature public certificates. kid and certificate path mappings.
jwt:
Expand All @@ -20,17 +20,17 @@ jwt:
clockSkewInSeconds: 60

# Enable or disable JWT token logging
logJwtToken: true
logJwtToken: ${openapi-security.logJwtToken:true}

# Enable or disable client_id, user_id and scope logging.
logClientUserScope: false
logClientUserScope: ${openapi-security.logClientUserScope:false}

# Enable JWT token cache to speed up verification. This will only verify expired time
# and skip the signature verification as it takes more CPU power and long time.
enableJwtCache: true
enableJwtCache: ${openapi-security.enableJwtCache:true}

# If you are using light-oauth2, then you don't need to have oauth subfolder for public
# key certificate to verify JWT token, the key will be retrieved from key endpoint once
# the first token is arrived. Default to false for dev environment without oauth2 server
# or official environment that use other OAuth 2.0 providers.
bootstrapFromKeyService: false
bootstrapFromKeyService: ${openapi-security.bootstrapFromKeyService:false}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# the generic validator.yml will be loaded as a fallback.
---
# Enable request validation. Response validation is not done on the server but client.
enabled: true
enabled: ${openapi-validator.enabled:true}
# Log error message if validation error occurs
logError: true
logError: ${openapi-validator.logError:true}
# Skip body validation set to true if used in light-router, light-proxy and light-spring-boot.
skipBodyValidation: false
skipBodyValidation: ${openapi-validator.skipBodyValidation:false}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Sanitize request for cross site scripting during runtime

# indicate if sanitizer is enabled or not
enabled: true
enabled: ${sanitizer.enabled:true}

# if it is enabled, does body need to be sanitized
sanitizeBody: true
sanitizeBody: ${sanitizer.sanitizeBody:true}

# if it is enabled, does header need to be sanitized
sanitizeHeader: false
sanitizeHeader: ${sanitizer.sanitizeHeader:false}
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@
# Sever section

# Key store password, the path of keystore is defined in server.yml
serverKeystorePass: password
serverKeystorePass: ${secret.serverKeystorePass:password}

# Key password, the key is in keystore
serverKeyPass: password
serverKeyPass: ${secret.serverKeyPass:password}

# Trust store password, the path of truststore is defined in server.yml
serverTruststorePass: password
serverTruststorePass: ${secret.serverTruststorePass:password}


# Client section

# Key store password, the path of keystore is defined in server.yml
clientKeystorePass: password
clientKeystorePass: ${secret.clientKeystorePass:password}

# Key password, the key is in keystore
clientKeyPass: password
clientKeyPass: ${secret.clientKeyPass:password}

# Trust store password, the path of truststore is defined in server.yml
clientTruststorePass: password
clientTruststorePass: ${secret.clientTruststorePass:password}

# Authorization code client secret for OAuth2 server
authorizationCodeClientSecret: f6h1FTI8Q3-7UScPZDzfXA
authorizationCodeClientSecret: ${secret.authorizationCodeClientSecret:f6h1FTI8Q3-7UScPZDzfXA}

# Client credentials client secret for OAuth2 server
clientCredentialsClientSecret: f6h1FTI8Q3-7UScPZDzfXA
clientCredentialsClientSecret: ${secret.clientCredentialsClientSecret:f6h1FTI8Q3-7UScPZDzfXA}

# Fresh token client secret for OAuth2 server
refreshTokenClientSecret: f6h1FTI8Q3-7UScPZDzfXA
refreshTokenClientSecret: ${secret.refreshTokenClientSecret:f6h1FTI8Q3-7UScPZDzfXA}

# Key distribution client secret for OAuth2 server
keyClientSecret: f6h1FTI8Q3-7UScPZDzfXA
keyClientSecret: ${secret.keyClientSecret:f6h1FTI8Q3-7UScPZDzfXA}

# Consul service registry and discovery

# Consul Token for service registry and discovery
# consulToken: the_one_ring

# EmailSender password
emailPassword: change-to-real-password
emailPassword: ${secret.emailPassword:change-to-real-password}
Loading