forked from loafle/openapi-generator-original
ApacheConfGen for HTTP Basic Authentication Proposed implementation (#5800)
* - Added Restbed Generator * - Added Json processing functions to model - Removed unnused code from restbed codegen class - Added response header processing to api template * Changed it to respect alphabetical order * Made the string joining java 7 compatible * Added samples * Auto stash before merge of "master" and "origin/master" * added missing apache2 config gen in services file * - Added new Config Type - Added Samples - Added sample generating scripts - Renamed Apache2Confgen to Apache2ConfigCodegen * - Added Samples - Added new config type - Added sample generating scripts - Renamed Apache2Confgen to Apache2ConfigCodegen
This commit is contained in:
parent
91f470e41f
commit
3c0623cce1
31
bin/apache2-petstore-config.sh
Normal file
31
bin/apache2-petstore-config.sh
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SCRIPT="$0"
|
||||||
|
|
||||||
|
while [ -h "$SCRIPT" ] ; do
|
||||||
|
ls=`ls -ld "$SCRIPT"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
SCRIPT="$link"
|
||||||
|
else
|
||||||
|
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "${APP_DIR}" ]; then
|
||||||
|
APP_DIR=`dirname "$SCRIPT"`/..
|
||||||
|
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||||
|
fi
|
||||||
|
|
||||||
|
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||||
|
|
||||||
|
if [ ! -f "$executable" ]
|
||||||
|
then
|
||||||
|
mvn clean package
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if you've executed sbt assembly previously it will use that instead.
|
||||||
|
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
|
ags="$@ generate -l apache2 -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -o samples/config/petstore/apache2"
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
10
bin/windows/apache2-petstore-config.bat
Normal file
10
bin/windows/apache2-petstore-config.bat
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||||
|
|
||||||
|
If Not Exist %executable% (
|
||||||
|
mvn clean package
|
||||||
|
)
|
||||||
|
|
||||||
|
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||||
|
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l apache2 -o samples\config\petstore\apache2\
|
||||||
|
|
||||||
|
java %JAVA_OPTS% -jar %executable% %ags%
|
@ -7,7 +7,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public enum CodegenType {
|
public enum CodegenType {
|
||||||
CLIENT, SERVER, DOCUMENTATION, OTHER;
|
CLIENT, SERVER, DOCUMENTATION, CONFIG, OTHER;
|
||||||
|
|
||||||
private static Map<String, CodegenType> names = new HashMap<String, CodegenType>();
|
private static Map<String, CodegenType> names = new HashMap<String, CodegenType>();
|
||||||
|
|
||||||
|
@ -0,0 +1,106 @@
|
|||||||
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import io.swagger.codegen.CliOption;
|
||||||
|
import io.swagger.codegen.CodegenConfig;
|
||||||
|
import io.swagger.codegen.CodegenConstants;
|
||||||
|
import io.swagger.codegen.CodegenOperation;
|
||||||
|
import io.swagger.codegen.CodegenType;
|
||||||
|
import io.swagger.codegen.DefaultCodegen;
|
||||||
|
import io.swagger.codegen.SupportingFile;
|
||||||
|
|
||||||
|
public class Apache2ConfigCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
public static final String USER_INFO_PATH = "userInfoPath";
|
||||||
|
protected String userInfoPath = "/var/www/html/";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "apache2";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates an Apache2 Config file with the permissions";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Apache2ConfigCodegen() {
|
||||||
|
super();
|
||||||
|
apiTemplateFiles.put("apache-config.mustache", ".conf");
|
||||||
|
|
||||||
|
embeddedTemplateDir = templateDir = "apache2";
|
||||||
|
|
||||||
|
cliOptions.add(new CliOption(USER_INFO_PATH, "Path to the user and group files"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processOpts() {
|
||||||
|
if (additionalProperties.containsKey(USER_INFO_PATH)) {
|
||||||
|
userInfoPath = additionalProperties.get(USER_INFO_PATH).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeQuotationMark(String input) {
|
||||||
|
// remove " to avoid code injection
|
||||||
|
return input.replace("\"", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeUnsafeCharacters(String input) {
|
||||||
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||||
|
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||||
|
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||||
|
List<CodegenOperation> newOpList = new ArrayList<CodegenOperation>();
|
||||||
|
for (CodegenOperation op : operationList) {
|
||||||
|
String path = new String(op.path);
|
||||||
|
|
||||||
|
String[] items = path.split("/", -1);
|
||||||
|
List<String> splitPath = new ArrayList<String>();
|
||||||
|
for (String item: items) {
|
||||||
|
if (item.matches("^\\{(.*)\\}$")) {
|
||||||
|
item = "*";
|
||||||
|
}
|
||||||
|
splitPath.add(item);
|
||||||
|
}
|
||||||
|
op.path = String.join("/", splitPath);
|
||||||
|
op.vendorExtensions.put("x-codegen-userInfoPath", userInfoPath);
|
||||||
|
boolean foundInNewList = false;
|
||||||
|
for (CodegenOperation op1 : newOpList) {
|
||||||
|
if (!foundInNewList) {
|
||||||
|
if (op1.path.equals(op.path)) {
|
||||||
|
foundInNewList = true;
|
||||||
|
List<CodegenOperation> currentOtherMethodList = (List<CodegenOperation>) op1.vendorExtensions.get("x-codegen-otherMethods");
|
||||||
|
if (currentOtherMethodList == null) {
|
||||||
|
currentOtherMethodList = new ArrayList<CodegenOperation>();
|
||||||
|
}
|
||||||
|
op.operationIdCamelCase = op1.operationIdCamelCase;
|
||||||
|
currentOtherMethodList.add(op);
|
||||||
|
op1.vendorExtensions.put("x-codegen-otherMethods", currentOtherMethodList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundInNewList) {
|
||||||
|
newOpList.add(op);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
operations.put("operation", newOpList);
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
io.swagger.codegen.languages.AkkaScalaClientCodegen
|
io.swagger.codegen.languages.AkkaScalaClientCodegen
|
||||||
io.swagger.codegen.languages.AndroidClientCodegen
|
io.swagger.codegen.languages.AndroidClientCodegen
|
||||||
|
io.swagger.codegen.languages.Apache2ConfigCodegen
|
||||||
io.swagger.codegen.languages.ApexClientCodegen
|
io.swagger.codegen.languages.ApexClientCodegen
|
||||||
io.swagger.codegen.languages.AspNet5ServerCodegen
|
io.swagger.codegen.languages.AspNet5ServerCodegen
|
||||||
io.swagger.codegen.languages.AspNetCoreServerCodegen
|
io.swagger.codegen.languages.AspNetCoreServerCodegen
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
{{#operations}}
|
||||||
|
{{#operation}}
|
||||||
|
<Location "{{basePathWithoutHost}}{{path}}">
|
||||||
|
{{>authConf}}
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
{{#hasAuthMethods}}
|
||||||
|
{{#authMethods}}
|
||||||
|
{{#isOAuth}}
|
||||||
|
<Limit {{httpMethod}}>
|
||||||
|
{{#scopes}}
|
||||||
|
Require group {{scope}}
|
||||||
|
{{/scopes}}
|
||||||
|
</Limit>
|
||||||
|
{{/isOAuth}}
|
||||||
|
{{/authMethods}}
|
||||||
|
{{/hasAuthMethods}}
|
||||||
|
{{^hasAuthMethods}}
|
||||||
|
<Limit {{httpMethod}}>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
{{/hasAuthMethods}}
|
||||||
|
{{#vendorExtensions.x-codegen-otherMethods}}
|
||||||
|
{{#hasAuthMethods}}
|
||||||
|
{{#authMethods}}
|
||||||
|
{{#isOAuth}}
|
||||||
|
<Limit {{httpMethod}}>
|
||||||
|
{{#scopes}}
|
||||||
|
Require group {{scope}}
|
||||||
|
{{/scopes}}
|
||||||
|
</Limit>
|
||||||
|
{{/isOAuth}}
|
||||||
|
{{/authMethods}}
|
||||||
|
{{/hasAuthMethods}}
|
||||||
|
{{^hasAuthMethods}}
|
||||||
|
<Limit {{httpMethod}}>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
{{/hasAuthMethods}}
|
||||||
|
{{/vendorExtensions.x-codegen-otherMethods}}
|
||||||
|
</Location>
|
||||||
|
{{/operation}}
|
||||||
|
{{/operations}}
|
@ -0,0 +1,5 @@
|
|||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "{{vendorExtensions.x-codegen-userInfoPath}}htpwd"
|
||||||
|
AuthGroupFile "{{vendorExtensions.x-codegen-userInfoPath}}groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
23
samples/config/petstore/apache2/.swagger-codegen-ignore
Normal file
23
samples/config/petstore/apache2/.swagger-codegen-ignore
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Swagger Codegen Ignore
|
||||||
|
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
1
samples/config/petstore/apache2/.swagger-codegen/VERSION
Normal file
1
samples/config/petstore/apache2/.swagger-codegen/VERSION
Normal file
@ -0,0 +1 @@
|
|||||||
|
2.2.3-SNAPSHOT
|
78
samples/config/petstore/apache2/PetApi.conf
Normal file
78
samples/config/petstore/apache2/PetApi.conf
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<Location "/v2/pet">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit POST>
|
||||||
|
Require group write:pets
|
||||||
|
Require group read:pets
|
||||||
|
</Limit>
|
||||||
|
<Limit PUT>
|
||||||
|
Require group write:pets
|
||||||
|
Require group read:pets
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/pet/*">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit DELETE>
|
||||||
|
Require group write:pets
|
||||||
|
Require group read:pets
|
||||||
|
</Limit>
|
||||||
|
<Limit POST>
|
||||||
|
Require group write:pets
|
||||||
|
Require group read:pets
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/pet/findByStatus">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit GET>
|
||||||
|
Require group write:pets
|
||||||
|
Require group read:pets
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/pet/findByTags">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit GET>
|
||||||
|
Require group write:pets
|
||||||
|
Require group read:pets
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/pet/*/uploadImage">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit POST>
|
||||||
|
Require group write:pets
|
||||||
|
Require group read:pets
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
39
samples/config/petstore/apache2/StoreApi.conf
Normal file
39
samples/config/petstore/apache2/StoreApi.conf
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<Location "/v2/store/order/*">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
<Limit GET>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/store/inventory">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/store/order">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit POST>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
84
samples/config/petstore/apache2/UserApi.conf
Normal file
84
samples/config/petstore/apache2/UserApi.conf
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<Location "/v2/user">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit POST>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/user/createWithArray">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit POST>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/user/createWithList">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit POST>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/user/*">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
<Limit GET>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
<Limit PUT>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/user/login">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit GET>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
||||||
|
<Location "/v2/user/logout">
|
||||||
|
AuthBasicProvider file
|
||||||
|
AuthUserFile "/var/www/html/htpwd"
|
||||||
|
AuthGroupFile "/var/www/html/groups"
|
||||||
|
AuthType basic
|
||||||
|
AuthName "api"
|
||||||
|
<LimitExcept GET POST PUT DELETE>
|
||||||
|
Require valid-user
|
||||||
|
</LimitExcept>
|
||||||
|
<Limit GET>
|
||||||
|
Require valid-user
|
||||||
|
</Limit>
|
||||||
|
</Location>
|
Loading…
x
Reference in New Issue
Block a user