├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── NOTICE ├── README.md ├── ROADMAP.md ├── apiman ├── apiman.bat ├── build.gradle ├── examples ├── declarative │ ├── backend-requires-http-auth.json │ ├── backend-requires-http-auth.yml │ ├── common-api-config.yml │ ├── shared-policies.json │ ├── shared-policies.yml │ ├── shared-properties.yml │ ├── simple.json │ └── simple.yml └── policies │ └── caching-policy-config.json ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── java │ └── io │ │ └── apiman │ │ └── cli │ │ ├── Cli.java │ │ ├── GatewayCli.java │ │ ├── ManagerCli.java │ │ ├── annotations │ │ └── CommandAvailableSince.java │ │ ├── command │ │ ├── api │ │ │ └── model │ │ │ │ ├── Api.java │ │ │ │ ├── ApiConfig.java │ │ │ │ ├── ApiGateway.java │ │ │ │ ├── ApiPolicy.java │ │ │ │ ├── ApiVersion.java │ │ │ │ ├── EndpointProperties.java │ │ │ │ └── ServiceConfig.java │ │ ├── core │ │ │ ├── AbstractCommand.java │ │ │ ├── AbstractFinalCommand.java │ │ │ └── Command.java │ │ ├── declarative │ │ │ ├── DeclarativeUtil.java │ │ │ ├── command │ │ │ │ └── AbstractApplyCommand.java │ │ │ └── model │ │ │ │ ├── BaseDeclaration.java │ │ │ │ ├── DeclarativeApi.java │ │ │ │ ├── DeclarativeApiConfig.java │ │ │ │ ├── DeclarativeApiDefinition.java │ │ │ │ ├── DeclarativeEndpointSecurity.java │ │ │ │ ├── DeclarativeGateway.java │ │ │ │ ├── DeclarativeOrg.java │ │ │ │ ├── DeclarativeOrgCommon.java │ │ │ │ ├── DeclarativeOrgCommonPolicies.java │ │ │ │ ├── DeclarativePolicy.java │ │ │ │ ├── DeclarativeSystem.java │ │ │ │ └── SharedItems.java │ │ ├── gateway │ │ │ └── model │ │ │ │ ├── Gateway.java │ │ │ │ ├── GatewayConfig.java │ │ │ │ ├── GatewayTestResponse.java │ │ │ │ └── GatewayType.java │ │ ├── org │ │ │ └── model │ │ │ │ └── Org.java │ │ └── plugin │ │ │ └── model │ │ │ └── Plugin.java │ │ ├── exception │ │ ├── CommandException.java │ │ ├── DeclarativeException.java │ │ └── ExitWithCodeException.java │ │ ├── gatewayapi │ │ ├── GatewayApi.java │ │ ├── GatewayCommon.java │ │ ├── GatewayHelper.java │ │ ├── command │ │ │ ├── GatewayOrgCommand.java │ │ │ ├── GatewayStatusCommand.java │ │ │ ├── ListOrgCommand.java │ │ │ ├── api │ │ │ │ ├── ApiEndpointCommand.java │ │ │ │ ├── GatewayApiCommand.java │ │ │ │ ├── ListApiCommand.java │ │ │ │ └── RetireApiCommand.java │ │ │ ├── client │ │ │ │ ├── ClientEndpointCommand.java │ │ │ │ ├── GatewayClientCommand.java │ │ │ │ ├── ListClientCommand.java │ │ │ │ └── UnregisterClientCommand.java │ │ │ ├── common │ │ │ │ └── AbstractGatewayCommand.java │ │ │ ├── factory │ │ │ │ ├── GatewayApiFactory.java │ │ │ │ └── GatewayApiService.java │ │ │ └── generate │ │ │ │ ├── Generate.java │ │ │ │ └── GenerateHeadless.java │ │ ├── declarative │ │ │ └── command │ │ │ │ └── GatewayApplyCommand.java │ │ └── model │ │ │ └── GatewayApiDataModel.java │ │ ├── managerapi │ │ ├── ManagerCommon.java │ │ ├── command │ │ │ ├── api │ │ │ │ ├── ApiMixin.java │ │ │ │ ├── Version11xServerApi.java │ │ │ │ ├── Version12xServerApi.java │ │ │ │ ├── VersionAgnosticApi.java │ │ │ │ ├── command │ │ │ │ │ ├── AbstractApiCommand.java │ │ │ │ │ ├── AbstractManagerCommand.java │ │ │ │ │ ├── ApiCommand.java │ │ │ │ │ ├── ApiCreateCommand.java │ │ │ │ │ ├── ApiDefinitionCommand.java │ │ │ │ │ ├── ApiListCommand.java │ │ │ │ │ ├── ApiPolicyAddCommand.java │ │ │ │ │ ├── ApiPolicyCommand.java │ │ │ │ │ └── ApiPublishCommand.java │ │ │ │ └── factory │ │ │ │ │ ├── Version11XManagementApiFactoryImpl.java │ │ │ │ │ └── Version12XManagementApiFactoryImpl.java │ │ │ ├── common │ │ │ │ ├── ActionApi.java │ │ │ │ ├── command │ │ │ │ │ ├── AbstractManagerModelCommand.java │ │ │ │ │ ├── ModelAction.java │ │ │ │ │ ├── ModelCreateCommand.java │ │ │ │ │ ├── ModelListCommand.java │ │ │ │ │ └── ModelShowCommand.java │ │ │ │ ├── model │ │ │ │ │ ├── ManagementApiVersion.java │ │ │ │ │ └── ServerAction.java │ │ │ │ └── util │ │ │ │ │ └── ServerActionUtil.java │ │ │ ├── gateway │ │ │ │ ├── GatewayApi.java │ │ │ │ ├── GatewayMixin.java │ │ │ │ └── command │ │ │ │ │ ├── AbstractGatewayCreateCommand.java │ │ │ │ │ ├── GatewayCommand.java │ │ │ │ │ ├── GatewayCreateCommand.java │ │ │ │ │ ├── GatewayListCommand.java │ │ │ │ │ ├── GatewayShowCommand.java │ │ │ │ │ └── GatewayTestCommand.java │ │ │ ├── org │ │ │ │ ├── OrgApi.java │ │ │ │ ├── OrgMixin.java │ │ │ │ └── command │ │ │ │ │ ├── OrgCommand.java │ │ │ │ │ ├── OrgCreateCommand.java │ │ │ │ │ └── OrgShowCommand.java │ │ │ └── plugin │ │ │ │ ├── PluginApi.java │ │ │ │ ├── PluginMixin.java │ │ │ │ └── command │ │ │ │ ├── PluginAddCommand.java │ │ │ │ ├── PluginCommand.java │ │ │ │ ├── PluginListCommand.java │ │ │ │ └── PluginShowCommand.java │ │ ├── declarative │ │ │ └── command │ │ │ │ └── ManagerApplyCommand.java │ │ ├── management │ │ │ ├── ManagementApiFactoryModule.java │ │ │ ├── ManagementApiUtil.java │ │ │ ├── api │ │ │ │ └── StatusApi.java │ │ │ ├── binding │ │ │ │ ├── ManagementApiBinding.java │ │ │ │ ├── ManagementApiBindingImpl.java │ │ │ │ └── ManagementApiBindings.java │ │ │ └── factory │ │ │ │ ├── AbstractManagementApiFactory.java │ │ │ │ ├── ManagementApiFactory.java │ │ │ │ └── SimpleManagementApiFactoryImpl.java │ │ └── service │ │ │ ├── ApiService.java │ │ │ ├── ApiServiceImpl.java │ │ │ ├── DeclarativeService.java │ │ │ ├── DeclarativeServiceImpl.java │ │ │ ├── ManagementApiService.java │ │ │ ├── ManagementApiServiceImpl.java │ │ │ ├── PluginService.java │ │ │ ├── PluginServiceImpl.java │ │ │ ├── PolicyService.java │ │ │ ├── PolicyServiceImpl.java │ │ │ └── ServiceModule.java │ │ ├── services │ │ └── WaitService.java │ │ └── util │ │ ├── AuthUtil.java │ │ ├── BeanUtil.java │ │ ├── Functions.java │ │ ├── InjectionUtil.java │ │ ├── LogUtil.java │ │ ├── MappingUtil.java │ │ └── PolicyResolver.java └── resources │ └── log4j2.xml └── test ├── java └── io │ └── apiman │ └── cli │ ├── ExceptionTest.java │ ├── command │ ├── GatewayDeclarativeTest.java │ └── declarative │ │ └── DeclarativeUtilTest.java │ ├── common │ ├── BaseIntegrationTest.java │ ├── BaseTest.java │ ├── IntegrationTest.java │ └── WaitForHttp.java │ ├── gatewayapi │ ├── GatewayBaseTest.java │ └── command │ │ ├── api │ │ └── ApiTest.java │ │ ├── apply │ │ └── ApplyTest.java │ │ └── generate │ │ └── GenerateHeadlessTest.java │ ├── managerapi │ ├── command │ │ ├── api │ │ │ └── ApiTest.java │ │ ├── declarative │ │ │ └── command │ │ │ │ └── ManagerDeclarativeTest.java │ │ ├── gateway │ │ │ └── GatewayTest.java │ │ ├── org │ │ │ └── OrgTest.java │ │ └── plugin │ │ │ └── PluginTest.java │ └── management │ │ └── ManagementApiUtilTest.java │ ├── service │ └── ManagementApiServiceImplTest.java │ ├── support │ └── TestModel.java │ └── util │ ├── BeanUtilTest.java │ ├── MappingUtilTest.java │ └── PluginRegistryTest.java └── resources ├── common-api-config.yml ├── gateway ├── command │ ├── api │ │ ├── basic-expectation.json │ │ └── basic.yml │ └── apply │ │ ├── basic-expectation.json │ │ ├── basic.yml │ │ ├── multi-version-expectation-1.json │ │ ├── multi-version-expectation-2.json │ │ └── multi-version.yml ├── common-api-config-expectation.json ├── generateHeadless │ ├── expected-headless_plugin-and-builtin-policies.json │ ├── expected-multiple-gateways-2.json │ ├── expected-multiple-gateways.json │ ├── plugin-and-builtin-policies.yml │ ├── plugin-and-builtin-policies_multiple-gateways.yml │ ├── transform-name.json │ └── transform-name.yml ├── multiple-versions-expectation-1.json ├── multiple-versions-expectation-2.json ├── plugin-and-builtin-policies-expectation.json ├── plugin-and-builtin-policies.yml ├── shared-policies-expectation-1.json └── shared-policies-expectation-2.json ├── multiple-versions.yml ├── placeholder-test.properties ├── placeholder-test.xml ├── shared-policies.json ├── shared-policies.yml ├── shared-properties.yml ├── simple-full.json ├── simple-full.yml ├── simple-no-plugin.yml ├── simple-placeholders.yml └── simple-plugin.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .idea/ 3 | build/ 4 | *.iml 5 | classes 6 | /bin/ 7 | .settings 8 | .classpath 9 | .project 10 | /out/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: java 3 | jdk: 4 | - openjdk8 5 | services: 6 | - docker 7 | before_install: 8 | - docker pull apiman/on-wildfly10:1.4.3.Final 9 | script: 10 | - docker run -d -p 8080:8080 apiman/on-wildfly10:1.4.3.Final 11 | - ./gradlew test -PintegrationTest --info --stacktrace 12 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Pete Cornish 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | Roadmap 2 | ======= 3 | 4 | * Support reading management API configuration from environment variables 5 | * Better support for non-public APIs 6 | * Support deletion 7 | * Support for retiring published APIs 8 | * Option to skip or fail for existing items in declarative mode 9 | * Docs - split examples into separate file 10 | * Docs - split detailed API usage into separate file 11 | * Docs - simplify README examples 12 | 13 | If you have other suggestions, please raise an issue! 14 | -------------------------------------------------------------------------------- /apiman: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | CLI_JAR="./build/libs/apiman-cli.jar" 6 | 7 | if [[ ! -f ${CLI_JAR} ]]; then 8 | chmod u+x ./gradlew 9 | ./gradlew clean shadowJar 10 | clear 11 | fi 12 | 13 | # look for -i parameter indicating STDIN 14 | USE_STDIN=0 15 | for ARG in $@; do 16 | if [[ "-i" == "${ARG}" ]]; then 17 | USE_STDIN=1 18 | break 19 | fi 20 | done 21 | 22 | # pipe STDIN into command 23 | if [[ 1 == ${USE_STDIN} ]]; then 24 | read STDIN 25 | echo ${STDIN} | java -jar ${CLI_JAR} "$@" 26 | 27 | else 28 | java -jar ${CLI_JAR} "$@" 29 | fi 30 | -------------------------------------------------------------------------------- /apiman.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | SET CLI_JAR=./build/libs/apiman-cli.jar 4 | 5 | If Not Exist %CLI_JAR% ( 6 | call ./gradlew.bat clean shadowJar 7 | cls 8 | ) 9 | 10 | java -jar %CLI_JAR% %* 11 | -------------------------------------------------------------------------------- /examples/declarative/backend-requires-http-auth.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "gateways": [ 4 | { 5 | "name": "test-gw", 6 | "description": "Test Gateway", 7 | "type": "REST", 8 | "config": { 9 | "endpoint": "http://localhost:8080/apiman-gateway-api", 10 | "username": "apimanager", 11 | "password": "apiman123!" 12 | } 13 | } 14 | ], 15 | "plugins": [ 16 | { 17 | "groupId": "io.apiman.plugins", 18 | "artifactId": "apiman-plugins-test-policy", 19 | "version": "1.4.3.Final" 20 | } 21 | ] 22 | }, 23 | "org": { 24 | "name": "test", 25 | "description": "Test organisation", 26 | "apis": [ 27 | { 28 | "name": "example", 29 | "description": "Example API", 30 | "version": "1.0", 31 | "published": true, 32 | "config": { 33 | "endpoint": "http://example.com", 34 | "endpointType": "rest", 35 | "public": true, 36 | "gateway": "test-gw", 37 | "security": { 38 | "authorizationType": "basic", 39 | "username": "user", 40 | "password": "Password123" 41 | } 42 | }, 43 | "policies": [ 44 | { 45 | "name": "CachingPolicy", 46 | "config": { 47 | "ttl": 60 48 | } 49 | } 50 | ] 51 | } 52 | ] 53 | } 54 | } -------------------------------------------------------------------------------- /examples/declarative/backend-requires-http-auth.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman example 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | plugins: 13 | - groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "test" 18 | description: "Test organisation" 19 | apis: 20 | - name: "example" 21 | description: "Example API" 22 | version: "1.0" 23 | published: true 24 | config: 25 | endpoint: "http://example.com" 26 | endpointType: "rest" 27 | security: 28 | authorizationType: "basic" 29 | username: "user" 30 | password: "Password123" 31 | public: true 32 | gateway: "test-gw" 33 | policies: 34 | - name: "CachingPolicy" 35 | config: 36 | ttl: 60 37 | -------------------------------------------------------------------------------- /examples/declarative/common-api-config.yml: -------------------------------------------------------------------------------- 1 | # Common configuration and policies across all APIs. 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | plugins: 13 | - groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | - name: "log-policy" 17 | groupId: "io.apiman.plugins" 18 | artifactId: "apiman-plugins-log-policy" 19 | version: "1.4.3.Final" 20 | shared: 21 | policies: 22 | - $id: "alwaysFirstPolicy" 23 | plugin: "log-policy" 24 | name: "log-headers-policy" 25 | config: 26 | direction: "both" 27 | - $id: "alwaysLastPolicy" 28 | name: "CachingPolicy" 29 | config: 30 | ttl: 60 31 | org: 32 | name: "test" 33 | description: "Test organisation" 34 | # Configuration and policies in the common org section are applied to each API. 35 | common: 36 | # Common configuration is overridden by API specific values. 37 | config: 38 | endpointType: "rest" 39 | public: true 40 | gateway: "test-gw" 41 | # Common policies are injected at either the start or the end of the policy chain for each API. 42 | policies: 43 | first: 44 | - "alwaysFirstPolicy" 45 | last: 46 | - "alwaysLastPolicy" 47 | apis: 48 | - name: "example" 49 | description: "Example API" 50 | version: "1.0" 51 | published: true 52 | config: 53 | endpoint: "http://example.com" 54 | # policies from the common block will be appended/prepended to this list 55 | policies: [] 56 | -------------------------------------------------------------------------------- /examples/declarative/shared-policies.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "gateways": [ 4 | { 5 | "name": "test-gw", 6 | "description": "Test Gateway", 7 | "type": "REST", 8 | "config": { 9 | "endpoint": "http://localhost:8080/apiman-gateway-api", 10 | "username": "apimanager", 11 | "password": "apiman123!" 12 | } 13 | } 14 | ], 15 | "plugins": [ 16 | { 17 | "groupId": "io.apiman.plugins", 18 | "artifactId": "apiman-plugins-test-policy", 19 | "version": "1.4.3.Final" 20 | } 21 | ] 22 | }, 23 | "shared": { 24 | "policies": [ 25 | { 26 | "$id": "sharedPolicy", 27 | "name": "CachingPolicy", 28 | "config": { 29 | "ttl": 60 30 | } 31 | } 32 | ] 33 | }, 34 | "org": { 35 | "name": "test", 36 | "description": "Test organisation", 37 | "apis": [ 38 | { 39 | "name": "example1", 40 | "description": "Example API 1", 41 | "version": "1.0", 42 | "published": true, 43 | "config": { 44 | "endpoint": "http://example.com", 45 | "endpointType": "rest", 46 | "public": true, 47 | "gateway": "test-gw" 48 | }, 49 | "policies": [ 50 | "sharedPolicy" 51 | ] 52 | }, 53 | { 54 | "name": "example2", 55 | "description": "Example API 2", 56 | "version": "1.0", 57 | "published": true, 58 | "config": { 59 | "endpoint": "http://example.com", 60 | "endpointType": "rest", 61 | "public": true, 62 | "gateway": "test-gw" 63 | }, 64 | "policies": [ 65 | "sharedPolicy" 66 | ] 67 | } 68 | ] 69 | } 70 | } -------------------------------------------------------------------------------- /examples/declarative/shared-policies.yml: -------------------------------------------------------------------------------- 1 | # Shared policies example 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | plugins: 13 | - groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | shared: 17 | policies: 18 | - $id: "sharedPolicy" 19 | name: "CachingPolicy" 20 | config: 21 | ttl: 60 22 | org: 23 | name: "test" 24 | description: "Test organisation" 25 | apis: 26 | - name: "example1" 27 | description: "Example API 1" 28 | version: "1.0" 29 | published: true 30 | config: 31 | endpoint: "http://example.com" 32 | endpointType: "rest" 33 | public: true 34 | gateway: "test-gw" 35 | policies: 36 | - "sharedPolicy" 37 | - name: "example2" 38 | description: "Example API 2" 39 | version: "1.0" 40 | published: true 41 | config: 42 | endpoint: "http://example.com" 43 | endpointType: "rest" 44 | public: true 45 | gateway: "test-gw" 46 | policies: 47 | - "sharedPolicy" 48 | -------------------------------------------------------------------------------- /examples/declarative/shared-properties.yml: -------------------------------------------------------------------------------- 1 | # Shared properties example 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | shared: 13 | properties: 14 | commonApiEndpoint: "http://example.com" 15 | org: 16 | name: "test" 17 | description: "Test organisation" 18 | apis: 19 | - name: "example1" 20 | description: "Example API 1" 21 | version: "1.0" 22 | published: true 23 | config: 24 | endpoint: "${commonApiEndpoint}" 25 | endpointType: "rest" 26 | public: true 27 | gateway: "test-gw" 28 | - name: "example2" 29 | description: "Example API 2" 30 | version: "1.0" 31 | published: true 32 | config: 33 | endpoint: "${commonApiEndpoint}" 34 | endpointType: "rest" 35 | public: true 36 | gateway: "test-gw" 37 | -------------------------------------------------------------------------------- /examples/declarative/simple.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "gateways": [ 4 | { 5 | "name": "test-gw", 6 | "description": "Test Gateway", 7 | "type": "REST", 8 | "config": { 9 | "endpoint": "http://localhost:8080/apiman-gateway-api", 10 | "username": "apimanager", 11 | "password": "apiman123!" 12 | } 13 | } 14 | ], 15 | "plugins": [ 16 | { 17 | "groupId": "io.apiman.plugins", 18 | "artifactId": "apiman-plugins-test-policy", 19 | "version": "1.4.3.Final" 20 | } 21 | ] 22 | }, 23 | "org": { 24 | "name": "test", 25 | "description": "Test organisation", 26 | "apis": [ 27 | { 28 | "name": "example", 29 | "description": "Example API", 30 | "version": "1.0", 31 | "published": true, 32 | "config": { 33 | "endpoint": "http://example.com", 34 | "endpointType": "rest", 35 | "public": true, 36 | "gateway": "test-gw" 37 | }, 38 | "policies": [ 39 | { 40 | "name": "CachingPolicy", 41 | "config": { 42 | "ttl": 60 43 | } 44 | } 45 | ] 46 | } 47 | ] 48 | } 49 | } -------------------------------------------------------------------------------- /examples/declarative/simple.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman example 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | plugins: 13 | - groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "test" 18 | description: "Test organisation" 19 | apis: 20 | - name: "example" 21 | description: "Example API" 22 | version: "1.0" 23 | published: true 24 | config: 25 | endpoint: "http://example.com" 26 | endpointType: "rest" 27 | public: true 28 | gateway: "test-gw" 29 | policies: 30 | - name: "CachingPolicy" 31 | config: 32 | ttl: 60 33 | -------------------------------------------------------------------------------- /examples/policies/caching-policy-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "ttl": 60 3 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apiman/apiman-cli/79db9e414181b0242f2529f992cb31df8647ca60/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = 'apiman-cli' 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/GatewayCli.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.core.AbstractCommand; 21 | import io.apiman.cli.command.core.Command; 22 | import io.apiman.cli.gatewayapi.command.GatewayOrgCommand; 23 | import io.apiman.cli.gatewayapi.command.GatewayStatusCommand; 24 | import io.apiman.cli.gatewayapi.command.api.GatewayApiCommand; 25 | import io.apiman.cli.gatewayapi.command.client.GatewayClientCommand; 26 | import io.apiman.cli.gatewayapi.command.generate.Generate; 27 | import io.apiman.cli.gatewayapi.declarative.command.GatewayApplyCommand; 28 | 29 | import java.util.Map; 30 | 31 | /** 32 | * Root of Gateway commands. 33 | * 34 | * @author Marc Savy {@literal } 35 | */ 36 | @Parameters(commandDescription = "Interact with an Apiman Gateway directly") 37 | public class GatewayCli extends AbstractCommand { 38 | 39 | @Override 40 | protected void populateCommands(Map> commandMap) { 41 | commandMap.put("generate", Generate.class); 42 | commandMap.put("apply", GatewayApplyCommand.class); 43 | commandMap.put("org", GatewayOrgCommand.class); 44 | commandMap.put("api", GatewayApiCommand.class); 45 | commandMap.put("client", GatewayClientCommand.class); 46 | commandMap.put("status", GatewayStatusCommand.class); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/ManagerCli.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.core.AbstractCommand; 21 | import io.apiman.cli.command.core.Command; 22 | import io.apiman.cli.managerapi.command.api.command.ApiCommand; 23 | import io.apiman.cli.managerapi.command.gateway.command.GatewayCommand; 24 | import io.apiman.cli.managerapi.command.org.command.OrgCommand; 25 | import io.apiman.cli.managerapi.command.plugin.command.PluginCommand; 26 | import io.apiman.cli.managerapi.declarative.command.ManagerApplyCommand; 27 | 28 | import java.util.Map; 29 | 30 | /** 31 | * The main class; the root of all Manager Commands. 32 | * 33 | * @author Pete Cornish {@literal } 34 | */ 35 | 36 | @Parameters(commandDescription = "Interact with the Apiman Manager") 37 | public class ManagerCli extends AbstractCommand { 38 | 39 | @Override 40 | protected void populateCommands(Map> commandMap) { 41 | commandMap.put("org", OrgCommand.class); 42 | commandMap.put("gateway", GatewayCommand.class); 43 | commandMap.put("plugin", PluginCommand.class); 44 | commandMap.put("api", ApiCommand.class); 45 | commandMap.put("apply", ManagerApplyCommand.class); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/annotations/CommandAvailableSince.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * @author Marc Savy {@literal } 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.TYPE) 29 | public @interface CommandAvailableSince { 30 | String value(); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/api/model/ApiGateway.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.api.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * @author Pete Cornish {@literal } 25 | */ 26 | @JsonInclude(JsonInclude.Include.NON_NULL) 27 | @JsonIgnoreProperties(ignoreUnknown = true) 28 | public class ApiGateway { 29 | @JsonProperty 30 | private String gatewayId; 31 | 32 | public ApiGateway() { 33 | } 34 | 35 | public ApiGateway(String gatewayId) { 36 | this.gatewayId = gatewayId; 37 | } 38 | 39 | public String getGatewayId() { 40 | return gatewayId; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/api/model/ApiPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.api.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | 23 | /** 24 | * Models a policy to be added to an API. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class ApiPolicy { 31 | /** 32 | * Note: this is a request property. 33 | */ 34 | @JsonProperty 35 | private String definitionId; 36 | 37 | /** 38 | * This is a response property. 39 | */ 40 | @JsonProperty 41 | private String policyDefinitionId; 42 | 43 | @JsonProperty 44 | private String configuration; 45 | 46 | /** 47 | * This is a response property. 48 | */ 49 | @JsonProperty 50 | private Long id; 51 | 52 | public ApiPolicy() { 53 | } 54 | 55 | public ApiPolicy(String configuration) { 56 | this.configuration = configuration; 57 | } 58 | 59 | public String getPolicyDefinitionId() { 60 | return policyDefinitionId; 61 | } 62 | 63 | public Long getId() { 64 | return id; 65 | } 66 | 67 | public void setDefinitionId(String definitionId) { 68 | this.definitionId = definitionId; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/api/model/ApiVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.api.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * Models an API version. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonInclude(JsonInclude.Include.NON_NULL) 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class ApiVersion { 31 | @JsonProperty 32 | private String version; 33 | 34 | /** 35 | * Never clone a previous version when creating a new version. 36 | */ 37 | @JsonProperty 38 | final private boolean clone = false; 39 | 40 | public ApiVersion(String version) { 41 | this.version = version; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/api/model/ServiceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.api.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Legacy support for apiman 1.1.x. 27 | * 28 | * @author Pete Cornish {@literal } 29 | */ 30 | @JsonInclude(JsonInclude.Include.NON_NULL) 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | public class ServiceConfig { 33 | @JsonProperty 34 | private String endpoint; 35 | 36 | @JsonProperty 37 | private String endpointType; 38 | 39 | @JsonProperty 40 | private boolean publicService; 41 | 42 | @JsonProperty 43 | private List gateways; 44 | 45 | public ServiceConfig() { 46 | } 47 | 48 | public ServiceConfig(String endpoint, String endpointType, boolean publicService, List gateways) { 49 | this.endpoint = endpoint; 50 | this.endpointType = endpointType; 51 | this.publicService = publicService; 52 | this.gateways = gateways; 53 | } 54 | 55 | public void setPublicService(boolean publicService) { 56 | this.publicService = publicService; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/core/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.core; 18 | 19 | import com.beust.jcommander.JCommander; 20 | import io.apiman.cli.exception.CommandException; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author Pete Cornish {@literal } 26 | */ 27 | public interface Command { 28 | 29 | /** 30 | * If the command is a child, the parent. 31 | * 32 | * @param command the parent command. 33 | */ 34 | void setParent(Command command); 35 | 36 | /** 37 | * Name of the command 38 | * 39 | * @param command the command name 40 | */ 41 | void setCommandName(String command); 42 | 43 | /** 44 | * Parse the given arguments and perform a command. 45 | * 46 | * @param args the arguments to parse 47 | */ 48 | void run(List args, JCommander jcommander); 49 | 50 | /** 51 | * Default implementation will print usage and exit with an error code. 52 | * Subclasses should implement their custom behaviour here. 53 | * 54 | * @param parser the command line parser 55 | */ 56 | void performAction(JCommander parser) throws CommandException; 57 | 58 | /** 59 | * Build subcommands and instantiate any children. 60 | * 61 | * @param jcommander the jcommander instance 62 | */ 63 | void build(JCommander jcommander); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/BaseDeclaration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | 23 | /** 24 | * Represents an API environment declaration. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonIgnoreProperties(ignoreUnknown = true) 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | public class BaseDeclaration { 31 | @JsonProperty 32 | private DeclarativeSystem system; 33 | 34 | @JsonProperty 35 | private SharedItems shared; 36 | 37 | @JsonProperty 38 | private DeclarativeOrg org; 39 | 40 | public DeclarativeSystem getSystem() { 41 | return system; 42 | } 43 | 44 | public DeclarativeOrg getOrg() { 45 | return org; 46 | } 47 | 48 | public void setSystem(DeclarativeSystem system) { 49 | this.system = system; 50 | } 51 | 52 | public void setOrg(DeclarativeOrg org) { 53 | this.org = org; 54 | } 55 | 56 | public SharedItems getShared() { 57 | return shared; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import io.apiman.cli.command.api.model.Api; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Declarative API representation. 28 | * 29 | * @author Pete Cornish {@literal } 30 | */ 31 | @JsonInclude(JsonInclude.Include.NON_NULL) 32 | @JsonIgnoreProperties(ignoreUnknown = true) 33 | public class DeclarativeApi extends Api { 34 | @JsonProperty 35 | private boolean published; 36 | 37 | @JsonProperty 38 | private DeclarativeApiConfig config; 39 | 40 | @JsonProperty 41 | private List policies; 42 | 43 | @JsonProperty 44 | private DeclarativeApiDefinition definition; 45 | 46 | public boolean isPublished() { 47 | return published; 48 | } 49 | 50 | public void setPublished(boolean published) { 51 | this.published = published; 52 | } 53 | 54 | public DeclarativeApiConfig getConfig() { 55 | return config; 56 | } 57 | 58 | public void setConfig(DeclarativeApiConfig config) { 59 | this.config = config; 60 | } 61 | 62 | public List getPolicies() { 63 | return policies; 64 | } 65 | 66 | public void setPolicies(List policies) { 67 | this.policies = policies; 68 | } 69 | 70 | public DeclarativeApiDefinition getDefinition() { 71 | return definition; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeApiConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import io.apiman.cli.command.api.model.ApiConfig; 23 | 24 | /** 25 | * Declarative API configuration. 26 | * 27 | * @author Pete Cornish {@literal } 28 | */ 29 | @JsonInclude(JsonInclude.Include.NON_NULL) 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | public class DeclarativeApiConfig extends ApiConfig { 32 | @JsonProperty("gateway") 33 | private String gateway; 34 | 35 | /** 36 | * Deliberate use of object instead of primitive, to allow nullity check. 37 | */ 38 | @JsonProperty("public") 39 | private Boolean makePublic; 40 | 41 | @JsonProperty("security") 42 | private DeclarativeEndpointSecurity security; 43 | 44 | public String getGateway() { 45 | return gateway; 46 | } 47 | 48 | public void setGateway(String gateway) { 49 | this.gateway = gateway; 50 | } 51 | 52 | public void setMakePublic(Boolean makePublic) { 53 | this.makePublic = makePublic; 54 | } 55 | 56 | public Boolean getMakePublic() { 57 | return makePublic; 58 | } 59 | 60 | public DeclarativeEndpointSecurity getSecurity() { 61 | return security; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeApiDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import io.apiman.cli.command.api.model.ApiConfig; 23 | 24 | /** 25 | * Declarative API configuration. 26 | * 27 | * @author Raleigh Pickard {@literal } 28 | */ 29 | @JsonInclude(JsonInclude.Include.NON_NULL) 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | public class DeclarativeApiDefinition extends ApiConfig { 32 | @JsonProperty("type") 33 | private String type = "application/json"; 34 | 35 | @JsonProperty("body") 36 | private String body; 37 | 38 | @JsonProperty("file") 39 | private String file; 40 | 41 | public String getType() { 42 | return type; 43 | } 44 | 45 | public String getBody() { 46 | return body; 47 | } 48 | 49 | public String getFile() { 50 | return file; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeEndpointSecurity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * @author Pete Cornish {@literal } 25 | */ 26 | @JsonInclude(JsonInclude.Include.NON_NULL) 27 | @JsonIgnoreProperties(ignoreUnknown = true) 28 | public class DeclarativeEndpointSecurity { 29 | @JsonProperty 30 | private String authorizationType; 31 | 32 | @JsonProperty 33 | private boolean requireSsl; 34 | 35 | @JsonProperty 36 | private String username; 37 | 38 | @JsonProperty 39 | private String password; 40 | 41 | public String getAuthorizationType() { 42 | return authorizationType; 43 | } 44 | 45 | public boolean getRequireSsl() { 46 | return requireSsl; 47 | } 48 | 49 | public String getUsername() { 50 | return username; 51 | } 52 | 53 | public String getPassword() { 54 | return password; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeGateway.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import io.apiman.cli.command.gateway.model.Gateway; 23 | import io.apiman.cli.command.gateway.model.GatewayConfig; 24 | 25 | /** 26 | * Declarative gateway representation. 27 | * 28 | * @author Pete Cornish {@literal } 29 | */ 30 | @JsonInclude(JsonInclude.Include.NON_NULL) 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | public class DeclarativeGateway extends Gateway { 33 | @JsonProperty 34 | private GatewayConfig config; 35 | 36 | public GatewayConfig getConfig() { 37 | return config; 38 | } 39 | 40 | public void setConfig(GatewayConfig config) { 41 | this.config = config; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeOrg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | import io.apiman.cli.command.org.model.Org; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Declarative organisation representation. 28 | * 29 | * @author Pete Cornish {@literal } 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 33 | public class DeclarativeOrg extends Org { 34 | /** 35 | * Common elements for every API. 36 | */ 37 | @JsonProperty 38 | private DeclarativeOrgCommon common; 39 | 40 | @JsonProperty 41 | private List apis; 42 | 43 | public DeclarativeOrgCommon getCommon() { 44 | return common; 45 | } 46 | 47 | public List getApis() { 48 | return apis; 49 | } 50 | 51 | public void setApis(List apis) { 52 | this.apis = apis; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeOrgCommon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | 23 | /** 24 | * Represents elements present in every API. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonIgnoreProperties(ignoreUnknown = true) 29 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 30 | public class DeclarativeOrgCommon { 31 | @JsonProperty 32 | private DeclarativeApiConfig config; 33 | 34 | @JsonProperty 35 | private DeclarativeOrgCommonPolicies policies; 36 | 37 | public DeclarativeApiConfig getConfig() { 38 | return config; 39 | } 40 | 41 | public DeclarativeOrgCommonPolicies getPolicies() { 42 | return policies; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeOrgCommonPolicies.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Represents policies present in every chain. 27 | * 28 | * @author Pete Cornish {@literal } 29 | */ 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 32 | public class DeclarativeOrgCommonPolicies { 33 | /** 34 | * Policies added to the beginning of every chain. 35 | */ 36 | @JsonProperty 37 | private List first; 38 | 39 | /** 40 | * Policies added to the end of every chain. 41 | */ 42 | @JsonProperty 43 | private List last; 44 | 45 | public List getFirst() { 46 | return first; 47 | } 48 | 49 | public List getLast() { 50 | return last; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativePolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import java.util.Map; 20 | 21 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 22 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 23 | import com.fasterxml.jackson.annotation.JsonInclude; 24 | import com.fasterxml.jackson.annotation.JsonProperty; 25 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 26 | 27 | /** 28 | * Declarative policy representation. 29 | * 30 | * @author Pete Cornish {@literal } 31 | */ 32 | @JsonInclude(JsonInclude.Include.NON_NULL) 33 | @JsonIgnoreProperties(ignoreUnknown = true) 34 | @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="$id") 35 | public class DeclarativePolicy { 36 | @JsonProperty("$id") 37 | private String id; 38 | 39 | @JsonProperty 40 | private String name; 41 | 42 | @JsonProperty 43 | private String plugin; 44 | 45 | @JsonProperty 46 | private Map config; 47 | 48 | public String getId() { 49 | return id; 50 | } 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | public Map getConfig() { 61 | return config; 62 | } 63 | 64 | public void setConfig(Map config) { 65 | this.config = config; 66 | } 67 | 68 | public String getPlugin() { 69 | return plugin; 70 | } 71 | 72 | public void setPlugin(String plugin) { 73 | this.plugin = plugin; 74 | } 75 | 76 | public boolean isPlugin() { 77 | return !(plugin == null || plugin.isEmpty()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/DeclarativeSystem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | import io.apiman.cli.command.plugin.model.Plugin; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Declarative system configuration. 28 | * 29 | * @author Pete Cornish {@literal } 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 33 | public class DeclarativeSystem { 34 | @JsonProperty 35 | private List gateways; 36 | 37 | @JsonProperty 38 | private List plugins; 39 | 40 | public List getGateways() { 41 | return gateways; 42 | } 43 | 44 | public void setGateways(List gateways) { 45 | this.gateways = gateways; 46 | } 47 | 48 | public List getPlugins() { 49 | return plugins; 50 | } 51 | 52 | public void setPlugins(List plugins) { 53 | this.plugins = plugins; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/declarative/model/SharedItems.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.declarative.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * Represents reusable items. 28 | * 29 | * @author Pete Cornish {@literal } 30 | */ 31 | @JsonIgnoreProperties(ignoreUnknown = true) 32 | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 33 | public class SharedItems { 34 | @JsonProperty 35 | private List policies; 36 | 37 | /** 38 | * Shared properties. 39 | */ 40 | @JsonProperty 41 | private Map properties; 42 | 43 | public Map getProperties() { 44 | return properties; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/gateway/model/Gateway.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.gateway.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * Models a gateway. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonInclude(JsonInclude.Include.NON_NULL) 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class Gateway { 31 | @JsonProperty 32 | private String name; 33 | 34 | @JsonProperty 35 | private String description; 36 | 37 | @JsonProperty 38 | private GatewayType type; 39 | 40 | @JsonProperty 41 | private String configuration; 42 | 43 | public Gateway() { 44 | } 45 | 46 | public Gateway(String name, String description, GatewayType type, String configuration) { 47 | this.name = name; 48 | this.description = description; 49 | this.type = type; 50 | this.configuration = configuration; 51 | } 52 | 53 | public void setConfiguration(String configuration) { 54 | this.configuration = configuration; 55 | } 56 | 57 | public String getName() { 58 | return name; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) return true; 64 | if (o == null || getClass() != o.getClass()) return false; 65 | 66 | Gateway gateway = (Gateway) o; 67 | 68 | return name != null ? name.equals(gateway.name) : gateway.name == null; 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return name != null ? name.hashCode() : 0; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/gateway/model/GatewayConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.gateway.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * Models gateway configuration. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonInclude(JsonInclude.Include.NON_NULL) 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class GatewayConfig { 31 | @JsonProperty 32 | private String endpoint; 33 | 34 | @JsonProperty 35 | private String username; 36 | 37 | @JsonProperty 38 | private String password; 39 | 40 | public GatewayConfig() { 41 | } 42 | 43 | public GatewayConfig(String endpoint, String username, String password) { 44 | this.endpoint = endpoint; 45 | this.username = username; 46 | this.password = password; 47 | } 48 | 49 | public String getEndpoint() { 50 | return endpoint; 51 | } 52 | 53 | public String getUsername() { 54 | return username; 55 | } 56 | 57 | public String getPassword() { 58 | return password; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/gateway/model/GatewayTestResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.gateway.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * Models the response from a gateway test. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonInclude(JsonInclude.Include.NON_NULL) 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class GatewayTestResponse { 31 | @JsonProperty 32 | private boolean success; 33 | 34 | @JsonProperty 35 | private String detail; 36 | 37 | public boolean isSuccess() { 38 | return success; 39 | } 40 | 41 | public String getDetail() { 42 | return detail; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/gateway/model/GatewayType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.gateway.model; 18 | 19 | /** 20 | * Models gateway types. 21 | * 22 | * @author Pete Cornish {@literal } 23 | */ 24 | public enum GatewayType { 25 | REST, 26 | SOAP 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/command/org/model/Org.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.command.org.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * Models an organisation. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonInclude(JsonInclude.Include.NON_NULL) 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class Org { 31 | @JsonProperty 32 | private String name; 33 | 34 | @JsonProperty 35 | private String description; 36 | 37 | public Org() { 38 | } 39 | 40 | public Org(String name, String description) { 41 | this.name = name; 42 | this.description = description; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public void setDescription(String description) { 54 | this.description = description; 55 | } 56 | 57 | public String getDescription() { 58 | return description; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/exception/CommandException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.exception; 18 | 19 | /** 20 | * Represents an error during command execution. 21 | * 22 | * @author Pete Cornish {@literal } 23 | */ 24 | public class CommandException extends RuntimeException { 25 | public CommandException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | public CommandException(String message) { 30 | super(message); 31 | } 32 | 33 | public CommandException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/exception/DeclarativeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.exception; 18 | 19 | /** 20 | * Thrown due to a failure to apply a declaration. 21 | * 22 | * @author Pete Cornish {@literal } 23 | */ 24 | public class DeclarativeException extends RuntimeException { 25 | public DeclarativeException() { 26 | super(); 27 | } 28 | 29 | public DeclarativeException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public DeclarativeException(String message) { 34 | super(message); 35 | } 36 | 37 | public DeclarativeException(String message, Throwable cause) { 38 | super(message, cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/exception/ExitWithCodeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.exception; 18 | 19 | /** 20 | * Causes the application to exit with the given code and prints a message. 21 | * 22 | * @author Pete Cornish {@literal } 23 | */ 24 | public class ExitWithCodeException extends RuntimeException { 25 | private final int exitCode; 26 | private final boolean printUsage; 27 | 28 | public ExitWithCodeException(int exitCode, String message) { 29 | this(exitCode, message, false); 30 | } 31 | 32 | public ExitWithCodeException(int exitCode, String message, boolean printUsage) { 33 | super(message); 34 | this.exitCode = exitCode; 35 | this.printUsage = printUsage; 36 | } 37 | 38 | public int getExitCode() { 39 | return exitCode; 40 | } 41 | 42 | public boolean isPrintUsage() { 43 | return printUsage; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/GatewayCommon.java: -------------------------------------------------------------------------------- 1 | package io.apiman.cli.gatewayapi; 2 | 3 | import com.beust.jcommander.Parameter; 4 | 5 | /** 6 | * @author Marc Savy {@literal } 7 | */ 8 | public class GatewayCommon { 9 | 10 | private String DEFAULT_SERVER_ADDRESS = "http://localhost:8080/apiman-gateway-api"; 11 | private String DEFAULT_GATEWAY_USER = "apimanager"; 12 | private String DEFAULT_GATEWAY_PASSWORD = "apiman123!"; 13 | 14 | @Parameter(names = { "--server", "-s"}, description = "Gateway API server address") 15 | private String serverAddress = DEFAULT_SERVER_ADDRESS; 16 | 17 | @Parameter(names = { "--serverUsername", "-su"}, description = "Gateway API server username") 18 | private String serverUsername = DEFAULT_GATEWAY_USER; 19 | 20 | @Parameter(names = { "--serverPassword", "-sp"}, description = "Gateway API server password") 21 | private String serverPassword = DEFAULT_GATEWAY_PASSWORD; 22 | 23 | public String getGatewayApiEndpoint() { 24 | return serverAddress; 25 | } 26 | 27 | public String getGatewayApiUsername() { 28 | return serverUsername; 29 | } 30 | 31 | public String getGatewayApiPassword() { 32 | return serverPassword; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/GatewayOrgCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command; 17 | 18 | import com.beust.jcommander.Parameters; 19 | import io.apiman.cli.command.core.AbstractCommand; 20 | import io.apiman.cli.command.core.Command; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Gateway organization commands. 26 | * 27 | * @author Marc Savy {@literal } 28 | */ 29 | @Parameters(commandDescription = "List Organizations") 30 | public class GatewayOrgCommand extends AbstractCommand { 31 | @Override 32 | protected void populateCommands(Map> commandMap) { 33 | commandMap.put("list", ListOrgCommand.class); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/GatewayStatusCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command; 17 | 18 | import com.beust.jcommander.JCommander; 19 | import com.beust.jcommander.Parameters; 20 | import com.google.inject.Inject; 21 | import io.apiman.cli.exception.CommandException; 22 | import io.apiman.cli.gatewayapi.GatewayApi; 23 | import io.apiman.cli.gatewayapi.GatewayHelper; 24 | import io.apiman.cli.gatewayapi.command.common.AbstractGatewayCommand; 25 | import io.apiman.cli.gatewayapi.command.factory.GatewayApiService; 26 | import io.apiman.cli.util.MappingUtil; 27 | import org.apache.logging.log4j.LogManager; 28 | import org.apache.logging.log4j.Logger; 29 | 30 | /** 31 | * Pulls remote gateway API status. 32 | * 33 | * @author Marc Savy {@literal } 34 | */ 35 | @Parameters(commandDescription = "View Gateway Status") 36 | public class GatewayStatusCommand extends AbstractGatewayCommand implements GatewayHelper { 37 | 38 | private Logger LOGGER = LogManager.getLogger(GatewayStatusCommand.class); 39 | 40 | @Inject 41 | protected GatewayStatusCommand(GatewayApiService apiFactory) { 42 | super(apiFactory); 43 | } 44 | 45 | @Override 46 | public void performFinalAction(JCommander parser) throws CommandException { 47 | GatewayApi gatewayApi = getGatewayApiService().buildGatewayApiClient(); 48 | // Do status check 49 | statusCheck(gatewayApi, getGatewayConfig().getGatewayApiEndpoint()); 50 | // Print status info 51 | System.out.println(MappingUtil.safeWriteValueAsJson(gatewayApi.getSystemStatus())); 52 | } 53 | 54 | protected boolean permitNoArgs() { 55 | return true; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/ListOrgCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command; 17 | 18 | import com.beust.jcommander.JCommander; 19 | import com.beust.jcommander.Parameters; 20 | import com.google.inject.Inject; 21 | import io.apiman.cli.annotations.CommandAvailableSince; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.gatewayapi.GatewayApi; 24 | import io.apiman.cli.gatewayapi.GatewayHelper; 25 | import io.apiman.cli.gatewayapi.command.common.AbstractGatewayCommand; 26 | import io.apiman.cli.gatewayapi.command.factory.GatewayApiService; 27 | import org.apache.logging.log4j.LogManager; 28 | import org.apache.logging.log4j.Logger; 29 | 30 | import java.util.List; 31 | 32 | /** 33 | * List all Org IDs on gateway. 34 | * 35 | * @author Marc Savy {@literal } 36 | */ 37 | @CommandAvailableSince("1.3.2") 38 | @Parameters(commandDescription = "List all Organization IDs") 39 | public class ListOrgCommand extends AbstractGatewayCommand 40 | implements GatewayHelper { 41 | 42 | private Logger LOGGER = LogManager.getLogger(ListOrgCommand.class); 43 | 44 | @Inject 45 | protected ListOrgCommand(GatewayApiService apiService) { 46 | super(apiService); 47 | } 48 | 49 | @Override 50 | public void performFinalAction(JCommander parser) throws CommandException { 51 | GatewayApi gatewayApi = getGatewayApiService().buildGatewayApiClient(); 52 | // Do status check 53 | statusCheck(gatewayApi, getGatewayConfig().getGatewayApiEndpoint()); 54 | // Get endpoint (if any) 55 | List orgs = callAndCatch(() -> gatewayApi.listOrgs()); 56 | LOGGER.debug("Orgs returned: {}", orgs.size()); 57 | // Sort case insensitively 58 | orgs.sort(String::compareToIgnoreCase); 59 | orgs.forEach(System.out::println); 60 | } 61 | 62 | protected boolean permitNoArgs() { 63 | return true; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/api/ApiEndpointCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command.api; 17 | 18 | import com.beust.jcommander.JCommander; 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import com.google.inject.Inject; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.gatewayapi.GatewayApi; 24 | import io.apiman.cli.gatewayapi.GatewayHelper; 25 | import io.apiman.cli.gatewayapi.command.common.AbstractGatewayCommand; 26 | import io.apiman.cli.gatewayapi.command.factory.GatewayApiService; 27 | import io.apiman.gateway.engine.beans.ApiEndpoint; 28 | 29 | /** 30 | * Get an API's public endpoint. 31 | * 32 | * @author Marc Savy {@literal } 33 | */ 34 | @Parameters(commandDescription = "Get an API's endpoint") 35 | public class ApiEndpointCommand extends AbstractGatewayCommand implements GatewayHelper { 36 | 37 | @Parameter(names = "--org", description = "Organization ID", required = true) 38 | private String orgId; 39 | 40 | @Parameter(names = "--api", description = "API ID", required = true) 41 | private String apiId; 42 | 43 | @Parameter(names = "--version", description = "API Version", required = true) 44 | private String version; 45 | 46 | @Inject 47 | protected ApiEndpointCommand(GatewayApiService apiFactory) { 48 | super(apiFactory); 49 | } 50 | 51 | @Override 52 | public void performFinalAction(JCommander parser) throws CommandException { 53 | GatewayApi gatewayApi = getGatewayApiService().buildGatewayApiClient(); 54 | // Do status check 55 | statusCheck(gatewayApi, getGatewayConfig().getGatewayApiEndpoint()); 56 | // Get endpoint (if any) 57 | ApiEndpoint endpoint = callAndCatch(() -> gatewayApi.getApiEndpoint(orgId, apiId, version)); 58 | // Print to syso 59 | System.out.println(endpoint.getEndpoint()); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/api/GatewayApiCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command.api; 17 | 18 | import com.beust.jcommander.Parameters; 19 | import io.apiman.cli.command.core.AbstractCommand; 20 | import io.apiman.cli.command.core.Command; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Operations on API entities. 26 | * 27 | * @author Marc Savy {@literal } 28 | */ 29 | @Parameters(commandDescription = "Retire and list APIs") 30 | public class GatewayApiCommand extends AbstractCommand { 31 | @Override 32 | protected void populateCommands(Map> commandMap) { 33 | commandMap.put("retire", RetireApiCommand.class); 34 | commandMap.put("list", ListApiCommand.class); 35 | commandMap.put("endpoint", ApiEndpointCommand.class); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/api/RetireApiCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command.api; 17 | 18 | import com.beust.jcommander.JCommander; 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import com.google.inject.Inject; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.gatewayapi.GatewayApi; 24 | import io.apiman.cli.gatewayapi.GatewayHelper; 25 | import io.apiman.cli.gatewayapi.command.common.AbstractGatewayCommand; 26 | import io.apiman.cli.gatewayapi.command.factory.GatewayApiService; 27 | 28 | /** 29 | * Retire an API entity. 30 | * 31 | * @author Marc Savy {@literal } 32 | */ 33 | @Parameters(commandDescription = "Retire an API") 34 | public class RetireApiCommand extends AbstractGatewayCommand implements GatewayHelper { 35 | 36 | @Parameter(names = "--org", description = "Organization ID", required = true) 37 | private String orgId; 38 | 39 | @Parameter(names = "--api", description = "API ID", required = true) 40 | private String apiId; 41 | 42 | @Parameter(names = "--version", description = "API Version", required = true) 43 | private String version; 44 | 45 | @Inject 46 | protected RetireApiCommand(GatewayApiService apiFactory) { 47 | super(apiFactory); 48 | } 49 | 50 | @Override 51 | public void performFinalAction(JCommander parser) throws CommandException { 52 | GatewayApi gatewayApi = getGatewayApiService().buildGatewayApiClient(); 53 | // Do status check 54 | statusCheck(gatewayApi, getGatewayConfig().getGatewayApiEndpoint()); 55 | // Attempt retire 56 | callAndCatch(() -> gatewayApi.retireApi(orgId, apiId, version)); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/client/GatewayClientCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command.client; 17 | 18 | import com.beust.jcommander.Parameters; 19 | import io.apiman.cli.command.core.AbstractCommand; 20 | import io.apiman.cli.command.core.Command; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Operations on client entities. 26 | * 27 | * @author Marc Savy {@literal } 28 | */ 29 | @Parameters(commandDescription = "Retire and list Clients") 30 | public class GatewayClientCommand extends AbstractCommand { 31 | @Override 32 | protected void populateCommands(Map> commandMap) { 33 | commandMap.put("unregister", UnregisterClientCommand.class); 34 | commandMap.put("list", ListClientCommand.class); 35 | commandMap.put("endpoint", ClientEndpointCommand.class); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/client/UnregisterClientCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command.client; 17 | 18 | import com.beust.jcommander.JCommander; 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import com.google.inject.Inject; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.gatewayapi.GatewayApi; 24 | import io.apiman.cli.gatewayapi.GatewayHelper; 25 | import io.apiman.cli.gatewayapi.command.common.AbstractGatewayCommand; 26 | import io.apiman.cli.gatewayapi.command.factory.GatewayApiService; 27 | 28 | /** 29 | * Unregister client entity. 30 | * 31 | * @author Marc Savy {@literal } 32 | */ 33 | @Parameters(commandDescription = "Unregister a Client App") 34 | public class UnregisterClientCommand extends AbstractGatewayCommand implements GatewayHelper { 35 | 36 | @Parameter(names = "--org", description = "Organization ID", required = true) 37 | private String orgId; 38 | 39 | @Parameter(names = "--client", description = "Client App ID", required = true) 40 | private String clientId; 41 | 42 | @Parameter(names = "--version", description = "API Version", required = true) 43 | private String version; 44 | 45 | @Inject 46 | protected UnregisterClientCommand(GatewayApiService apiFactory) { 47 | super(apiFactory); 48 | } 49 | 50 | @Override 51 | public void performFinalAction(JCommander parser) throws CommandException { 52 | GatewayApi gatewayApi = getGatewayApiService().buildGatewayApiClient(); 53 | // Do status check 54 | statusCheck(gatewayApi, getGatewayConfig().getGatewayApiEndpoint()); 55 | // Attempt retire 56 | callAndCatch(() -> gatewayApi.unregisterClient(orgId, clientId, version)); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/factory/GatewayApiFactory.java: -------------------------------------------------------------------------------- 1 | package io.apiman.cli.gatewayapi.command.factory; 2 | 3 | import io.apiman.cli.gatewayapi.GatewayApi; 4 | import io.apiman.cli.managerapi.management.factory.AbstractManagementApiFactory; 5 | 6 | /** 7 | * @author Marc Savy {@literal } 8 | */ 9 | public class GatewayApiFactory extends AbstractManagementApiFactory { 10 | 11 | @Override 12 | public GatewayApi build(String endpoint, String username, String password, boolean debugLogging) { 13 | return buildClient(GatewayApi.class, endpoint, username, password, debugLogging); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/factory/GatewayApiService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 JBoss Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.gatewayapi.command.factory; 18 | 19 | import com.google.inject.Inject; 20 | import io.apiman.cli.gatewayapi.GatewayApi; 21 | import io.apiman.cli.gatewayapi.GatewayCommon; 22 | import io.apiman.cli.gatewayapi.GatewayHelper; 23 | import io.apiman.cli.services.WaitService; 24 | import io.apiman.cli.util.LogUtil; 25 | 26 | /** 27 | * @author Marc Savy {@literal } 28 | */ 29 | public class GatewayApiService implements WaitService, GatewayHelper { 30 | 31 | private GatewayCommon gatewayConfig; 32 | private GatewayApiFactory gatewayApiFactory; 33 | 34 | @Inject 35 | public void setGatewayApiFactory(GatewayApiFactory gatewayApiFactory) { 36 | this.gatewayApiFactory = gatewayApiFactory; 37 | } 38 | 39 | public void configureEndpoint(GatewayCommon gatewayConfig) { 40 | this.gatewayConfig = gatewayConfig; 41 | } 42 | 43 | /** 44 | * See {@link GatewayApiFactory#build(String, String, String, boolean)} 45 | * @return the a GatewayApi instance 46 | */ 47 | public GatewayApi buildGatewayApiClient() { 48 | return gatewayApiFactory.build(gatewayConfig.getGatewayApiEndpoint(), 49 | gatewayConfig.getGatewayApiUsername(), 50 | gatewayConfig.getGatewayApiPassword(), 51 | LogUtil.isLogDebug()); 52 | } 53 | 54 | @Override 55 | public void waitForServer(int waitTime) { 56 | waitForServer(buildGatewayApiClient(), waitTime); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/gatewayapi/command/generate/Generate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.apiman.cli.gatewayapi.command.generate; 17 | 18 | import com.beust.jcommander.Parameters; 19 | import io.apiman.cli.command.core.AbstractCommand; 20 | import io.apiman.cli.command.core.Command; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Sub-command for generating gateway configurations 26 | * 27 | * @author Marc Savy {@literal } 28 | */ 29 | @Parameters(commandDescription = "Generate configurations") 30 | public class Generate extends AbstractCommand { 31 | @Override 32 | protected void populateCommands(Map> commandMap) { 33 | commandMap.put("headless", GenerateHeadless.class); // Is this generic enough? 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/ApiMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.api; 18 | 19 | import io.apiman.cli.command.api.model.Api; 20 | import io.apiman.cli.managerapi.command.common.command.ModelAction; 21 | 22 | /** 23 | * @author Pete Cornish {@literal } 24 | */ 25 | public interface ApiMixin extends ModelAction { 26 | @Override 27 | default Class getApiClass() { 28 | return Version12xServerApi.class; 29 | } 30 | 31 | @Override 32 | default Class getModelClass() { 33 | return Api.class; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/VersionAgnosticApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.api; 18 | import io.apiman.cli.command.api.model.Api; 19 | import io.apiman.cli.command.api.model.ApiConfig; 20 | import io.apiman.cli.command.api.model.ApiPolicy; 21 | import io.apiman.cli.command.api.model.ApiVersion; 22 | import retrofit.client.Response; 23 | import retrofit.mime.TypedString; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * @author Pete Cornish {@literal } 29 | */ 30 | public interface VersionAgnosticApi { 31 | Response create(String orgName, Api api); 32 | 33 | Response createVersion(String orgName, String apiName, ApiVersion apiVersion); 34 | 35 | List list(String orgName); 36 | 37 | Api fetch(String orgName, String apiName); 38 | 39 | Api fetchVersion(String orgName, String apiName, String version); 40 | 41 | Response configure(String orgName, String apiName, 42 | String version, ApiConfig config); 43 | 44 | Response addPolicy(String orgName, String apiName, 45 | String version, ApiPolicy policyConfig); 46 | 47 | Response setDefinition(String orgName, String apiName, 48 | String version, String definitionType, TypedString definition); 49 | 50 | List fetchPolicies(String orgName, String serviceName, 51 | String version); 52 | 53 | Response configurePolicy(String orgName, String apiName, 54 | String apiVersion, Long policyId, ApiPolicy policyConfig); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/command/AbstractApiCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.api.command; 18 | 19 | import com.beust.jcommander.Parameter; 20 | import io.apiman.cli.command.api.model.Api; 21 | import io.apiman.cli.managerapi.command.api.ApiMixin; 22 | import io.apiman.cli.managerapi.command.api.Version12xServerApi; 23 | import io.apiman.cli.managerapi.command.common.command.AbstractManagerModelCommand; 24 | import io.apiman.cli.managerapi.command.common.model.ManagementApiVersion; 25 | import io.apiman.cli.managerapi.service.ManagementApiService; 26 | 27 | /** 28 | * Common API functionality. 29 | * 30 | * @author Pete Cornish {@literal } 31 | */ 32 | public abstract class AbstractApiCommand extends AbstractManagerModelCommand 33 | implements ApiMixin { 34 | @Parameter(names = { "--orgName", "-o"}, description = "Organisation name", required = true) 35 | protected String orgName; 36 | 37 | @Parameter(names = { "--serverVersion", "-sv"}, description = "Management API server version") 38 | protected ManagementApiVersion serverVersion = ManagementApiVersion.DEFAULT_VERSION; 39 | 40 | AbstractApiCommand(ManagementApiService managementApiService) { 41 | super(managementApiService); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/command/AbstractManagerCommand.java: -------------------------------------------------------------------------------- 1 | package io.apiman.cli.managerapi.command.api.command; 2 | 3 | import io.apiman.cli.command.core.AbstractCommand; 4 | import io.apiman.cli.managerapi.service.ManagementApiService; 5 | 6 | /** 7 | * @author Marc Savy {@literal } 8 | */ 9 | public abstract class AbstractManagerCommand extends AbstractCommand { 10 | protected final ManagementApiService managementApiService; 11 | 12 | public AbstractManagerCommand(ManagementApiService managementApiService) { 13 | this.managementApiService = managementApiService; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/command/ApiCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.api.command; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.core.Command; 21 | import io.apiman.cli.managerapi.service.ManagementApiService; 22 | 23 | import javax.inject.Inject; 24 | import java.util.Map; 25 | 26 | /** 27 | * Root Command for managing APIs. 28 | * 29 | * @author Pete Cornish {@literal } 30 | */ 31 | @Parameters(commandDescription = "Manage APIs") 32 | public class ApiCommand extends AbstractManagerCommand { 33 | 34 | @Inject 35 | public ApiCommand(ManagementApiService managementApiService) { 36 | super(managementApiService); 37 | } 38 | 39 | @Override 40 | protected void populateCommands(Map> commandMap) { 41 | commandMap.put("create", ApiCreateCommand.class); 42 | commandMap.put("list", ApiListCommand.class); 43 | commandMap.put("publish", ApiPublishCommand.class); 44 | commandMap.put("policy", ApiPolicyCommand.class); 45 | commandMap.put("definition", ApiDefinitionCommand.class); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/command/ApiListCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.api.command; 18 | 19 | import com.beust.jcommander.JCommander; 20 | import com.beust.jcommander.Parameters; 21 | import io.apiman.cli.command.api.model.Api; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.managerapi.command.api.ApiMixin; 24 | import io.apiman.cli.managerapi.command.api.VersionAgnosticApi; 25 | import io.apiman.cli.managerapi.service.ManagementApiService; 26 | import io.apiman.cli.util.LogUtil; 27 | import io.apiman.cli.util.MappingUtil; 28 | import org.apache.logging.log4j.LogManager; 29 | import org.apache.logging.log4j.Logger; 30 | 31 | import javax.inject.Inject; 32 | import java.util.List; 33 | 34 | /** 35 | * List APIs. 36 | * 37 | * @author Pete Cornish {@literal } 38 | */ 39 | @Parameters(commandDescription = "List APIs") 40 | public class ApiListCommand extends AbstractApiCommand implements ApiMixin { 41 | private static final Logger LOGGER = LogManager.getLogger(ApiListCommand.class); 42 | 43 | @Inject 44 | public ApiListCommand(ManagementApiService managementApiService) { 45 | super(managementApiService); 46 | } 47 | 48 | @Override 49 | public void performFinalAction(JCommander parser) throws CommandException { 50 | LOGGER.debug("Listing {}", this::getModelName); 51 | 52 | final List apis = getManagerConfig().buildServerApiClient(VersionAgnosticApi.class, serverVersion).list(orgName); 53 | LogUtil.OUTPUT.info(MappingUtil.safeWriteValueAsJson(apis)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/command/ApiPolicyCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.api.command; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.core.Command; 21 | import io.apiman.cli.managerapi.service.ManagementApiService; 22 | 23 | import javax.inject.Inject; 24 | import java.util.Map; 25 | 26 | /** 27 | * Root Command for managing API policies. 28 | * 29 | * @author Pete Cornish {@literal } 30 | */ 31 | 32 | @Parameters(commandDescription = "Manage API policies") 33 | public class ApiPolicyCommand extends AbstractManagerCommand { 34 | @Inject 35 | public ApiPolicyCommand(ManagementApiService managementApiService) { 36 | super(managementApiService); 37 | } 38 | 39 | @Override 40 | protected void populateCommands(Map> commandMap) { 41 | commandMap.put("add", ApiPolicyAddCommand.class); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/api/command/ApiPublishCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.api.command; 18 | 19 | import com.beust.jcommander.JCommander; 20 | import com.beust.jcommander.Parameter; 21 | import com.beust.jcommander.Parameters; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.managerapi.command.api.ApiMixin; 24 | import io.apiman.cli.managerapi.command.common.ActionApi; 25 | import io.apiman.cli.managerapi.command.common.util.ServerActionUtil; 26 | import io.apiman.cli.managerapi.service.ManagementApiService; 27 | import org.apache.logging.log4j.LogManager; 28 | import org.apache.logging.log4j.Logger; 29 | 30 | import javax.inject.Inject; 31 | 32 | /** 33 | * Publish an API. 34 | * 35 | * @author Pete Cornish {@literal } 36 | */ 37 | @Parameters(commandDescription = "Publish API") 38 | public class ApiPublishCommand extends AbstractApiCommand implements ApiMixin { 39 | private static final Logger LOGGER = LogManager.getLogger(ApiPublishCommand.class); 40 | 41 | @Parameter(names = { "--name", "-n"}, description = "API name", required = true) 42 | private String name; 43 | 44 | @Parameter(names = { "--version", "-v"}, description = "API version", required = true) 45 | private String version; 46 | 47 | @Inject 48 | public ApiPublishCommand(ManagementApiService managementApiService) { 49 | super(managementApiService); 50 | } 51 | 52 | @Override 53 | public void performFinalAction(JCommander parser) throws CommandException { 54 | LOGGER.debug("Publishing {}", this::getModelName); 55 | ServerActionUtil.publishApi(orgName, name, version, serverVersion, getManagerConfig().buildServerApiClient(ActionApi.class)); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/ActionApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common; 18 | 19 | import io.apiman.cli.managerapi.command.common.model.ServerAction; 20 | import retrofit.client.Response; 21 | import retrofit.http.Body; 22 | import retrofit.http.POST; 23 | 24 | /** 25 | * @author Pete Cornish {@literal } 26 | */ 27 | public interface ActionApi { 28 | @POST("/actions") 29 | Response doAction(@Body ServerAction action); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/command/AbstractManagerModelCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common.command; 18 | 19 | import com.beust.jcommander.ParametersDelegate; 20 | import io.apiman.cli.command.core.AbstractFinalCommand; 21 | import io.apiman.cli.managerapi.ManagerCommon; 22 | import io.apiman.cli.managerapi.service.ManagementApiService; 23 | 24 | /** 25 | * Common model CRUD functionality. 26 | * 27 | * @author Pete Cornish {@literal } 28 | */ 29 | public abstract class AbstractManagerModelCommand extends AbstractFinalCommand 30 | implements ModelAction { 31 | 32 | protected final ManagementApiService managementApiService; 33 | 34 | @ParametersDelegate 35 | private ManagerCommon managerConfig; 36 | 37 | public ManagerCommon getManagerConfig() { 38 | return managerConfig; 39 | } 40 | 41 | public AbstractManagerModelCommand(ManagementApiService managementApiService) { 42 | super(managementApiService); 43 | this.managementApiService = managementApiService; 44 | managerConfig = new ManagerCommon(managementApiService); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/command/ModelAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common.command; 18 | 19 | /** 20 | * @author Pete Cornish {@literal } 21 | */ 22 | public interface ModelAction { 23 | Class getModelClass(); 24 | 25 | Class getApiClass(); 26 | 27 | /** 28 | * @return the name for the model class 29 | */ 30 | default String getModelName() { 31 | return getModelClass().getSimpleName(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/command/ModelCreateCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common.command; 18 | 19 | import com.beust.jcommander.JCommander; 20 | import io.apiman.cli.exception.CommandException; 21 | import io.apiman.cli.managerapi.management.ManagementApiUtil; 22 | import io.apiman.cli.managerapi.service.ManagementApiService; 23 | import org.apache.logging.log4j.LogManager; 24 | import org.apache.logging.log4j.Logger; 25 | import retrofit.client.Response; 26 | 27 | import java.lang.reflect.InvocationTargetException; 28 | import java.lang.reflect.Method; 29 | 30 | /** 31 | * @author Pete Cornish {@literal } 32 | */ 33 | public abstract class ModelCreateCommand extends AbstractManagerModelCommand { 34 | private static final Logger LOGGER = LogManager.getLogger(ModelCreateCommand.class); 35 | 36 | public ModelCreateCommand(ManagementApiService managementApiService) { 37 | super(managementApiService); 38 | } 39 | 40 | @Override 41 | public void performFinalAction(JCommander parser) throws CommandException { 42 | LOGGER.debug("Creating {}", this::getModelName); 43 | 44 | ManagementApiUtil.invokeAndCheckResponse(() -> { 45 | try { 46 | final A apiClient = getManagerConfig().buildServerApiClient(getApiClass()); 47 | final Method createMethod = apiClient.getClass().getMethod("create", getModelClass()); 48 | return (Response) createMethod.invoke(apiClient, buildModelInstance()); 49 | 50 | } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { 51 | throw new CommandException(e); 52 | } 53 | }); 54 | } 55 | 56 | protected abstract M buildModelInstance() throws CommandException; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/command/ModelListCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common.command; 18 | 19 | import com.beust.jcommander.JCommander; 20 | import io.apiman.cli.exception.CommandException; 21 | import io.apiman.cli.managerapi.service.ManagementApiService; 22 | import io.apiman.cli.util.LogUtil; 23 | import io.apiman.cli.util.MappingUtil; 24 | import org.apache.logging.log4j.LogManager; 25 | import org.apache.logging.log4j.Logger; 26 | 27 | import java.lang.reflect.InvocationTargetException; 28 | import java.lang.reflect.Method; 29 | import java.util.List; 30 | 31 | /** 32 | * @author Pete Cornish {@literal } 33 | */ 34 | public abstract class ModelListCommand extends AbstractManagerModelCommand { 35 | private static final Logger LOGGER = LogManager.getLogger(ModelListCommand.class); 36 | 37 | public ModelListCommand(ManagementApiService managementApiService) { 38 | super(managementApiService); 39 | } 40 | 41 | @Override 42 | protected boolean permitNoArgs() { 43 | return true; 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | @Override 48 | public void performFinalAction(JCommander parser) throws CommandException { 49 | LOGGER.debug("Listing {}", this::getModelName); 50 | 51 | try { 52 | final A apiClient = getManagerConfig().buildServerApiClient(getApiClass()); 53 | final Method listMethod = apiClient.getClass().getMethod("list"); 54 | processList((List) listMethod.invoke(apiClient)); 55 | 56 | } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { 57 | throw new CommandException(e); 58 | } 59 | } 60 | 61 | protected void processList(List model) { 62 | LogUtil.OUTPUT.info(MappingUtil.safeWriteValueAsJson(model)); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/command/ModelShowCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common.command; 18 | 19 | import com.beust.jcommander.JCommander; 20 | import io.apiman.cli.exception.CommandException; 21 | import io.apiman.cli.managerapi.service.ManagementApiService; 22 | import io.apiman.cli.util.LogUtil; 23 | import io.apiman.cli.util.MappingUtil; 24 | import org.apache.logging.log4j.LogManager; 25 | import org.apache.logging.log4j.Logger; 26 | 27 | import java.lang.reflect.Method; 28 | 29 | /** 30 | * @author Pete Cornish {@literal } 31 | */ 32 | public abstract class ModelShowCommand extends AbstractManagerModelCommand { 33 | private static final Logger LOGGER = LogManager.getLogger(ModelShowCommand.class); 34 | 35 | public ModelShowCommand(ManagementApiService managementApiService) { 36 | super(managementApiService); 37 | } 38 | 39 | @Override 40 | public void performFinalAction(JCommander parser) throws CommandException { 41 | LOGGER.debug("Showing {}", this::getModelName); 42 | 43 | try { 44 | final A apiClient = getManagerConfig().buildServerApiClient(getApiClass()); 45 | final Method fetchMethod = apiClient.getClass().getMethod("fetch", String.class); 46 | 47 | @SuppressWarnings("unchecked") 48 | final M model = (M) fetchMethod.invoke(apiClient, getModelId()); 49 | LOGGER.debug("{} received: {}", this::getModelName, () -> MappingUtil.safeWriteValueAsJson(model)); 50 | 51 | processModel(model); 52 | 53 | } catch (Exception e) { 54 | throw new CommandException(e); 55 | } 56 | } 57 | 58 | protected void processModel(M model) { 59 | LogUtil.OUTPUT.info(MappingUtil.safeWriteValueAsJson(model)); 60 | } 61 | 62 | protected abstract String getModelId() throws CommandException; 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/model/ManagementApiVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common.model; 18 | 19 | /** 20 | * The supported management API versions. 21 | * 22 | * @author Pete Cornish {@literal } 23 | */ 24 | public enum ManagementApiVersion { 25 | UNSPECIFIED, 26 | v11x, 27 | v12x; 28 | 29 | public static final ManagementApiVersion DEFAULT_VERSION = v12x; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/common/model/ServerAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.common.model; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | /** 24 | * Models a server action. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | @JsonInclude(JsonInclude.Include.NON_NULL) 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class ServerAction { 31 | @JsonProperty 32 | private String type; 33 | 34 | @JsonProperty 35 | private String entityId; 36 | 37 | @JsonProperty 38 | private String organizationId; 39 | 40 | @JsonProperty 41 | private String entityVersion; 42 | 43 | public ServerAction() { 44 | } 45 | 46 | public ServerAction(String type, String organizationId, String entityId, String entityVersion) { 47 | this.type = type; 48 | this.organizationId = organizationId; 49 | this.entityId = entityId; 50 | this.entityVersion = entityVersion; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/gateway/GatewayApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.gateway; 18 | 19 | import io.apiman.cli.command.gateway.model.Gateway; 20 | import io.apiman.cli.command.gateway.model.GatewayTestResponse; 21 | import retrofit.client.Response; 22 | import retrofit.http.Body; 23 | import retrofit.http.GET; 24 | import retrofit.http.POST; 25 | import retrofit.http.PUT; 26 | import retrofit.http.Path; 27 | 28 | import java.util.List; 29 | 30 | /** 31 | * @author Pete Cornish {@literal } 32 | */ 33 | public interface GatewayApi { 34 | @POST("/gateways") 35 | Response create(@Body Gateway gateway); 36 | 37 | @GET("/gateways") 38 | List list(); 39 | 40 | @GET("/gateways/{gatewayId}") 41 | Gateway fetch(@Path("gatewayId") String gatewayId); 42 | 43 | @PUT("/gateways") 44 | GatewayTestResponse test(@Body Gateway gateway); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/gateway/GatewayMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.gateway; 18 | 19 | import io.apiman.cli.command.gateway.model.Gateway; 20 | import io.apiman.cli.managerapi.command.common.command.ModelAction; 21 | 22 | /** 23 | * @author Pete Cornish {@literal } 24 | */ 25 | public interface GatewayMixin extends ModelAction { 26 | @Override 27 | default Class getApiClass() { 28 | return GatewayApi.class; 29 | } 30 | 31 | @Override 32 | default Class getModelClass() { 33 | return Gateway.class; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/gateway/command/GatewayCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.gateway.command; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.core.Command; 21 | import io.apiman.cli.managerapi.command.api.command.AbstractManagerCommand; 22 | import io.apiman.cli.managerapi.service.ManagementApiService; 23 | 24 | import javax.inject.Inject; 25 | import java.util.Map; 26 | 27 | /** 28 | * Root Command for managing gateways. 29 | * 30 | * @author Pete Cornish {@literal } 31 | */ 32 | @Parameters(commandDescription = "Manage gateways") 33 | public class GatewayCommand extends AbstractManagerCommand { 34 | 35 | @Inject 36 | public GatewayCommand(ManagementApiService managementApiService) { 37 | super(managementApiService); 38 | } 39 | 40 | @Override 41 | protected void populateCommands(Map> commandMap) { 42 | commandMap.put("create", GatewayCreateCommand.class); 43 | commandMap.put("show", GatewayShowCommand.class); 44 | commandMap.put("list", GatewayListCommand.class); 45 | commandMap.put("test", GatewayTestCommand.class); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/gateway/command/GatewayCreateCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.gateway.command; 18 | 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import io.apiman.cli.managerapi.service.ManagementApiService; 22 | 23 | import javax.inject.Inject; 24 | 25 | /** 26 | * Create a gateway. 27 | * 28 | * @author Pete Cornish {@literal } 29 | */ 30 | @Parameters(commandDescription = "Create a new gateway") 31 | public class GatewayCreateCommand extends AbstractGatewayCreateCommand { 32 | 33 | @Parameter(names = {"--name", "-n"}, description = "Name", required = true) 34 | private String name; 35 | 36 | @Inject 37 | public GatewayCreateCommand(ManagementApiService managementApiService) { 38 | super(managementApiService); 39 | } 40 | 41 | @Override 42 | protected String getGatewayName() { 43 | return name; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/gateway/command/GatewayListCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.gateway.command; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.gateway.model.Gateway; 21 | import io.apiman.cli.managerapi.command.common.command.ModelListCommand; 22 | import io.apiman.cli.managerapi.command.gateway.GatewayApi; 23 | import io.apiman.cli.managerapi.command.gateway.GatewayMixin; 24 | import io.apiman.cli.managerapi.service.ManagementApiService; 25 | 26 | import javax.inject.Inject; 27 | 28 | /** 29 | * List gateways. 30 | * 31 | * @author Pete Cornish {@literal } 32 | */ 33 | @Parameters(commandDescription = "List gateways") 34 | public class GatewayListCommand extends ModelListCommand 35 | implements GatewayMixin { 36 | @Inject 37 | public GatewayListCommand(ManagementApiService managementApiService) { 38 | super(managementApiService); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/gateway/command/GatewayShowCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.gateway.command; 18 | 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import io.apiman.cli.command.gateway.model.Gateway; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.managerapi.command.common.command.ModelShowCommand; 24 | import io.apiman.cli.managerapi.command.gateway.GatewayApi; 25 | import io.apiman.cli.managerapi.command.gateway.GatewayMixin; 26 | import io.apiman.cli.managerapi.service.ManagementApiService; 27 | 28 | import javax.inject.Inject; 29 | 30 | /** 31 | * Show a gateway. 32 | * 33 | * @author Pete Cornish {@literal } 34 | */ 35 | @Parameters(commandDescription = "Show a gateway") 36 | public class GatewayShowCommand extends ModelShowCommand 37 | implements GatewayMixin { 38 | 39 | @Parameter(names = { "--name", "-n"}, description = "Name") 40 | private String name; 41 | 42 | @Inject 43 | public GatewayShowCommand(ManagementApiService managementApiService) { 44 | super(managementApiService); 45 | } 46 | 47 | 48 | @Override 49 | protected String getModelId() throws CommandException { 50 | return name; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/org/OrgApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.org; 18 | 19 | import io.apiman.cli.command.org.model.Org; 20 | import retrofit.client.Response; 21 | import retrofit.http.Body; 22 | import retrofit.http.GET; 23 | import retrofit.http.POST; 24 | import retrofit.http.Path; 25 | 26 | /** 27 | * @author Pete Cornish {@literal } 28 | */ 29 | public interface OrgApi { 30 | @POST("/organizations") 31 | Response create(@Body Org organisation); 32 | 33 | @GET("/organizations/{orgName}") 34 | Org fetch(@Path("orgName") String orgName); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/org/OrgMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.org; 18 | 19 | import io.apiman.cli.command.org.model.Org; 20 | import io.apiman.cli.managerapi.command.common.command.ModelAction; 21 | 22 | /** 23 | * @author Pete Cornish {@literal } 24 | */ 25 | public interface OrgMixin extends ModelAction { 26 | @Override 27 | default Class getApiClass() { 28 | return OrgApi.class; 29 | } 30 | 31 | @Override 32 | default Class getModelClass() { 33 | return Org.class; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/org/command/OrgCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.org.command; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.core.Command; 21 | import io.apiman.cli.managerapi.command.api.command.AbstractManagerCommand; 22 | import io.apiman.cli.managerapi.service.ManagementApiService; 23 | 24 | import javax.inject.Inject; 25 | import java.util.Map; 26 | 27 | /** 28 | * Root Command for managing organisations. 29 | * 30 | * @author Pete Cornish {@literal } 31 | */ 32 | @Parameters(commandDescription = "Manage organisations") 33 | public class OrgCommand extends AbstractManagerCommand { 34 | 35 | @Inject 36 | public OrgCommand(ManagementApiService managementApiService) { 37 | super(managementApiService); 38 | } 39 | 40 | @Override 41 | protected void populateCommands(Map> commandMap) { 42 | commandMap.put("create", OrgCreateCommand.class); 43 | commandMap.put("show", OrgShowCommand.class); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/org/command/OrgCreateCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.org.command; 18 | 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import io.apiman.cli.command.org.model.Org; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.managerapi.command.common.command.ModelCreateCommand; 24 | import io.apiman.cli.managerapi.command.org.OrgApi; 25 | import io.apiman.cli.managerapi.command.org.OrgMixin; 26 | import io.apiman.cli.managerapi.service.ManagementApiService; 27 | 28 | import javax.inject.Inject; 29 | 30 | /** 31 | * Create an organisation. 32 | * 33 | * @author Pete Cornish {@literal } 34 | */ 35 | @Parameters(commandDescription = "Create organisation") 36 | public class OrgCreateCommand extends ModelCreateCommand 37 | implements OrgMixin { 38 | 39 | @Parameter(names = { "--name", "-n"}, description = "Name", required = true) 40 | private String name; 41 | 42 | @Parameter(names = { "--description", "-d"}, description = "Description") 43 | private String description; 44 | 45 | @Inject 46 | public OrgCreateCommand(ManagementApiService managementApiService) { 47 | super(managementApiService); 48 | } 49 | 50 | @Override 51 | protected Org buildModelInstance() throws CommandException { 52 | return new Org(name, description); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/org/command/OrgShowCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.org.command; 18 | 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import io.apiman.cli.command.org.model.Org; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.managerapi.command.common.command.ModelShowCommand; 24 | import io.apiman.cli.managerapi.command.org.OrgApi; 25 | import io.apiman.cli.managerapi.command.org.OrgMixin; 26 | import io.apiman.cli.managerapi.service.ManagementApiService; 27 | import org.apache.logging.log4j.LogManager; 28 | import org.apache.logging.log4j.Logger; 29 | 30 | import javax.inject.Inject; 31 | 32 | /** 33 | * Show an organisation. 34 | * 35 | * @author Pete Cornish {@literal } 36 | */ 37 | @Parameters(commandDescription = "Show organisation") 38 | public class OrgShowCommand extends ModelShowCommand implements OrgMixin { 39 | private static final Logger LOGGER = LogManager.getLogger(OrgShowCommand.class); 40 | 41 | @Parameter(names = { "--name", "-n"}, description = "Name") 42 | private String name; 43 | 44 | @Inject 45 | public OrgShowCommand(ManagementApiService managementApiService) { 46 | super(managementApiService); 47 | } 48 | 49 | @Override 50 | protected String getModelId() throws CommandException { 51 | return name; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/plugin/PluginApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.plugin; 18 | 19 | import io.apiman.cli.command.plugin.model.Plugin; 20 | import retrofit.client.Response; 21 | import retrofit.http.Body; 22 | import retrofit.http.GET; 23 | import retrofit.http.POST; 24 | import retrofit.http.Path; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * @author Pete Cornish {@literal } 30 | */ 31 | public interface PluginApi { 32 | @POST("/plugins") 33 | Response create(@Body Plugin plugin); 34 | 35 | @GET("/plugins") 36 | List list(); 37 | 38 | @GET("/plugins/{pluginId}") 39 | Plugin fetch(@Path("pluginId") String pluginId); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/plugin/PluginMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.plugin; 18 | 19 | import io.apiman.cli.command.plugin.model.Plugin; 20 | import io.apiman.cli.managerapi.command.common.command.ModelAction; 21 | 22 | /** 23 | * @author Pete Cornish {@literal } 24 | */ 25 | public interface PluginMixin extends ModelAction { 26 | @Override 27 | default Class getApiClass() { 28 | return PluginApi.class; 29 | } 30 | 31 | @Override 32 | default Class getModelClass() { 33 | return Plugin.class; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/plugin/command/PluginAddCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.plugin.command; 18 | 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import io.apiman.cli.command.plugin.model.Plugin; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.managerapi.command.common.command.ModelCreateCommand; 24 | import io.apiman.cli.managerapi.command.plugin.PluginApi; 25 | import io.apiman.cli.managerapi.command.plugin.PluginMixin; 26 | import io.apiman.cli.managerapi.service.ManagementApiService; 27 | 28 | import javax.inject.Inject; 29 | 30 | /** 31 | * Add a plugin. 32 | * 33 | * @author Pete Cornish {@literal } 34 | */ 35 | @Parameters(commandDescription = "Add a plugin") 36 | public class PluginAddCommand extends ModelCreateCommand 37 | implements PluginMixin { 38 | 39 | @Parameter(names = {"--groupId", "-g"}, description = "Group ID", required = true) 40 | private String groupId; 41 | 42 | @Parameter(names = {"--artifactId", "-a"}, description = "Artifact ID", required = true) 43 | private String artifactId; 44 | 45 | @Parameter(names = {"--version", "-v"}, description = "Version", required = true) 46 | private String version; 47 | 48 | @Parameter(names = {"--classifier", "-c"}, description = "Classifier") 49 | private String classifier; 50 | 51 | @Inject 52 | public PluginAddCommand(ManagementApiService managementApiService) { 53 | super(managementApiService); 54 | } 55 | 56 | @Override 57 | protected Plugin buildModelInstance() throws CommandException { 58 | return new Plugin(groupId, artifactId, classifier, version); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/plugin/command/PluginCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.plugin.command; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.core.Command; 21 | import io.apiman.cli.managerapi.command.api.command.AbstractManagerCommand; 22 | import io.apiman.cli.managerapi.service.ManagementApiService; 23 | 24 | import javax.inject.Inject; 25 | import java.util.Map; 26 | 27 | /** 28 | * Root Command for managing plugins. 29 | * 30 | * @author Pete Cornish {@literal } 31 | */ 32 | @Parameters(commandDescription = "Manage plugins") 33 | public class PluginCommand extends AbstractManagerCommand { 34 | @Inject 35 | public PluginCommand(ManagementApiService managementApiService) { 36 | super(managementApiService); 37 | } 38 | 39 | @Override 40 | protected void populateCommands(Map> commandMap) { 41 | commandMap.put("add", PluginAddCommand.class); 42 | commandMap.put("show", PluginShowCommand.class); 43 | commandMap.put("list", PluginListCommand.class); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/plugin/command/PluginListCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.plugin.command; 18 | 19 | import com.beust.jcommander.Parameters; 20 | import io.apiman.cli.command.plugin.model.Plugin; 21 | import io.apiman.cli.managerapi.command.common.command.ModelListCommand; 22 | import io.apiman.cli.managerapi.command.plugin.PluginApi; 23 | import io.apiman.cli.managerapi.command.plugin.PluginMixin; 24 | import io.apiman.cli.managerapi.service.ManagementApiService; 25 | 26 | import javax.inject.Inject; 27 | 28 | /** 29 | * List plugins. 30 | * 31 | * @author Pete Cornish {@literal } 32 | */ 33 | @Parameters(commandDescription = "List plugins") 34 | public class PluginListCommand extends ModelListCommand 35 | implements PluginMixin { 36 | @Inject 37 | public PluginListCommand(ManagementApiService managementApiService) { 38 | super(managementApiService); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/command/plugin/command/PluginShowCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.plugin.command; 18 | 19 | import com.beust.jcommander.Parameter; 20 | import com.beust.jcommander.Parameters; 21 | import io.apiman.cli.command.plugin.model.Plugin; 22 | import io.apiman.cli.exception.CommandException; 23 | import io.apiman.cli.managerapi.command.common.command.ModelShowCommand; 24 | import io.apiman.cli.managerapi.command.plugin.PluginApi; 25 | import io.apiman.cli.managerapi.command.plugin.PluginMixin; 26 | import io.apiman.cli.managerapi.service.ManagementApiService; 27 | 28 | import javax.inject.Inject; 29 | 30 | /** 31 | * Show a plugin. 32 | * 33 | * @author Pete Cornish {@literal } 34 | */ 35 | @Parameters(commandDescription = "Show a plugin") 36 | public class PluginShowCommand extends ModelShowCommand 37 | implements PluginMixin { 38 | 39 | @Parameter(names = { "--id", "-i"}, description = "Plugin ID") 40 | private String id; 41 | 42 | @Inject 43 | public PluginShowCommand(ManagementApiService managementApiService) { 44 | super(managementApiService); 45 | } 46 | 47 | @Override 48 | protected String getModelId() throws CommandException { 49 | return id; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/management/api/StatusApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.management.api; 18 | 19 | import retrofit.client.Response; 20 | import retrofit.http.GET; 21 | 22 | /** 23 | * Models the status check API. 24 | * 25 | * @author Pete Cornish {@literal } 26 | */ 27 | public interface StatusApi { 28 | @GET("/system/status") 29 | Response checkStatus(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/management/binding/ManagementApiBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.management.binding; 18 | 19 | import com.google.inject.BindingAnnotation; 20 | import io.apiman.cli.managerapi.command.common.model.ManagementApiVersion; 21 | 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.Target; 25 | 26 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 27 | 28 | /** 29 | * Specialises an injection binding between an interface and implementation class. The {@link #value()} 30 | * represents the API interface that the implementation provides. 31 | * 32 | * @author Pete Cornish {@literal } 33 | */ 34 | @Retention(RUNTIME) 35 | @Target({ElementType.TYPE}) 36 | @BindingAnnotation 37 | public @interface ManagementApiBinding { 38 | Class value(); 39 | 40 | ManagementApiVersion serverVersion() default ManagementApiVersion.UNSPECIFIED; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/management/binding/ManagementApiBindings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.management.binding; 18 | 19 | import io.apiman.cli.managerapi.command.common.model.ManagementApiVersion; 20 | 21 | /** 22 | * Convenience methods for instantiating {@link ManagementApiBinding}s. 23 | * 24 | * @author Pete Cornish {@literal } 25 | */ 26 | public class ManagementApiBindings { 27 | public static ManagementApiBinding boundTo(Class apiClass) { 28 | return new ManagementApiBindingImpl(apiClass); 29 | } 30 | 31 | public static ManagementApiBinding boundTo(Class apiClass, ManagementApiVersion serverVersion) { 32 | return new ManagementApiBindingImpl(apiClass, serverVersion); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/management/factory/AbstractManagementApiFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.management.factory; 18 | 19 | import io.apiman.cli.util.AuthUtil; 20 | import retrofit.RestAdapter; 21 | import retrofit.converter.JacksonConverter; 22 | 23 | import static io.apiman.cli.util.AuthUtil.HEADER_AUTHORIZATION; 24 | import static io.apiman.cli.util.MappingUtil.JSON_MAPPER; 25 | 26 | /** 27 | * Builds a Management API client proxy for a given API interface. 28 | * 29 | * @param the requested API interface 30 | * @param the actual API interface 31 | * @author Pete Cornish {@literal } 32 | */ 33 | public abstract class AbstractManagementApiFactory implements ManagementApiFactory { 34 | /** 35 | * @param apiClass the Class for which to build a client 36 | * @param username the management API username 37 | * @param password the management API password 38 | * @param debugLogging whether debug logging should be enabled 39 | * @return an API client for the given Class 40 | */ 41 | protected A buildClient(Class apiClass, String endpoint, String username, String password, boolean debugLogging) { 42 | final RestAdapter.Builder builder = new RestAdapter.Builder() // 43 | .setConverter(new JacksonConverter(JSON_MAPPER)) 44 | .setEndpoint(endpoint) 45 | .setRequestInterceptor(request -> { 46 | request.addHeader(HEADER_AUTHORIZATION, AuthUtil.buildAuthString(username, password)); 47 | }); 48 | 49 | if (debugLogging) { 50 | builder.setLogLevel(RestAdapter.LogLevel.FULL); 51 | } 52 | 53 | return builder.build().create(apiClass); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/management/factory/ManagementApiFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.management.factory; 18 | 19 | /** 20 | * Builds a Management API client proxy for a given API interface. 21 | * 22 | * @param the API interface 23 | * @author Pete Cornish {@literal } 24 | */ 25 | public interface ManagementApiFactory { 26 | /** 27 | * @param username the management API username 28 | * @param password the management API password 29 | * @param debugLogging whether debug logging should be enabled 30 | * @return an API client for the given Class 31 | */ 32 | T build(String endpoint, String username, String password, boolean debugLogging); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/management/factory/SimpleManagementApiFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.management.factory; 18 | 19 | /** 20 | * Builds a Management API client proxy for a given API interface. 21 | * 22 | * @author Pete Cornish {@literal } 23 | */ 24 | public class SimpleManagementApiFactoryImpl extends AbstractManagementApiFactory { 25 | private final Class apiClass; 26 | 27 | public SimpleManagementApiFactoryImpl(Class apiClass) { 28 | this.apiClass = apiClass; 29 | } 30 | 31 | @Override 32 | public T build(String endpoint, String username, String password, boolean debugLogging) { 33 | return buildClient(apiClass, endpoint, username, password, debugLogging); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/service/ApiService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.service; 18 | 19 | import io.apiman.cli.managerapi.command.common.model.ManagementApiVersion; 20 | 21 | /** 22 | * Manages APIs. 23 | * 24 | * @author Pete Cornish {@literal } 25 | */ 26 | public interface ApiService { 27 | String STATE_READY = "READY"; 28 | String STATE_PUBLISHED = "PUBLISHED"; 29 | String STATE_RETIRED = "RETIRED"; 30 | 31 | /** 32 | * Return the current state of the API. 33 | * 34 | * @param serverVersion the management server API version 35 | * @param orgName the organisation name 36 | * @param apiName the API name 37 | * @param apiVersion the API version 38 | * @return the API state 39 | */ 40 | String fetchCurrentState(ManagementApiVersion serverVersion, String orgName, String apiName, String apiVersion); 41 | 42 | /** 43 | * Publish the API, if it is in the 'Ready' state. 44 | * 45 | * @param serverVersion the management server API version 46 | * @param orgName the organisation name 47 | * @param apiName the API name 48 | * @param apiVersion the API version 49 | */ 50 | void publish(ManagementApiVersion serverVersion, String orgName, String apiName, String apiVersion); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/service/DeclarativeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.service; 18 | 19 | import io.apiman.cli.command.declarative.model.DeclarativeApi; 20 | import io.apiman.cli.command.declarative.model.DeclarativeGateway; 21 | import io.apiman.cli.command.declarative.model.DeclarativeOrg; 22 | import io.apiman.cli.managerapi.command.common.model.ManagementApiVersion; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Applies changes in a declarative fashion. 28 | * 29 | * @author Pete Cornish {@literal } 30 | */ 31 | public interface DeclarativeService { 32 | /** 33 | * Add gateways if they are not present. 34 | * 35 | * @param gateways the gateways to add. 36 | */ 37 | void applyGateways(List gateways); 38 | 39 | /** 40 | * Add the organisation if it is not present. 41 | * 42 | * @param org the organisation to add. 43 | */ 44 | void applyOrg(DeclarativeOrg org); 45 | 46 | /** 47 | * Add APIs to the specified organisation, if they are not present, then configure them. 48 | * 49 | * @param serverVersion the management server version. 50 | * @param apis the APIs to add. 51 | * @param orgName the name of the organisation. 52 | */ 53 | void applyApis(ManagementApiVersion serverVersion, List apis, String orgName); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/service/PluginService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.service; 18 | 19 | import io.apiman.cli.command.plugin.model.Plugin; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Manages plugins. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | public interface PluginService { 29 | /** 30 | * Add plugins if they are not present. 31 | * 32 | * @param plugins the plugins to add. 33 | */ 34 | void addPlugins(List plugins); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/service/PolicyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.service; 18 | 19 | import io.apiman.cli.command.api.model.ApiPolicy; 20 | import io.apiman.cli.managerapi.command.common.model.ManagementApiVersion; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * Manages policies. 26 | * 27 | * @author Pete Cornish {@literal } 28 | */ 29 | public interface PolicyService { 30 | /** 31 | * Fetch the policies attached to the specified API. 32 | * 33 | * @param serverVersion the management server API version 34 | * @param orgName the organisation name 35 | * @param apiName the API name 36 | * @param apiVersion the API version 37 | * @return the policies 38 | */ 39 | List fetchPolicies(ManagementApiVersion serverVersion, String orgName, 40 | String apiName, String apiVersion); 41 | 42 | /** 43 | * Apply the policies to the specified API. 44 | * 45 | * @param serverVersion the management server API version 46 | * @param orgName the organisation name 47 | * @param apiName the API name 48 | * @param apiVersion the API version 49 | * @param apiPolicies the policies to apply. 50 | * @param policyName the policy name 51 | * @param apiPolicy the policy to apply 52 | */ 53 | void applyPolicies(ManagementApiVersion serverVersion, String orgName, 54 | String apiName, String apiVersion, List apiPolicies, 55 | String policyName, ApiPolicy apiPolicy); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/managerapi/service/ServiceModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.service; 18 | 19 | import com.google.inject.AbstractModule; 20 | import com.google.inject.Singleton; 21 | 22 | /** 23 | * Dependency injection configuration for services. 24 | * 25 | * @author Pete Cornish {@literal } 26 | */ 27 | public class ServiceModule extends AbstractModule { 28 | @Override 29 | protected void configure() { 30 | bind(ManagementApiService.class).to(ManagementApiServiceImpl.class).in(Singleton.class); 31 | bind(ApiService.class).to(ApiServiceImpl.class).in(Singleton.class); 32 | bind(PluginService.class).to(PluginServiceImpl.class).in(Singleton.class); 33 | bind(PolicyService.class).to(PolicyServiceImpl.class).in(Singleton.class); 34 | bind(DeclarativeService.class).to(DeclarativeServiceImpl.class).in(Singleton.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/services/WaitService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.services; 18 | 19 | /** 20 | * @author Marc Savy {@literal } 21 | */ 22 | public interface WaitService { 23 | 24 | /** 25 | * Wait for the server to be ready. 26 | * 27 | * @param waitTime the time, in seconds, to wait 28 | */ 29 | void waitForServer(int waitTime); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/util/AuthUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.util; 18 | 19 | import com.google.common.io.BaseEncoding; 20 | 21 | /** 22 | * Utility class for authenticating access to the management API. 23 | * 24 | * @author Pete Cornish {@literal } 25 | */ 26 | public final class AuthUtil { 27 | /** 28 | * Authorization HTTP header. 29 | */ 30 | public static final String HEADER_AUTHORIZATION = "Authorization"; 31 | 32 | /** 33 | * Basic Authorization scheme prefix. 34 | */ 35 | private static final String AUTH_BASIC = "Basic "; 36 | 37 | /** 38 | * Management API username. 39 | */ 40 | public static final String DEFAULT_SERVER_USERNAME = "admin"; 41 | 42 | /** 43 | * Management API password. 44 | */ 45 | public static final String DEFAULT_SERVER_PASSWORD = "admin123!"; 46 | 47 | /** 48 | * Encoded credentials for Basic auth. 49 | */ 50 | public static final String BASIC_AUTH_VALUE = buildAuthString(DEFAULT_SERVER_USERNAME, DEFAULT_SERVER_PASSWORD); 51 | 52 | private AuthUtil() { 53 | } 54 | 55 | /** 56 | * @param username the username 57 | * @param password the password 58 | * @return an basic authentication string for the given credentials 59 | */ 60 | public static String buildAuthString(String username, String password) { 61 | return AUTH_BASIC + BaseEncoding.base64().encode((username + ":" + password).getBytes()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/util/Functions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.util; 18 | 19 | import java.util.Optional; 20 | import java.util.function.Consumer; 21 | import java.util.function.Predicate; 22 | 23 | /** 24 | * Functional convenience methods. 25 | * 26 | * @author Pete Cornish {@literal } 27 | */ 28 | public class Functions { 29 | private Optional optional; 30 | 31 | private Functions(Optional optional) { 32 | this.optional = optional; 33 | } 34 | 35 | public static Functions of(Optional optional) { 36 | return new Functions<>(optional); 37 | } 38 | 39 | public Functions ifPresent(Consumer c) { 40 | optional.ifPresent(c); 41 | return this; 42 | } 43 | 44 | public Functions ifNotPresent(Runnable r) { 45 | if (!optional.isPresent()) { 46 | r.run(); 47 | } 48 | return this; 49 | } 50 | 51 | public static Predicate not(Predicate p) { 52 | return t -> !p.test(t); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/io/apiman/cli/util/InjectionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.util; 18 | 19 | import com.google.inject.Guice; 20 | import com.google.inject.Injector; 21 | import io.apiman.cli.managerapi.management.ManagementApiFactoryModule; 22 | import io.apiman.cli.managerapi.service.ServiceModule; 23 | 24 | /** 25 | * Manages the injection context. 26 | * 27 | * @author Pete Cornish {@literal } 28 | */ 29 | public final class InjectionUtil { 30 | private static Injector injector; 31 | 32 | private InjectionUtil() { 33 | } 34 | 35 | public synchronized static Injector getInjector() { 36 | if (null == injector) { 37 | injector = Guice.createInjector( 38 | new ManagementApiFactoryModule(), 39 | new ServiceModule() 40 | ); 41 | } 42 | return injector; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/test/java/io/apiman/cli/ExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Andrew Haines 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli; 18 | 19 | import io.apiman.cli.common.IntegrationTest; 20 | import io.apiman.cli.util.AuthUtil; 21 | import org.junit.Rule; 22 | import org.junit.Test; 23 | import org.junit.contrib.java.lang.system.ExpectedSystemExit; 24 | import org.junit.experimental.categories.Category; 25 | 26 | /** 27 | * @author Andrew Haines {@literal } 28 | */ 29 | @Category(IntegrationTest.class) 30 | public class ExceptionTest { 31 | private static final String INVALID_URL = "this is not a valid url"; 32 | 33 | @Rule 34 | public final ExpectedSystemExit exit = ExpectedSystemExit.none(); 35 | 36 | @Test 37 | public void testExitWithCode255OnException() { 38 | exit.expectSystemExitWithStatus(255); 39 | 40 | Cli.main("manager", 41 | "gateway", "list", 42 | "--debug", 43 | "--server", INVALID_URL, 44 | "--serverUsername", AuthUtil.DEFAULT_SERVER_USERNAME, 45 | "--serverPassword", AuthUtil.DEFAULT_SERVER_PASSWORD); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/io/apiman/cli/common/BaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.common; 18 | 19 | import com.google.common.collect.Lists; 20 | import io.apiman.cli.util.MappingUtil; 21 | 22 | import java.io.IOException; 23 | import java.net.MalformedURLException; 24 | import java.net.URI; 25 | import java.net.URISyntaxException; 26 | import java.nio.file.Files; 27 | import java.nio.file.Path; 28 | import java.nio.file.Paths; 29 | import java.util.List; 30 | 31 | /** 32 | * Convenience methods for tests. 33 | * 34 | * @author Pete Cornish {@literal } 35 | */ 36 | public abstract class BaseTest { 37 | protected T expectJson(String resource, Class klazz) throws URISyntaxException, MalformedURLException { 38 | return MappingUtil.readJsonValue(getResourceAsURI(resource).toURL(), klazz); 39 | } 40 | 41 | protected URI getResourceAsURI(String resource) throws URISyntaxException { 42 | return BaseTest.class.getResource(resource).toURI(); 43 | } 44 | 45 | protected Path getResourceAsPath(String resource) throws URISyntaxException { 46 | return Paths.get(getResourceAsURI(resource)); 47 | } 48 | 49 | protected List getResourceAsPathList(String resource) throws URISyntaxException { 50 | final List paths = Lists.newArrayList(); 51 | paths.add(getResourceAsPath(resource)); 52 | return paths; 53 | } 54 | 55 | protected String getResourceAsString(String resource) throws URISyntaxException, IOException { 56 | return new String(Files.readAllBytes(Paths.get(getResourceAsURI(resource)))); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/io/apiman/cli/common/IntegrationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.common; 18 | 19 | /** 20 | * JUnit category for marking integration tests. 21 | * 22 | * @author Pete Cornish {@literal } 23 | */ 24 | public @interface IntegrationTest { 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/io/apiman/cli/managerapi/command/org/OrgTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.managerapi.command.org; 18 | 19 | import io.apiman.cli.Cli; 20 | import io.apiman.cli.common.BaseIntegrationTest; 21 | import io.apiman.cli.common.IntegrationTest; 22 | import io.apiman.cli.util.AuthUtil; 23 | 24 | import org.junit.FixMethodOrder; 25 | import org.junit.Test; 26 | import org.junit.experimental.categories.Category; 27 | import org.junit.runners.MethodSorters; 28 | 29 | /** 30 | * @author Pete Cornish {@literal } 31 | */ 32 | @Category(IntegrationTest.class) 33 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 34 | public class OrgTest extends BaseIntegrationTest { 35 | 36 | @Test 37 | public void test1_create() { 38 | createOrg("test-org"); 39 | } 40 | 41 | @Test 42 | public void test2_fetch() { 43 | Cli.main("manager", 44 | "org", "show", 45 | "--debug", 46 | "--server", getApimanUrl(), 47 | "--serverUsername", AuthUtil.DEFAULT_SERVER_USERNAME, 48 | "--serverPassword", AuthUtil.DEFAULT_SERVER_PASSWORD, 49 | "--name", "test-org"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/io/apiman/cli/service/ManagementApiServiceImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.service; 18 | 19 | import io.apiman.cli.managerapi.command.common.model.ManagementApiVersion; 20 | import io.apiman.cli.managerapi.command.org.OrgApi; 21 | import io.apiman.cli.managerapi.service.ManagementApiServiceImpl; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertTrue; 27 | 28 | /** 29 | * Tests for {@link ManagementApiServiceImpl}. 30 | * 31 | * @author Pete Cornish {@literal } 32 | */ 33 | public class ManagementApiServiceImplTest { 34 | private static final String URL = "http://example.com"; 35 | 36 | /** 37 | * Unit under test. 38 | */ 39 | private ManagementApiServiceImpl service; 40 | 41 | @Before 42 | public void setUp() throws Exception { 43 | service = new ManagementApiServiceImpl(); 44 | } 45 | 46 | @Test 47 | public void testBuildServerApiClient() throws Exception { 48 | // test 49 | final OrgApi actual = service.buildServerApiClient( 50 | OrgApi.class, ManagementApiVersion.UNSPECIFIED, URL, "username", "password", true); 51 | 52 | // assertions 53 | assertNotNull(actual); 54 | assertTrue(OrgApi.class.isAssignableFrom(actual.getClass())); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/io/apiman/cli/support/TestModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.support; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | import com.fasterxml.jackson.annotation.JsonInclude; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import com.google.common.base.Objects; 23 | 24 | /** 25 | * Model for tests. 26 | * 27 | * @author Pete Cornish {@literal } 28 | */ 29 | @JsonInclude(JsonInclude.Include.NON_NULL) 30 | @JsonIgnoreProperties(ignoreUnknown = true) 31 | public class TestModel { 32 | @JsonProperty 33 | private String key; 34 | 35 | @Override 36 | public boolean equals(Object o) { 37 | if (this == o) return true; 38 | if (o == null || getClass() != o.getClass()) return false; 39 | TestModel testModel = (TestModel) o; 40 | return Objects.equal(key, testModel.key); 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return Objects.hashCode(key); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/io/apiman/cli/util/MappingUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Pete Cornish 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.apiman.cli.util; 18 | 19 | import io.apiman.cli.support.TestModel; 20 | import org.junit.Test; 21 | 22 | import java.util.Map; 23 | 24 | import static com.google.common.collect.Maps.newHashMap; 25 | import static org.junit.Assert.assertEquals; 26 | import static org.junit.Assert.assertNotNull; 27 | 28 | /** 29 | * Tests for {@link MappingUtil}. 30 | * 31 | * @author Pete Cornish {@literal } 32 | */ 33 | public class MappingUtilTest { 34 | @Test 35 | public void testSafeWriteValueAsJson_Populated() throws Exception { 36 | // test data 37 | final Map input = newHashMap(); 38 | input.put("key", "value"); 39 | 40 | // test 41 | final String actual = MappingUtil.safeWriteValueAsJson(input); 42 | 43 | // assertions 44 | assertNotNull(actual); 45 | assertEquals("Object should be serialised to JSON (check ignores whitespace)", 46 | "{\"key\":\"value\"}", actual.replaceAll("\\s+","")); 47 | } 48 | 49 | @Test 50 | public void testSafeWriteValueAsJson_Null() throws Exception { 51 | // test data 52 | final Map input = null; 53 | 54 | // test 55 | final String actual = MappingUtil.safeWriteValueAsJson(input); 56 | 57 | // assertions 58 | assertEquals("null", actual); 59 | } 60 | 61 | @Test 62 | public void testMap() throws Exception { 63 | // test data 64 | final TestModel input = new TestModel(); 65 | 66 | // test 67 | final TestModel actual = MappingUtil.map(input, TestModel.class); 68 | 69 | // assertions 70 | assertEquals(input, actual); 71 | } 72 | } -------------------------------------------------------------------------------- /src/test/resources/common-api-config.yml: -------------------------------------------------------------------------------- 1 | # Common configuration and policies across all APIs. 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | plugins: 13 | - groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | - name: "log-policy" 17 | groupId: "io.apiman.plugins" 18 | artifactId: "apiman-plugins-log-policy" 19 | version: "1.4.3.Final" 20 | shared: 21 | policies: 22 | - $id: "alwaysFirstPolicy" 23 | plugin: "log-policy" 24 | name: "log-headers-policy" 25 | config: 26 | direction: "both" 27 | - $id: "alwaysLastPolicy" 28 | name: "CachingPolicy" 29 | config: 30 | ttl: 60 31 | org: 32 | name: "test" 33 | description: "Test organisation" 34 | # Configuration and policies in the common org section are applied to each API. 35 | common: 36 | # Common configuration is overridden by API specific values. 37 | config: 38 | endpointType: "rest" 39 | public: true 40 | gateway: "test-gw" 41 | # Common policies are injected at either the start or the end of the policy chain for each API. 42 | policies: 43 | first: 44 | - "alwaysFirstPolicy" 45 | last: 46 | - "alwaysLastPolicy" 47 | apis: 48 | - name: "common-api-config" 49 | description: "Example API" 50 | version: "1.0" 51 | published: true 52 | config: 53 | endpoint: "http://example.com" 54 | policies: [] 55 | -------------------------------------------------------------------------------- /src/test/resources/gateway/command/api/basic-expectation.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "woohooapiman", 4 | "apiId" : "mycoolapi", 5 | "version" : "1.0", 6 | "endpoint" : "http://example.com", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { 10 | "authorization.type" : "basic", 11 | "basic-auth.requireSSL" : "false", 12 | "basic-auth.username" : "user", 13 | "basic-auth.password" : "ILoveApiman" 14 | }, 15 | "parsePayload" : false, 16 | "apiPolicies" : [ { 17 | "policyJsonConfig" : "null", 18 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 19 | } ], 20 | "maxPayloadBufferSize" : 0 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/gateway/command/api/basic.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman example 2 | --- 3 | system: 4 | gateways: 5 | - name: "thegateway" 6 | type: "REST" 7 | config: 8 | endpoint: "http://localhost:8080/apiman-gateway-api" 9 | username: "apimanager" 10 | password: "apiman123!" 11 | plugins: 12 | - name: "test-policy-plugin" 13 | groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "woohooapiman" 18 | apis: 19 | - name: "mycoolapi" 20 | version: "1.0" 21 | config: 22 | endpoint: "http://example.com" 23 | endpointType: "rest" 24 | security: 25 | authorizationType: "basic" 26 | username: "user" 27 | password: "ILoveApiman" 28 | public: true 29 | gateway: "thegateway" 30 | policies: 31 | - plugin: "test-policy-plugin" 32 | -------------------------------------------------------------------------------- /src/test/resources/gateway/command/apply/basic-expectation.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "theorgname", 4 | "apiId" : "mycoolapi", 5 | "version" : "1.0", 6 | "endpoint" : "http://example.com", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { 10 | "authorization.type" : "basic", 11 | "basic-auth.requireSSL" : "false", 12 | "basic-auth.username" : "user", 13 | "basic-auth.password" : "ILoveApiman" 14 | }, 15 | "parsePayload" : false, 16 | "apiPolicies" : [ { 17 | "policyJsonConfig" : "null", 18 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 19 | } ], 20 | "maxPayloadBufferSize" : 0 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/gateway/command/apply/basic.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman example 2 | --- 3 | system: 4 | gateways: 5 | - name: "thegateway" 6 | type: "REST" 7 | config: 8 | endpoint: "http://localhost:8080/apiman-gateway-api" 9 | username: "apimanager" 10 | password: "apiman123!" 11 | plugins: 12 | - name: "test-policy-plugin" 13 | groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "theorgname" 18 | apis: 19 | - name: "mycoolapi" 20 | version: "1.0" 21 | config: 22 | endpoint: "http://example.com" 23 | endpointType: "rest" 24 | security: 25 | authorizationType: "basic" 26 | username: "user" 27 | password: "ILoveApiman" 28 | public: true 29 | gateway: "thegateway" 30 | policies: 31 | - plugin: "test-policy-plugin" 32 | -------------------------------------------------------------------------------- /src/test/resources/gateway/command/apply/multi-version-expectation-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "seychelles", 4 | "apiId" : "mahe", 5 | "version" : "1.0", 6 | "endpoint" : "http://localhost:8080/services/echo", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { }, 10 | "parsePayload" : false, 11 | "apiPolicies" : [ { 12 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 13 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 14 | }, { 15 | "policyJsonConfig" : "{\n \"foo\" : 123\n}", 16 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 17 | } ], 18 | "maxPayloadBufferSize" : 0 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/gateway/command/apply/multi-version-expectation-2.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "seychelles", 4 | "apiId" : "mahe", 5 | "version" : "2.0", 6 | "endpoint" : "http://localhost:8080/something/different", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { }, 10 | "parsePayload" : false, 11 | "apiPolicies" : [ { 12 | "policyJsonConfig" : "{\n \"ttl\" : 600\n}", 13 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 14 | }, { 15 | "policyJsonConfig" : "{\n \"foo\" : 1234\n}", 16 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 17 | } ], 18 | "maxPayloadBufferSize" : 0 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/gateway/command/apply/multi-version.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman gateway declaration 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | type: "REST" 7 | config: 8 | endpoint: "http://localhost:8080/apiman-gateway-api" 9 | username: "apimanager" 10 | password: "apiman123!" 11 | plugins: 12 | - name: TestPolicy 13 | groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "seychelles" 18 | apis: 19 | - name: "mahe" 20 | version: "1.0" 21 | config: 22 | endpoint: "http://localhost:8080/services/echo" 23 | endpointType: "rest" 24 | public: true 25 | gateway: "test-gw" 26 | policies: 27 | - name: "CachingPolicy" 28 | config: 29 | ttl: 60 30 | - plugin: TestPolicy 31 | config: 32 | foo: 123 33 | 34 | - name: "mahe" 35 | version: "2.0" 36 | config: 37 | endpoint: "http://localhost:8080/something/different" 38 | endpointType: "rest" 39 | public: true 40 | gateway: "test-gw" 41 | policies: 42 | - name: "CachingPolicy" 43 | config: 44 | ttl: 600 45 | - plugin: TestPolicy 46 | config: 47 | foo: 1234 48 | -------------------------------------------------------------------------------- /src/test/resources/gateway/common-api-config-expectation.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "test", 4 | "apiId" : "common-api-config", 5 | "version" : "1.0", 6 | "endpoint" : "http://example.com", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { }, 10 | "parsePayload" : false, 11 | "apiPolicies" : [ { 12 | "policyJsonConfig" : "{\n \"direction\" : \"both\"\n}", 13 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-log-policy:1.4.3.Final:war/io.apiman.plugins.log_policy.LogHeadersPolicy" 14 | }, { 15 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 16 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 17 | } ], 18 | "maxPayloadBufferSize" : 0 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/gateway/generateHeadless/expected-headless_plugin-and-builtin-policies.json: -------------------------------------------------------------------------------- 1 | { 2 | "apis" : [ { 3 | "publicAPI" : true, 4 | "organizationId" : "test", 5 | "apiId" : "example", 6 | "version" : "1.0", 7 | "endpoint" : "http://localhost:8080/services/echo", 8 | "endpointType" : "rest", 9 | "endpointContentType" : null, 10 | "endpointProperties" : { }, 11 | "parsePayload" : false, 12 | "apiPolicies" : [ { 13 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 14 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 15 | }, { 16 | "policyJsonConfig" : "{\n \"foo\" : 123\n}", 17 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 18 | } ] 19 | } ], 20 | "clients" : [ ] 21 | } -------------------------------------------------------------------------------- /src/test/resources/gateway/generateHeadless/expected-multiple-gateways-2.json: -------------------------------------------------------------------------------- 1 | { 2 | "apis" : [ { 3 | "publicAPI" : true, 4 | "organizationId" : "test", 5 | "apiId" : "example", 6 | "version" : "1.0", 7 | "endpoint" : "http://localhost:8080/services/echo", 8 | "endpointType" : "rest", 9 | "endpointContentType" : null, 10 | "endpointProperties" : { }, 11 | "parsePayload" : false, 12 | "apiPolicies" : [ { 13 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 14 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 15 | }, { 16 | "policyJsonConfig" : "{\n \"foo\" : 123\n}", 17 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 18 | } ], 19 | "maxPayloadBufferSize" : 0 20 | } ], 21 | "clients" : [ ] 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/gateway/generateHeadless/expected-multiple-gateways.json: -------------------------------------------------------------------------------- 1 | { 2 | "apis" : [ { 3 | "publicAPI" : true, 4 | "organizationId" : "test", 5 | "apiId" : "foo", 6 | "version" : "2.0", 7 | "endpoint" : "http://localhost:8080/services/echo", 8 | "endpointType" : "rest", 9 | "endpointContentType" : null, 10 | "endpointProperties" : { }, 11 | "parsePayload" : false, 12 | "apiPolicies" : [ { 13 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 14 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 15 | }, { 16 | "policyJsonConfig" : "{\n \"foo\" : 123\n}", 17 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 18 | } ], 19 | "maxPayloadBufferSize" : 0 20 | } ], 21 | "clients" : [ ] 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/gateway/generateHeadless/plugin-and-builtin-policies.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman gateway declaration 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | type: "REST" 7 | config: 8 | endpoint: "http://localhost:8080/apiman-gateway-api" 9 | username: "apimanager" 10 | password: "apiman123!" 11 | plugins: 12 | - name: TestPolicy 13 | groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "test" 18 | apis: 19 | - name: "example" 20 | version: "1.0" 21 | config: 22 | endpoint: "http://localhost:8080/services/echo" 23 | endpointType: "rest" 24 | public: true 25 | gateway: "test-gw" 26 | policies: 27 | - name: "CachingPolicy" 28 | config: 29 | ttl: 60 30 | - plugin: TestPolicy 31 | config: 32 | foo: 123 33 | -------------------------------------------------------------------------------- /src/test/resources/gateway/generateHeadless/plugin-and-builtin-policies_multiple-gateways.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman gateway declaration 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | type: "REST" 7 | - name: "test-gw-2" 8 | type: "REST" 9 | plugins: 10 | - name: TestPolicy 11 | groupId: "io.apiman.plugins" 12 | artifactId: "apiman-plugins-test-policy" 13 | version: "1.4.3.Final" 14 | org: 15 | name: "test" 16 | apis: 17 | - name: "example" 18 | version: "1.0" 19 | config: 20 | endpoint: "http://localhost:8080/services/echo" 21 | endpointType: "rest" 22 | public: true 23 | gateway: "test-gw" 24 | policies: 25 | - name: "CachingPolicy" 26 | config: 27 | ttl: 60 28 | - plugin: TestPolicy 29 | config: 30 | foo: 123 31 | # 32 | - name: "foo" 33 | version: "2.0" 34 | config: 35 | endpoint: "http://localhost:8080/services/echo" 36 | endpointType: "rest" 37 | public: true 38 | gateway: "test-gw-2" # NOTE GATEWAY 2 39 | policies: 40 | - name: "CachingPolicy" 41 | config: 42 | ttl: 60 43 | - plugin: TestPolicy 44 | config: 45 | foo: 123 46 | -------------------------------------------------------------------------------- /src/test/resources/gateway/generateHeadless/transform-name.json: -------------------------------------------------------------------------------- 1 | { 2 | "apis" : [ { 3 | "publicAPI" : true, 4 | "organizationId" : "test", 5 | "apiId" : "example", 6 | "version" : "1.0", 7 | "endpoint" : "http://localhost:8080/services/echo", 8 | "endpointType" : "rest", 9 | "endpointContentType" : null, 10 | "endpointProperties" : { }, 11 | "parsePayload" : false, 12 | "apiPolicies" : [ { 13 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 14 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 15 | }, { 16 | "policyJsonConfig" : "{\n \"foo\" : 123\n}", 17 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 18 | } ], 19 | "maxPayloadBufferSize" : 0 20 | } ], 21 | "clients" : [ ] 22 | } -------------------------------------------------------------------------------- /src/test/resources/gateway/generateHeadless/transform-name.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman gateway declaration 2 | --- 3 | system: 4 | gateways: 5 | - name: "gateway with various spaces in original ᠎ name and forward slash /" 6 | type: "REST" 7 | plugins: 8 | - name: TestPolicy 9 | groupId: "io.apiman.plugins" 10 | artifactId: "apiman-plugins-test-policy" 11 | version: "1.4.3.Final" 12 | org: 13 | name: "test" 14 | apis: 15 | - name: "example" 16 | version: "1.0" 17 | config: 18 | endpoint: "http://localhost:8080/services/echo" 19 | endpointType: "rest" 20 | public: true 21 | gateway: "gateway with various spaces in original ᠎ name and forward slash /" 22 | policies: 23 | - name: "CachingPolicy" 24 | config: 25 | ttl: 60 26 | - plugin: TestPolicy 27 | config: 28 | foo: 123 29 | -------------------------------------------------------------------------------- /src/test/resources/gateway/multiple-versions-expectation-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "test", 4 | "apiId" : "multi-version-example", 5 | "version" : "2.0", 6 | "endpoint" : "http://example.com/v2", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { }, 10 | "parsePayload" : false, 11 | "apiPolicies" : [ { 12 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 13 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 14 | } ], 15 | "maxPayloadBufferSize" : 0 16 | } 17 | -------------------------------------------------------------------------------- /src/test/resources/gateway/multiple-versions-expectation-2.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "test", 4 | "apiId" : "multi-version-example", 5 | "version" : "1.0", 6 | "endpoint" : "http://example.com/v1", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { }, 10 | "parsePayload" : false, 11 | "apiPolicies" : [ { 12 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 13 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 14 | } ], 15 | "maxPayloadBufferSize" : 0 16 | } 17 | -------------------------------------------------------------------------------- /src/test/resources/gateway/plugin-and-builtin-policies-expectation.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "test", 4 | "apiId" : "example", 5 | "version" : "1.0", 6 | "endpoint" : "http://localhost:8080/services/echo", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { }, 10 | "parsePayload" : false, 11 | "apiPolicies" : [ { 12 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 13 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 14 | }, { 15 | "policyJsonConfig" : "{\n \"foo\" : 123\n}", 16 | "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-test-policy:1.4.3.Final:war/io.apiman.plugins.test_policy.TestPolicy" 17 | } ], 18 | "maxPayloadBufferSize" : 0 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/gateway/plugin-and-builtin-policies.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman gateway declaration 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | type: "REST" 7 | config: 8 | endpoint: "http://localhost:8080/apiman-gateway-api" 9 | username: "apimanager" 10 | password: "apiman123!" 11 | plugins: 12 | - name: TestPolicy 13 | groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "test" 18 | apis: 19 | - name: "example" 20 | version: "1.0" 21 | config: 22 | endpoint: "http://localhost:8080/services/echo" 23 | endpointType: "rest" 24 | public: true 25 | gateway: "test-gw" 26 | policies: 27 | - name: "CachingPolicy" 28 | config: 29 | ttl: 60 30 | - plugin: TestPolicy 31 | config: 32 | foo: 123 33 | -------------------------------------------------------------------------------- /src/test/resources/gateway/shared-policies-expectation-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "test", 4 | "apiId" : "example2", 5 | "version" : "1.0", 6 | "endpoint" : "http://example.com", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { }, 10 | "parsePayload" : false, 11 | "apiPolicies" : [ { 12 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 13 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 14 | } ], 15 | "maxPayloadBufferSize" : 0 16 | } 17 | -------------------------------------------------------------------------------- /src/test/resources/gateway/shared-policies-expectation-2.json: -------------------------------------------------------------------------------- 1 | { 2 | "publicAPI" : true, 3 | "organizationId" : "test", 4 | "apiId" : "example1", 5 | "version" : "1.0", 6 | "endpoint" : "http://example.com", 7 | "endpointType" : "rest", 8 | "endpointContentType" : null, 9 | "endpointProperties" : { 10 | "authorization.type" : "basic", 11 | "basic-auth.requireSSL" : "false", 12 | "basic-auth.username" : "user", 13 | "basic-auth.password" : "Password123" 14 | }, 15 | "parsePayload" : false, 16 | "apiPolicies" : [ { 17 | "policyJsonConfig" : "{\n \"ttl\" : 60\n}", 18 | "policyImpl" : "class:io.apiman.gateway.engine.policies.CachingPolicy" 19 | } ], 20 | "maxPayloadBufferSize" : 0 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/multiple-versions.yml: -------------------------------------------------------------------------------- 1 | # Multiple versions of an API defined in a single file. 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | org: 13 | name: "test" 14 | description: "Test organisation" 15 | apis: 16 | - name: "multi-version-example" 17 | description: "Multi-version example API V1" 18 | version: "1.0" 19 | published: true 20 | config: 21 | endpoint: "http://example.com/v1" 22 | endpointType: "rest" 23 | public: true 24 | gateway: "test-gw" 25 | policies: 26 | - name: "CachingPolicy" 27 | config: 28 | ttl: 60 29 | - name: "multi-version-example" 30 | description: "Multi-version example API V2" 31 | version: "2.0" 32 | published: true 33 | config: 34 | endpoint: "http://example.com/v2" 35 | endpointType: "rest" 36 | public: true 37 | gateway: "test-gw" 38 | policies: 39 | - name: "CachingPolicy" 40 | config: 41 | ttl: 60 42 | -------------------------------------------------------------------------------- /src/test/resources/placeholder-test.properties: -------------------------------------------------------------------------------- 1 | gw.username=user 2 | -------------------------------------------------------------------------------- /src/test/resources/placeholder-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/test/resources/shared-policies.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "gateways": [ 4 | { 5 | "name": "test-gw", 6 | "description": "Test Gateway", 7 | "type": "REST", 8 | "config": { 9 | "endpoint": "http://localhost:8080/apiman-gateway-api", 10 | "username": "apimanager", 11 | "password": "apiman123!" 12 | } 13 | } 14 | ], 15 | "plugins": [ 16 | { 17 | "groupId": "io.apiman.plugins", 18 | "artifactId": "apiman-plugins-test-policy", 19 | "version": "1.4.3.Final" 20 | } 21 | ] 22 | }, 23 | "shared": { 24 | "policies": [ 25 | { 26 | "$id": "sharedPolicy", 27 | "name": "CachingPolicy", 28 | "config": { 29 | "ttl": 60 30 | } 31 | } 32 | ] 33 | }, 34 | "org": { 35 | "name": "test", 36 | "description": "Test organisation", 37 | "apis": [ 38 | { 39 | "name": "example1", 40 | "description": "Example API 1", 41 | "version": "1.0", 42 | "published": true, 43 | "config": { 44 | "endpoint": "http://example.com", 45 | "endpointType": "rest", 46 | "public": true, 47 | "gateway": "test-gw", 48 | "security": { 49 | "authorizationType": "basic", 50 | "username": "user", 51 | "password": "Password123" 52 | } 53 | }, 54 | "policies": [ 55 | "sharedPolicy" 56 | ] 57 | }, 58 | { 59 | "name": "example2", 60 | "description": "Example API 2", 61 | "version": "1.0", 62 | "published": true, 63 | "config": { 64 | "endpoint": "http://example.com", 65 | "endpointType": "rest", 66 | "public": true, 67 | "gateway": "test-gw", 68 | "security": { 69 | "authorizationType": "basic", 70 | "username": "user", 71 | "password": "Password123" 72 | } 73 | }, 74 | "policies": [ 75 | "sharedPolicy" 76 | ] 77 | } 78 | ] 79 | } 80 | } -------------------------------------------------------------------------------- /src/test/resources/shared-policies.yml: -------------------------------------------------------------------------------- 1 | # Shared policies example 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | plugins: 13 | - groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | shared: 17 | policies: 18 | - $id: "sharedPolicy" 19 | name: "CachingPolicy" 20 | config: 21 | ttl: 60 22 | org: 23 | name: "test" 24 | description: "Test organisation" 25 | apis: 26 | - name: "example1" 27 | description: "Example API 1" 28 | version: "1.0" 29 | published: true 30 | config: 31 | endpoint: "http://example.com" 32 | endpointType: "rest" 33 | public: true 34 | gateway: "test-gw" 35 | security: 36 | authorizationType: "basic" 37 | username: "user" 38 | password: "Password123" 39 | policies: 40 | - "sharedPolicy" 41 | - name: "example2" 42 | description: "Example API 2" 43 | version: "1.0" 44 | published: true 45 | config: 46 | endpoint: "http://example.com" 47 | endpointType: "rest" 48 | public: true 49 | gateway: "test-gw" 50 | endpointProperties: 51 | authorizationType: "basic" 52 | username: "user" 53 | password: "Password123" 54 | policies: 55 | - "sharedPolicy" 56 | -------------------------------------------------------------------------------- /src/test/resources/shared-properties.yml: -------------------------------------------------------------------------------- 1 | # Declaration with placeholders and shared properties. 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "${embedded1}" 10 | username: "${embedded2}" 11 | password: "${embedded3}" 12 | shared: 13 | properties: 14 | embedded1: "value1" 15 | embedded2: "value2" 16 | embedded3: "value3" 17 | -------------------------------------------------------------------------------- /src/test/resources/simple-full.json: -------------------------------------------------------------------------------- 1 | { 2 | "system": { 3 | "gateways": [ 4 | { 5 | "name": "test-gw", 6 | "description": "Test Gateway", 7 | "type": "REST", 8 | "config": { 9 | "endpoint": "http://localhost:8080/apiman-gateway-api", 10 | "username": "apimanager", 11 | "password": "apiman123!" 12 | } 13 | } 14 | ], 15 | "plugins": [ 16 | { 17 | "groupId": "io.apiman.plugins", 18 | "artifactId": "apiman-plugins-test-policy", 19 | "version": "1.4.3.Final" 20 | } 21 | ] 22 | }, 23 | "org": { 24 | "name": "test", 25 | "description": "Test organisation", 26 | "apis": [ 27 | { 28 | "name": "example", 29 | "description": "Example API", 30 | "version": "1.0", 31 | "published": true, 32 | "config": { 33 | "endpoint": "http://example.com", 34 | "endpointType": "rest", 35 | "public": true, 36 | "gateway": "test-gw", 37 | "security": { 38 | "authorizationType": "basic", 39 | "username": "user", 40 | "password": "Password123" 41 | } 42 | }, 43 | "policies": [ 44 | { 45 | "name": "CachingPolicy", 46 | "config": { 47 | "ttl": 60 48 | } 49 | } 50 | ] 51 | } 52 | ] 53 | } 54 | } -------------------------------------------------------------------------------- /src/test/resources/simple-full.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman example 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | plugins: 13 | - groupId: "io.apiman.plugins" 14 | artifactId: "apiman-plugins-test-policy" 15 | version: "1.4.3.Final" 16 | org: 17 | name: "test" 18 | description: "Test organisation" 19 | apis: 20 | - name: "example" 21 | description: "Example API" 22 | version: "1.0" 23 | published: true 24 | config: 25 | endpoint: "http://example.com" 26 | endpointType: "rest" 27 | security: 28 | authorizationType: "basic" 29 | username: "user" 30 | password: "Password123" 31 | public: true 32 | gateway: "test-gw" 33 | policies: 34 | - name: "CachingPolicy" 35 | config: 36 | ttl: 60 37 | -------------------------------------------------------------------------------- /src/test/resources/simple-no-plugin.yml: -------------------------------------------------------------------------------- 1 | # Simple apiman example, without adding a plugin 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "http://localhost:8080/apiman-gateway-api" 10 | username: "apimanager" 11 | password: "apiman123!" 12 | org: 13 | name: "test" 14 | description: "Test organisation" 15 | apis: 16 | - name: "example" 17 | description: "Example API" 18 | version: "1.0" 19 | published: true 20 | config: 21 | endpoint: "http://example.com" 22 | endpointType: "rest" 23 | public: true 24 | gateway: "test-gw" 25 | security: 26 | authorizationType: "basic" 27 | username: "user" 28 | password: "Password123" 29 | policies: 30 | - name: "CachingPolicy" 31 | config: 32 | ttl: 60 33 | -------------------------------------------------------------------------------- /src/test/resources/simple-placeholders.yml: -------------------------------------------------------------------------------- 1 | # Declaration with placeholders. 2 | --- 3 | system: 4 | gateways: 5 | - name: "test-gw" 6 | description: "Test Gateway" 7 | type: "REST" 8 | config: 9 | endpoint: "${gw.endpoint}" 10 | username: "${gw.username}" 11 | password: "${gw.password}" 12 | -------------------------------------------------------------------------------- /src/test/resources/simple-plugin.yml: -------------------------------------------------------------------------------- 1 | # Adds a plugin 2 | --- 3 | system: 4 | plugins: 5 | - groupId: "io.apiman.plugins" 6 | artifactId: "apiman-plugins-noop-policy" 7 | version: "1.4.3.Final" 8 | --------------------------------------------------------------------------------