├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── github
│ └── vaibhavsinha
│ └── kong
│ ├── api
│ ├── admin
│ │ ├── ApiPluginService.java
│ │ ├── ApiService.java
│ │ ├── CertificateService.java
│ │ ├── ConsumerService.java
│ │ ├── PluginRepoService.java
│ │ ├── PluginService.java
│ │ ├── SniService.java
│ │ ├── TargetService.java
│ │ └── UpstreamService.java
│ └── plugin
│ │ ├── authentication
│ │ ├── BasicAuthService.java
│ │ ├── HmacAuthService.java
│ │ ├── JwtService.java
│ │ ├── KeyAuthService.java
│ │ ├── OAuth2ManageService.java
│ │ └── OAuth2ProcessService.java
│ │ └── security
│ │ └── AclService.java
│ ├── exception
│ └── KongClientException.java
│ ├── impl
│ ├── KongClient.java
│ ├── helper
│ │ ├── CustomGsonConverterFactory.java
│ │ ├── CustomGsonRequestBodyConverter.java
│ │ ├── CustomGsonResponseBodyConverter.java
│ │ ├── RetrofitBodyExtractorInvocationHandler.java
│ │ └── RetrofitServiceCreator.java
│ └── service
│ │ └── plugin
│ │ ├── authentication
│ │ ├── BasicAuthServiceImpl.java
│ │ ├── HmacAuthServiceImpl.java
│ │ ├── JwtAuthServiceImpl.java
│ │ └── KeyAuthServiceImpl.java
│ │ └── security
│ │ └── AclServiceImpl.java
│ ├── internal
│ ├── admin
│ │ ├── RetrofitApiPluginService.java
│ │ ├── RetrofitApiService.java
│ │ ├── RetrofitCertificateService.java
│ │ ├── RetrofitConsumerService.java
│ │ ├── RetrofitPluginRepoService.java
│ │ ├── RetrofitPluginService.java
│ │ ├── RetrofitSniService.java
│ │ ├── RetrofitTargetService.java
│ │ └── RetrofitUpstreamService.java
│ └── plugin
│ │ ├── authentication
│ │ ├── RetrofitBasicAuthService.java
│ │ ├── RetrofitHmacAuthService.java
│ │ ├── RetrofitJwtService.java
│ │ ├── RetrofitKeyAuthService.java
│ │ ├── RetrofitOAuth2ManageService.java
│ │ └── RetrofitOAuth2ProcessService.java
│ │ └── security
│ │ └── RetrofitAclService.java
│ ├── model
│ ├── admin
│ │ ├── api
│ │ │ ├── Api.java
│ │ │ └── ApiList.java
│ │ ├── certificate
│ │ │ ├── Certificate.java
│ │ │ └── CertificateList.java
│ │ ├── consumer
│ │ │ ├── Consumer.java
│ │ │ └── ConsumerList.java
│ │ ├── plugin
│ │ │ ├── EnabledPlugins.java
│ │ │ ├── OAuth2Config.java
│ │ │ ├── Plugin.java
│ │ │ └── PluginList.java
│ │ ├── sni
│ │ │ ├── Sni.java
│ │ │ └── SniList.java
│ │ ├── target
│ │ │ ├── Target.java
│ │ │ └── TargetList.java
│ │ └── upstream
│ │ │ ├── Upstream.java
│ │ │ └── UpstreamList.java
│ ├── common
│ │ └── AbstractEntityList.java
│ └── plugin
│ │ ├── authentication
│ │ ├── basic
│ │ │ ├── BasicAuthConfig.java
│ │ │ └── BasicAuthCredential.java
│ │ ├── hmac
│ │ │ ├── HmacAuthConfig.java
│ │ │ └── HmacAuthCredential.java
│ │ ├── jwt
│ │ │ ├── JwtConfig.java
│ │ │ ├── JwtCredential.java
│ │ │ └── JwtCredentialList.java
│ │ ├── key
│ │ │ ├── KeyAuthConfig.java
│ │ │ ├── KeyAuthCredential.java
│ │ │ └── KeyAuthCredentialList.java
│ │ ├── ldap
│ │ │ └── LdapConfig.java
│ │ └── oauth2
│ │ │ ├── Application.java
│ │ │ ├── ApplicationList.java
│ │ │ ├── AuthorizationRequest.java
│ │ │ ├── GrantTokenRequest.java
│ │ │ ├── OAuth2Config.java
│ │ │ ├── Redirect.java
│ │ │ ├── RefreshRequest.java
│ │ │ ├── Token.java
│ │ │ └── TokenList.java
│ │ ├── security
│ │ ├── acl
│ │ │ ├── Acl.java
│ │ │ ├── AclConfig.java
│ │ │ └── AclList.java
│ │ └── iprestriction
│ │ │ └── IpRestrictionConfig.java
│ │ └── trafficcontrol
│ │ ├── ratelimiting
│ │ └── RateLimitingConfig.java
│ │ ├── requestsizelimiting
│ │ └── RequestSizeLimitingConfig.java
│ │ └── requesttermination
│ │ └── RequestTerminationConfig.java
│ └── utils
│ ├── HttpsUtil.java
│ └── UrlUtil.java
└── test
├── java
└── com
│ └── github
│ └── vaibhavsinha
│ └── kong
│ ├── BaseTest.java
│ ├── RetrofitAclServiceTest.java
│ ├── RetrofitApiPluginServiceTest.java
│ ├── RetrofitApiServiceTest.java
│ ├── RetrofitCertificateServiceTest.java
│ ├── RetrofitConsumerServiceTest.java
│ ├── RetrofitJwtServiceTest.java
│ ├── RetrofitKeyAuthServiceTest.java
│ ├── RetrofitPluginRepoServiceTest.java
│ ├── RetrofitPluginServiceTest.java
│ ├── RetrofitSniServiceTest.java
│ ├── RetrofitTargetServiceTest.java
│ ├── RetrofitUpstreamServiceTest.java
│ └── plugin
│ ├── RetrofitOAuth2ManageServiceTest.java
│ └── RetrofitOAuth2ProcessServiceTest.java
└── resources
└── log4j.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Java template
3 | # Log file
4 | *.log
5 |
6 | # BlueJ files
7 | *.ctxt
8 |
9 | # Mobile Tools for Java (J2ME)
10 | .mtj.tmp/
11 |
12 | # Package Files #
13 | *.jar
14 | *.war
15 | *.ear
16 | *.zip
17 | *.tar.gz
18 | *.rar
19 |
20 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
21 | hs_err_pid*
22 |
23 | # Eclipse
24 | .classpath
25 | .project
26 | .settings/
27 |
28 | # Intellij
29 | .idea/
30 | *.iml
31 | *.iws
32 |
33 | # Mac
34 | .DS_Store
35 |
36 | # Maven
37 | log/
38 | target/
39 |
40 | rebel.xml
41 | logs/
42 | zs/
43 | lib
44 | *.bak
45 | !/com/github/vaibhavsinha/kong/model/admin/target/
46 | !/src/main/java/com/github/vaibhavsinha/kong/model/admin/target/
47 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at vaibhavsinh@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Kong Java Client
2 |
3 | [Kong](https://getkong.org/) is a popular Open Source API Gateway. Kong Java Client makes it easy to configure the API Gateway through your code.
4 |
5 | ## Installation
6 |
7 | The artifact is available on Maven Central Repository and be downloaded by adding the following dependency in pom.xml
8 |
9 |
10 | com.github.vaibhav-sinha
11 | kong-java-client
12 | 0.2.0
13 |
14 |
15 | ## Usage
16 |
17 | KongClient kongClient = new KongClient("http://localhost:8001");
18 | Consumer request = new Consumer();
19 | request.setCustomId("1234-5678-9012");
20 | Consumer response = kongClient.getConsumerService().createConsumer(request);
21 |
22 | Look in the tests to find more examples.
23 |
24 | ## Supported Plugins
25 |
26 | Besides the Admin APIs, Plugin configuration is also supported.
27 |
28 | ### Authentication Plugins
29 | * Basic Auth
30 | * Key Auth
31 | * HMAC Auth
32 | * JWT Auth
33 | * OAuth2
34 | * LDAP
35 |
36 | ### Security Plugins
37 | * ACL
38 | * IP Restriction
39 |
40 | ### Traffic Control Plugins
41 | * Rate Limiting
42 | * Request Size Limiting
43 | * Request Termination
44 |
45 | Only those plugins are supported which might need configuration through code. For example, adding rate limit for a new consumer when there is a new signup. Plugins which require one time configuration are not supported.
46 |
47 | ### Example Usage
48 |
49 | To add credentials for a new Consumer for Basic Auth
50 |
51 | kongClient.getBasicAuthService().addCredentials("con-su-mer-id", "username", "password");
52 |
53 |
54 | To add OAuth2 Plugin for an API
55 |
56 | //See: RetrofitApiPluginServiceTest.java
57 | kongClient.getApiPluginService().addPluginForApi(API_NAME, oauth2Plugin);
58 |
59 | To add an Application for a Consumer for OAuth2
60 |
61 | //See: RetrofitOAuth2ManageServiceTest.java
62 | kongClient.getOAuth2ManageService().createConsumerApplication(CONSUMER_ID,
63 | new Application(appName, appRedirectUrl, appClientId, appClientSecret));
64 |
65 | To do the OAuth2 Process (Authorization Code)
66 |
67 | //See: RetrofitOAuth2ProcessServiceTest.java
68 | kongClient.getOAuth2ProcessService().authorize(API_URI, authorizationRequest);
69 | kongClient.getOAuth2ProcessService().grantToken(API_URI, grantTokenRequest)
70 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.vaibhav-sinha
8 | kong-java-client
9 | 0.2.0
10 |
11 | jar
12 |
13 | kong-java-client
14 | Kong is a popular Open Source API Gateway. Kong Java Client makes it easy to configure the API Gateway through your code.
15 | https://github.com/vaibhav-sinha/kong-java-client
16 |
17 |
18 |
19 | The Apache License, Version 2.0
20 | http://www.apache.org/licenses/LICENSE-2.0.txt
21 |
22 |
23 |
24 |
25 |
26 | Vaibhav Sinha
27 | vaibhavsinh@gmail.com
28 |
29 |
30 |
31 |
32 | scm:git:git://github.com/vaibhav-sinha/kong-java-client.git
33 | scm:git:ssh://github.com:vaibhav-sinha/kong-java-client.git
34 | http://github.com/vaibhav-sinha/kong-java-client/tree/master
35 |
36 |
37 |
38 | 2.3.0
39 | 1.16.16
40 | 1.6.2
41 | 1.1
42 | 1.2.16
43 | 1.0.6
44 | 4.12
45 |
46 |
47 |
48 |
49 | com.squareup.retrofit2
50 | retrofit
51 | ${retrofit.version}
52 |
53 |
54 | com.squareup.retrofit2
55 | converter-gson
56 | ${retrofit.version}
57 |
58 |
59 | com.google.code.gson
60 | gson
61 |
62 |
63 |
64 |
65 | com.google.code.gson
66 | gson
67 | 2.8.1
68 |
69 |
76 |
83 |
84 |
85 | org.projectlombok
86 | lombok
87 | ${lombok.version}
88 | provided
89 |
90 |
91 |
92 |
93 | org.slf4j
94 | slf4j-api
95 | ${slf4j.version}
96 |
97 |
98 | org.slf4j
99 | slf4j-log4j12
100 | ${slf4j.version}
101 |
102 |
103 | commons-logging
104 | commons-logging-api
105 | ${jcl.version}
106 |
107 |
108 | log4j
109 | log4j
110 | ${log4j.version}
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 | junit
120 | junit
121 | ${junit.version}
122 | test
123 |
124 |
125 |
126 |
127 |
128 | ossrh
129 | https://oss.sonatype.org/content/repositories/snapshots
130 |
131 |
132 | ossrh
133 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
134 |
135 |
136 |
137 |
138 |
139 |
140 | maven-compiler-plugin
141 | 3.1
142 |
143 | 1.8
144 | 1.8
145 |
146 |
147 |
148 | org.apache.maven.plugins
149 | maven-source-plugin
150 | 2.2.1
151 |
152 |
153 | attach-sources
154 |
155 | jar-no-fork
156 |
157 |
158 |
159 |
160 |
161 | org.apache.maven.plugins
162 | maven-javadoc-plugin
163 | 2.9.1
164 |
165 |
166 | attach-javadocs
167 |
168 | jar
169 |
170 |
171 |
172 |
173 |
174 | org.apache.maven.plugins
175 | maven-gpg-plugin
176 | 1.5
177 |
178 |
179 | sign-artifacts
180 | verify
181 |
182 | sign
183 |
184 |
185 |
186 |
187 |
188 | org.sonatype.plugins
189 | nexus-staging-maven-plugin
190 | 1.6.7
191 | true
192 |
193 | ossrh
194 | https://oss.sonatype.org/
195 | true
196 |
197 |
198 |
199 |
200 |
201 |
202 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/ApiPluginService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin;
4 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
5 |
6 | /**
7 | *
8 | * You can add a plugin in four different ways:
9 | * For every API and Consumer. Don't set api_id and consumer_id.
10 | * For every API and a specific Consumer. Only set consumer_id.
11 | * For every Consumer and a specific API. Only set api_id.
12 | * For a specific Consumer and API. Set both api_id and consumer_id.
13 | * Note that not all plugins allow to specify consumer_id. Check the plugin documentation.
14 | */
15 | public interface ApiPluginService {
16 |
17 |
18 | Plugin addPluginForApi(String apiNameOrId, Plugin plugin);
19 |
20 | Plugin getPluginForApi(String apiNameOrId, String pluginId);
21 |
22 | Plugin updatePluginForApi(String apiNameOrId, String pluginNameOrId, Plugin request);
23 |
24 | @Deprecated
25 | Plugin createOrUpdatePluginForApi(String apiNameOrId, Plugin plugin);
26 |
27 | void deletePluginForApi(String apiNameOrId, String pluginNameOrId);
28 |
29 | PluginList listPluginsForApi(String apiNameOrId, String pluginNameOrId, String apiId, String consumerId, String name, Long size, String offset);
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/ApiService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.api.Api;
4 | import com.github.vaibhavsinha.kong.model.admin.api.ApiList;
5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
6 |
7 | /**
8 | * Created by vaibhav on 13/06/17.
9 | */
10 | public interface ApiService {
11 |
12 | Api createApi(Api request);
13 |
14 | Api getApi(String nameOrId);
15 |
16 | Api updateApi(String nameOrId, Api request);
17 |
18 | /**
19 | * This interface has issue in Kong.
20 | * 1. Usually, when we put a API(which not exist in Kong) as a parameter, it should be added as a new one.
21 | * But it only take effect when API id is empty.
22 | * 2. When the API id input is not empty, it will consider to update the existing API. So, we can either
23 | * create a API (without id), or update a API (with id).
24 | * 3. When you try to create a API with name and id, it will become odd. Kong will give you the 200(ok) response,
25 | * but won't create the API that you wanted. (That's why we'd better not use this interface.
26 | *
27 | * */
28 | @Deprecated
29 | Api createOrUpdateApi(Api request);
30 |
31 | void deleteApi(String nameOrId);
32 |
33 | ApiList listApis(String id, String upstreamUrl, String name, Long retries, Long size, String offset);
34 | PluginList listApiPlugins(String id);
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/CertificateService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.certificate.Certificate;
4 | import com.github.vaibhavsinha.kong.model.admin.certificate.CertificateList;
5 |
6 | /**
7 | * Created by vaibhav on 13/06/17.
8 | */
9 | @Deprecated
10 | public interface CertificateService {
11 | Certificate createCertificate(Certificate request);
12 | Certificate getCertificate(String sniOrId);
13 | Certificate updateCertificate(String sniOrId, Certificate request);
14 | Certificate createOrUpdateCertificate(Certificate request);
15 | Certificate deleteCertificate(String sniOrId);
16 | CertificateList listCertificates();
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/ConsumerService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer;
4 | import com.github.vaibhavsinha.kong.model.admin.consumer.ConsumerList;
5 |
6 | /**
7 | * Created by vaibhav on 13/06/17.
8 | */
9 | public interface ConsumerService {
10 |
11 | Consumer createConsumer(Consumer request);
12 |
13 | Consumer getConsumer(String usernameOrId);
14 |
15 | Consumer updateConsumer(String usernameOrId, Consumer request);
16 |
17 | @Deprecated
18 | Consumer createOrUpdateConsumer(Consumer request);
19 |
20 | void deleteConsumer(String usernameOrId);
21 |
22 | ConsumerList listConsumers(String id, String customId, String username, Long size, String offset);
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/PluginRepoService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.plugin.EnabledPlugins;
4 |
5 | public interface PluginRepoService {
6 |
7 | EnabledPlugins retrieveEnabledPlugins();
8 |
9 | Object retrievePluginSchema(String pluginName);
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/PluginService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.plugin.EnabledPlugins;
4 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin;
5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
6 |
7 | /**
8 | * Created by vaibhav on 13/06/17.
9 | *
10 | * You can add a plugin in four different ways:
11 | * For every API and Consumer. Don't set api_id and consumer_id.
12 | * For every API and a specific Consumer. Only set consumer_id.
13 | * For every Consumer and a specific API. Only set api_id.
14 | * For a specific Consumer and API. Set both api_id and consumer_id.
15 | * Note that not all plugins allow to specify consumer_id. Check the plugin documentation.
16 | */
17 | public interface PluginService {
18 |
19 |
20 | Plugin addPlugin(Plugin request);
21 |
22 | Plugin getPlugin(String nameOrId);
23 |
24 | Plugin updatePlugin(String nameOrId, Plugin request);
25 |
26 | @Deprecated
27 | Plugin createOrUpdatePlugin(Plugin request);
28 |
29 | void deletePlugin(String nameOrId);
30 |
31 | PluginList listPlugins(String id, String apiId, String consumerId, String name, Long size, String offset);
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/SniService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.sni.Sni;
4 | import com.github.vaibhavsinha.kong.model.admin.sni.SniList;
5 |
6 | /**
7 | * Created by vaibhav on 13/06/17.
8 | */
9 | @Deprecated
10 | public interface SniService {
11 | Sni createSni(Sni request);
12 | Sni getSni(String name);
13 | Sni updateSni(String name, Sni request);
14 | Sni createOrUpdateSni(Sni request);
15 | Sni deleteSni(String name);
16 | SniList listSnis();
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/TargetService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.target.Target;
4 | import com.github.vaibhavsinha.kong.model.admin.target.TargetList;
5 |
6 | /**
7 | * Created by vaibhav on 13/06/17.
8 | */
9 | @Deprecated
10 | public interface TargetService {
11 | Target createTarget(String upstreamNameOrId, Target request);
12 | Target deleteTarget(String upstreamNameOrId, String target);
13 | TargetList listTargets(String upstreamNameOrId, String id, Integer weight, String target, Long size, String offset);
14 | TargetList listActiveTargets(String upstreamNameOrId);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/admin/UpstreamService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.upstream.Upstream;
4 | import com.github.vaibhavsinha.kong.model.admin.upstream.UpstreamList;
5 |
6 | /**
7 | * Created by vaibhav on 13/06/17.
8 | */
9 | @Deprecated
10 | public interface UpstreamService {
11 | Upstream createUpstream(Upstream request);
12 | Upstream getUpstream(String nameOrId);
13 | Upstream updateUpstream(String nameOrId, Upstream request);
14 | Upstream createOrUpdateUpstream(Upstream request);
15 | Upstream deleteUpstream(String nameOrId);
16 | UpstreamList listUpstreams(String id, Integer slots, String name, Long size, String offset);
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/BasicAuthService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.plugin.authentication;
2 |
3 | /**
4 | * Created by vaibhav on 15/06/17.
5 | */
6 | public interface BasicAuthService {
7 | void addCredentials(String consumerIdOrUsername, String username, String password);
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/HmacAuthService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.plugin.authentication;
2 |
3 | /**
4 | * Created by vaibhav on 15/06/17.
5 | */
6 | public interface HmacAuthService {
7 | void addCredentials(String consumerIdOrUsername, String username, String secret);
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/JwtService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.plugin.authentication;
2 |
3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredential;
4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredentialList;
5 |
6 | /**
7 | * Created by vaibhav on 16/06/17.
8 | *
9 | * Updated by dvilela on 17/10/17.
10 | */
11 | public interface JwtService {
12 | JwtCredential addCredentials(String consumerIdOrUsername, JwtCredential request);
13 | void deleteCredentials(String consumerIdOrUsername, String id);
14 | JwtCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/KeyAuthService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.plugin.authentication;
2 |
3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential;
4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList;
5 |
6 | /**
7 | * Created by vaibhav on 15/06/17.
8 | *
9 | * Updated by dvilela on 17/10/17.
10 | */
11 | public interface KeyAuthService {
12 | KeyAuthCredential addCredentials(String consumerIdOrUsername, String key);
13 | KeyAuthCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset);
14 | void deleteCredential(String consumerIdOrUsername, String id);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/OAuth2ManageService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.plugin.authentication;
2 |
3 |
4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Application;
5 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.ApplicationList;
6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Token;
7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.TokenList;
8 |
9 | public interface OAuth2ManageService {
10 |
11 | // App Management ---------------------------------------------------------------------------------------------------
12 |
13 | Application createConsumerApplication(String consumerId, Application request);
14 |
15 | Application getConsumerApplication(String consumerId, String applicationId);
16 |
17 | Application updateConsumerApplication(String consumerId, String applicationId, Application request);
18 |
19 | void deleteConsumerApplication(String consumerId, String applicationId);
20 |
21 | ApplicationList listConsumerApplications(String consumerId);
22 |
23 | ApplicationList listClientApplications(String applicationId, String applicatonName, String clientId, String clientSecret, String consumerId);
24 |
25 | // Token Management ---------------------------------------------------------------------------------------------------
26 |
27 | Token createToken(Token request);
28 |
29 | Token getToken(String tokenId);
30 |
31 | Token updateToken(String tokenId, Token request);
32 |
33 | TokenList listTokens();
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/OAuth2ProcessService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.plugin.authentication;
2 |
3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.*;
4 |
5 | import java.util.Map;
6 |
7 | public interface OAuth2ProcessService {
8 |
9 |
10 | // OAuth2 Process ---------------------------------------------------------------------------------------------------
11 |
12 |
13 | Map authorize(String apiUri, AuthorizationRequest request);
14 |
15 | Token grantToken(String apiUri, GrantTokenRequest request);
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/api/plugin/security/AclService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.api.plugin.security;
2 |
3 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.AclList;
4 |
5 | /**
6 | * Created by vaibhav on 18/06/17.
7 | *
8 | * Upated by dvilela on 22/10/17.
9 | */
10 | public interface AclService {
11 | void associateConsumer(String usernameOrId, String group);
12 | AclList listAcls(String usernameOrId, Long size, String offset);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.exception;
2 |
3 | /**
4 | * Created by vaibhav on 13/06/17.
5 | *
6 | * Updated by dvilela on 11/08/17.
7 | */
8 | public class KongClientException extends RuntimeException {
9 |
10 | private int code;
11 |
12 | private String error;
13 |
14 | public KongClientException(String message) {
15 | super(message);
16 | }
17 |
18 | public KongClientException(String message, int code, String error) {
19 | super(message);
20 | this.code = code;
21 | this.error = error;
22 | }
23 |
24 | public int getCode() {
25 | return code;
26 | }
27 |
28 | public String getError() {
29 | return error;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/KongClient.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl;
2 |
3 | import com.github.vaibhavsinha.kong.api.admin.*;
4 | import com.github.vaibhavsinha.kong.api.plugin.authentication.*;
5 | import com.github.vaibhavsinha.kong.api.plugin.security.AclService;
6 | import com.github.vaibhavsinha.kong.impl.helper.RetrofitServiceCreator;
7 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.BasicAuthServiceImpl;
8 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.HmacAuthServiceImpl;
9 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.JwtAuthServiceImpl;
10 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.KeyAuthServiceImpl;
11 | import com.github.vaibhavsinha.kong.impl.service.plugin.security.AclServiceImpl;
12 | import com.github.vaibhavsinha.kong.internal.admin.*;
13 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.*;
14 | import com.github.vaibhavsinha.kong.internal.plugin.security.RetrofitAclService;
15 | import lombok.Data;
16 |
17 | /**
18 | * Created by vaibhav on 12/06/17.
19 | *
20 | * Updated by fanhua on 2017-08-07.
21 | *
22 | * Updated by dvilela on 17/10/17.
23 | */
24 | @Data
25 | public class KongClient {
26 |
27 | private ConsumerService consumerService;
28 |
29 | private ApiService apiService;
30 | private ApiPluginService apiPluginService;
31 |
32 | private PluginService pluginService;
33 | private PluginRepoService pluginRepoService;
34 | private CertificateService certificateService;
35 | private SniService sniService;
36 | private UpstreamService upstreamService;
37 | private TargetService targetService;
38 |
39 | private BasicAuthService basicAuthService;
40 | private KeyAuthService keyAuthService;
41 | private HmacAuthService hmacAuthService;
42 | private JwtService jwtService;
43 |
44 | private OAuth2ProcessService oAuth2ProcessService;
45 | private OAuth2ManageService oAuth2ManageService;
46 |
47 | private AclService aclService;
48 |
49 |
50 | public KongClient(String adminUrl) {
51 | this(adminUrl, null, false);
52 | }
53 |
54 |
55 | public KongClient(String adminUrl, String proxyUrl, boolean needOAuth2Support) {
56 |
57 | if (adminUrl == null || adminUrl.isEmpty()) {
58 | throw new IllegalArgumentException("The adminUrl cannot be null or empty!");
59 | }
60 |
61 | if (needOAuth2Support) {
62 | if (proxyUrl == null || proxyUrl.isEmpty()) {
63 | throw new IllegalArgumentException("The proxyUrl cannot be null or empty!");
64 | }
65 | if (!proxyUrl.startsWith("https://")) {
66 | throw new IllegalArgumentException("The proxyUrl must use https if you need OAuth2 support!");
67 | }
68 | }
69 |
70 |
71 | RetrofitServiceCreator retrofitServiceCreatorForAdminUrl = new RetrofitServiceCreator(adminUrl);
72 |
73 | {
74 | consumerService = retrofitServiceCreatorForAdminUrl.create(ConsumerService.class, RetrofitConsumerService.class);
75 |
76 | apiService = retrofitServiceCreatorForAdminUrl.create(ApiService.class, RetrofitApiService.class);
77 | apiPluginService = retrofitServiceCreatorForAdminUrl.create(ApiPluginService.class, RetrofitApiPluginService.class);
78 |
79 | pluginService = retrofitServiceCreatorForAdminUrl.create(PluginService.class, RetrofitPluginService.class);
80 | pluginRepoService = retrofitServiceCreatorForAdminUrl.create(PluginRepoService.class, RetrofitPluginRepoService.class);
81 |
82 | certificateService = retrofitServiceCreatorForAdminUrl.create(CertificateService.class, RetrofitCertificateService.class);
83 | sniService = retrofitServiceCreatorForAdminUrl.create(SniService.class, RetrofitSniService.class);
84 | upstreamService = retrofitServiceCreatorForAdminUrl.create(UpstreamService.class, RetrofitUpstreamService.class);
85 | targetService = retrofitServiceCreatorForAdminUrl.create(TargetService.class, RetrofitTargetService.class);
86 | }
87 |
88 | {
89 | basicAuthService = new BasicAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitBasicAuthService.class));
90 | keyAuthService = new KeyAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitKeyAuthService.class));
91 | hmacAuthService = new HmacAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitHmacAuthService.class));
92 | jwtService = new JwtAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitJwtService.class));
93 | aclService = new AclServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitAclService.class));
94 | }
95 |
96 | if(needOAuth2Support) {
97 |
98 | RetrofitServiceCreator retrofitServiceCreatorForProxyUrl = new RetrofitServiceCreator(proxyUrl);
99 |
100 | //oauth2 process is on proxy port
101 | oAuth2ProcessService = retrofitServiceCreatorForProxyUrl.create(OAuth2ProcessService.class, RetrofitOAuth2ProcessService.class);
102 |
103 | //oauth2 manage is on admin port
104 | oAuth2ManageService = retrofitServiceCreatorForAdminUrl.create(OAuth2ManageService.class, RetrofitOAuth2ManageService.class);
105 | }
106 |
107 | }
108 |
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/helper/CustomGsonConverterFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.helper;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.TypeAdapter;
5 | import com.google.gson.reflect.TypeToken;
6 | import okhttp3.RequestBody;
7 | import okhttp3.ResponseBody;
8 | import retrofit2.Converter;
9 | import retrofit2.Retrofit;
10 |
11 | import java.lang.annotation.Annotation;
12 | import java.lang.reflect.Type;
13 |
14 | class CustomGsonConverterFactory extends Converter.Factory {
15 |
16 | private final Gson gson;
17 |
18 | private CustomGsonConverterFactory(Gson gson) {
19 | if (gson == null) throw new NullPointerException("gson == null");
20 | this.gson = gson;
21 | }
22 |
23 | public static CustomGsonConverterFactory create() {
24 | return create(new Gson());
25 | }
26 |
27 | public static CustomGsonConverterFactory create(Gson gson) {
28 | return new CustomGsonConverterFactory(gson);
29 | }
30 |
31 | @Override
32 | public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
33 | TypeAdapter> adapter = gson.getAdapter(TypeToken.get(type));
34 | return new CustomGsonResponseBodyConverter<>(gson, adapter);
35 | }
36 |
37 | @Override
38 | public Converter, RequestBody> requestBodyConverter(Type type,Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
39 | TypeAdapter> adapter = gson.getAdapter(TypeToken.get(type));
40 | return new CustomGsonRequestBodyConverter<>(gson, adapter);
41 | }
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/helper/CustomGsonRequestBodyConverter.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.helper;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.TypeAdapter;
5 | import com.google.gson.stream.JsonWriter;
6 | import okhttp3.MediaType;
7 | import okhttp3.RequestBody;
8 | import okio.Buffer;
9 | import retrofit2.Converter;
10 |
11 | import java.io.IOException;
12 | import java.io.OutputStreamWriter;
13 | import java.io.Writer;
14 | import java.nio.charset.Charset;
15 |
16 | final class CustomGsonRequestBodyConverter implements Converter {
17 |
18 | private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
19 | private static final Charset UTF_8 = Charset.forName("UTF-8");
20 |
21 | private final Gson gson;
22 | private final TypeAdapter adapter;
23 |
24 | CustomGsonRequestBodyConverter(Gson gson, TypeAdapter adapter) {
25 | this.gson = gson;
26 | this.adapter = adapter;
27 | }
28 |
29 | @Override
30 | public RequestBody convert(T value) throws IOException {
31 | Buffer buffer = new Buffer();
32 | Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
33 | JsonWriter jsonWriter = gson.newJsonWriter(writer);
34 | adapter.write(jsonWriter, value);
35 | jsonWriter.close();
36 | return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/helper/CustomGsonResponseBodyConverter.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.helper;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.TypeAdapter;
5 | import com.google.gson.stream.JsonReader;
6 | import lombok.extern.slf4j.Slf4j;
7 | import okhttp3.MediaType;
8 | import okhttp3.ResponseBody;
9 | import retrofit2.Converter;
10 |
11 | import java.io.ByteArrayInputStream;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.InputStreamReader;
15 | import java.io.Reader;
16 | import java.nio.charset.Charset;
17 |
18 | @Slf4j
19 | final class CustomGsonResponseBodyConverter implements Converter {
20 |
21 | private static final Charset UTF_8 = Charset.forName("UTF-8");
22 |
23 | private final Gson gson;
24 | private final TypeAdapter adapter;
25 |
26 | CustomGsonResponseBodyConverter(Gson gson, TypeAdapter adapter) {
27 | this.gson = gson;
28 | this.adapter = adapter;
29 | }
30 |
31 | @Override
32 | public T convert(ResponseBody value) throws IOException {
33 |
34 | String response = value.string();
35 |
36 | if(response == null || response.isEmpty()) {
37 | //It may response empty body...
38 | log.debug("Response empty body...");
39 | return null;
40 | }
41 |
42 | MediaType contentType = value.contentType();
43 | Charset charset = contentType != null ? contentType.charset(UTF_8) : UTF_8;
44 | InputStream inputStream = new ByteArrayInputStream(response.getBytes());
45 | Reader reader = new InputStreamReader(inputStream, charset);
46 | JsonReader jsonReader = gson.newJsonReader(reader);
47 |
48 | try {
49 | return adapter.read(jsonReader);
50 | } finally {
51 | value.close();
52 | }
53 |
54 | }
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/helper/RetrofitBodyExtractorInvocationHandler.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.helper;
2 |
3 | import com.github.vaibhavsinha.kong.exception.KongClientException;
4 | import lombok.extern.slf4j.Slf4j;
5 | import retrofit2.Call;
6 | import retrofit2.Response;
7 |
8 | import java.lang.reflect.InvocationHandler;
9 | import java.lang.reflect.Method;
10 |
11 | /**
12 | * Created by vaibhav on 13/06/17.
13 | */
14 | @Slf4j
15 | public class RetrofitBodyExtractorInvocationHandler implements InvocationHandler {
16 |
17 | private Object proxied;
18 |
19 | public RetrofitBodyExtractorInvocationHandler(Object proxied) {
20 | this.proxied = proxied;
21 | }
22 |
23 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
24 | String methodName = method.getName();
25 | Class>[] parameterTypes = method.getParameterTypes();
26 | Method method1 = proxied.getClass().getMethod(methodName, parameterTypes);
27 | Call call = (Call) method1.invoke(proxied, args);
28 | Response response = call.execute();
29 | log.debug("Http Request: " + response.raw().request());
30 | log.debug("Http Response: " + response.raw().toString());
31 | if(!response.isSuccessful()) {
32 | throw new KongClientException(response.errorBody() != null ? response.errorBody().string() : String.valueOf(response.code()));
33 | }
34 | return response.body();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/helper/RetrofitServiceCreator.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.helper;
2 |
3 | //import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
4 | import com.github.vaibhavsinha.kong.utils.HttpsUtil;
5 | import okhttp3.OkHttpClient;
6 | import retrofit2.Retrofit;
7 | //import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
8 | //import retrofit2.converter.gson.GsonConverterFactory;
9 |
10 | import java.lang.reflect.Proxy;
11 |
12 | /**
13 | * Created by vaibhav on 13/06/17.
14 | *
15 | * Update by fanhua on 2017-07-28.
16 | */
17 | public class RetrofitServiceCreator {
18 |
19 | private Retrofit retrofit;
20 |
21 |
22 | // -------------------------------------------------------------------
23 |
24 | public RetrofitServiceCreator(String baseUrl) {
25 |
26 | retrofit = new Retrofit.Builder()
27 | .baseUrl(baseUrl)
28 | .client(initOkHttpClient(baseUrl.toLowerCase().startsWith("https"))) // support https
29 | .addConverterFactory(CustomGsonConverterFactory.create()) // replace GsonConverterFactory
30 | // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // add rxJava1 support
31 | // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // add rxJava2 support
32 | .build();
33 |
34 | }
35 |
36 | // -------------------------------------------------------------------
37 |
38 | @SuppressWarnings("unchecked")
39 | public T create(Class serviceInterface, Class> retrofitServiceInterface) {
40 | Object proxied = retrofit.create(retrofitServiceInterface);
41 | return (T) Proxy.newProxyInstance(
42 | RetrofitServiceCreator.class.getClassLoader(),
43 | new Class[] { serviceInterface },
44 | new RetrofitBodyExtractorInvocationHandler(proxied));
45 | }
46 |
47 | public T createRetrofitService(Class retrofitServiceInterface) {
48 | return retrofit.create(retrofitServiceInterface);
49 | }
50 |
51 | // -------------------------------------------------------------------
52 |
53 | private OkHttpClient initOkHttpClient(boolean supportHttps) {
54 |
55 | if(supportHttps) {
56 | HttpsUtil.SSLParams sslParams = HttpsUtil.getSslSocketFactory(null, null, null);
57 | OkHttpClient okHttpClient = new OkHttpClient.Builder()
58 | .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
59 | .build();
60 | return okHttpClient;
61 | }
62 |
63 | return new OkHttpClient.Builder().build();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/BasicAuthServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication;
2 |
3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.BasicAuthService;
4 | import com.github.vaibhavsinha.kong.exception.KongClientException;
5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitBasicAuthService;
6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.basic.BasicAuthCredential;
7 | import retrofit2.Retrofit;
8 | import retrofit2.converter.gson.GsonConverterFactory;
9 |
10 | import java.io.IOException;
11 |
12 | /**
13 | * Created by vaibhav on 15/06/17.
14 | *
15 | * Updated by fanhua on 2017-08-07.
16 | */
17 | public class BasicAuthServiceImpl implements BasicAuthService {
18 |
19 | private RetrofitBasicAuthService retrofitBasicAuthService;
20 |
21 | public BasicAuthServiceImpl(RetrofitBasicAuthService retrofitBasicAuthService) {
22 | this.retrofitBasicAuthService = retrofitBasicAuthService;
23 | }
24 |
25 | @Override
26 | public void addCredentials(String consumerIdOrUsername, String username, String password) {
27 | try {
28 | retrofitBasicAuthService.addCredentials(consumerIdOrUsername, new BasicAuthCredential(username, password)).execute();
29 | } catch (IOException e) {
30 | throw new KongClientException(e.getMessage());
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/HmacAuthServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication;
2 |
3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.HmacAuthService;
4 | import com.github.vaibhavsinha.kong.exception.KongClientException;
5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitHmacAuthService;
6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.hmac.HmacAuthCredential;
7 | import retrofit2.Retrofit;
8 | import retrofit2.converter.gson.GsonConverterFactory;
9 |
10 | import java.io.IOException;
11 |
12 | /**
13 | * Created by vaibhav on 15/06/17.
14 | *
15 | * Updated by fanhua on 2017-08-07.
16 | */
17 | public class HmacAuthServiceImpl implements HmacAuthService {
18 |
19 | private RetrofitHmacAuthService retrofitHmacAuthService;
20 |
21 | public HmacAuthServiceImpl(RetrofitHmacAuthService retrofitHmacAuthService) {
22 | this.retrofitHmacAuthService = retrofitHmacAuthService;
23 | }
24 |
25 | @Override
26 | public void addCredentials(String consumerIdOrUsername, String username, String secret) {
27 | try {
28 | retrofitHmacAuthService.addCredentials(consumerIdOrUsername, new HmacAuthCredential(username, secret)).execute();
29 | } catch (IOException e) {
30 | throw new KongClientException(e.getMessage());
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/JwtAuthServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication;
2 |
3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.JwtService;
4 | import com.github.vaibhavsinha.kong.exception.KongClientException;
5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitJwtService;
6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredential;
7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredentialList;
8 |
9 | import java.io.IOException;
10 |
11 | /**
12 | * Created by dvilela on 10/16/17.
13 | */
14 | public class JwtAuthServiceImpl implements JwtService {
15 |
16 | private RetrofitJwtService retrofitJwtService;
17 |
18 | public JwtAuthServiceImpl(RetrofitJwtService retrofitJwtService) {
19 | this.retrofitJwtService = retrofitJwtService;
20 | }
21 |
22 | @Override
23 | public JwtCredential addCredentials(String consumerIdOrUsername, JwtCredential request) {
24 | try {
25 | return retrofitJwtService.addCredentials(consumerIdOrUsername, request).execute().body();
26 | } catch (IOException e) {
27 | throw new KongClientException(e.getMessage());
28 | }
29 | }
30 |
31 | @Override
32 | public void deleteCredentials(String consumerIdOrUsername, String id) {
33 | try {
34 | retrofitJwtService.deleteCredentials(consumerIdOrUsername, id).execute();
35 | } catch (IOException e) {
36 | throw new KongClientException(e.getMessage());
37 | }
38 | }
39 |
40 | @Override
41 | public JwtCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset) {
42 | try {
43 | return retrofitJwtService.listCredentials(consumerIdOrUsername, size, offset).execute().body();
44 | } catch (IOException e) {
45 | throw new KongClientException(e.getMessage());
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/KeyAuthServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication;
2 |
3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.KeyAuthService;
4 | import com.github.vaibhavsinha.kong.exception.KongClientException;
5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitKeyAuthService;
6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential;
7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList;
8 | import retrofit2.Response;
9 |
10 | import java.io.IOException;
11 |
12 | /**
13 | * Created by vaibhav on 15/06/17.
14 | *
15 | * Updated by fanhua on 2017-08-07.
16 | *
17 | * Updated by dvilela on 17/10/17.
18 | */
19 | public class KeyAuthServiceImpl implements KeyAuthService {
20 |
21 | private RetrofitKeyAuthService retrofitKeyAuthService;
22 |
23 | public KeyAuthServiceImpl(RetrofitKeyAuthService retrofitKeyAuthService) {
24 | this.retrofitKeyAuthService = retrofitKeyAuthService;
25 | }
26 |
27 | @Override
28 | public KeyAuthCredential addCredentials(String consumerIdOrUsername, String key) {
29 | try {
30 | Response res = retrofitKeyAuthService.addCredentials(consumerIdOrUsername,
31 | new KeyAuthCredential(key)).execute();
32 | if (res.code() == 201) {
33 | return res.body();
34 | }
35 | throw new KongClientException("Could not create credentials", res.code(), res.message());
36 | } catch (IOException e) {
37 | throw new KongClientException(e.getMessage());
38 | }
39 | }
40 |
41 | @Override
42 | public KeyAuthCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset) {
43 | try {
44 | return retrofitKeyAuthService.listCredentials(consumerIdOrUsername, size, offset).execute().body();
45 | } catch (IOException e) {
46 | throw new KongClientException(e.getMessage());
47 | }
48 | }
49 |
50 | @Override
51 | public void deleteCredential(String consumerIdOrUsername, String id) {
52 | try {
53 | retrofitKeyAuthService.deleteCredential(consumerIdOrUsername, id).execute();
54 | } catch (IOException e) {
55 | throw new KongClientException(e.getMessage());
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/security/AclServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.impl.service.plugin.security;
2 |
3 | import com.github.vaibhavsinha.kong.api.plugin.security.AclService;
4 | import com.github.vaibhavsinha.kong.exception.KongClientException;
5 | import com.github.vaibhavsinha.kong.internal.plugin.security.RetrofitAclService;
6 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.Acl;
7 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.AclList;
8 |
9 | import java.io.IOException;
10 |
11 | /**
12 | * Created by vaibhav on 18/06/17.
13 | *
14 | * Updated by fanhua on 2017-08-07.
15 | *
16 | * Upated by dvilela on 22/10/17.
17 | */
18 | public class AclServiceImpl implements AclService {
19 |
20 | private RetrofitAclService retrofitAclService;
21 |
22 | public AclServiceImpl(RetrofitAclService retrofitAclService) {
23 | this.retrofitAclService = retrofitAclService;
24 | }
25 | @Override
26 | public void associateConsumer(String usernameOrId, String group) {
27 | try {
28 | retrofitAclService.associateConsumer(usernameOrId, new Acl(group)).execute();
29 | } catch (IOException e) {
30 | throw new KongClientException(e.getMessage());
31 | }
32 | }
33 |
34 | @Override
35 | public AclList listAcls(String usernameOrId, Long size, String offset) {
36 | try {
37 | return retrofitAclService.listAcls(usernameOrId, size, offset).execute().body();
38 | } catch (IOException e) {
39 | throw new KongClientException(e.getMessage());
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitApiPluginService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.internal.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin;
4 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
5 |
6 | import retrofit2.Call;
7 | import retrofit2.http.Body;
8 | import retrofit2.http.DELETE;
9 | import retrofit2.http.GET;
10 | import retrofit2.http.PATCH;
11 | import retrofit2.http.POST;
12 | import retrofit2.http.PUT;
13 | import retrofit2.http.Path;
14 | import retrofit2.http.Query;
15 |
16 | /**
17 | * Created by fanhua on 2017-08-05.
18 | */
19 | public interface RetrofitApiPluginService {
20 |
21 |
22 | @POST("/apis/{api}/plugins")
23 | Call addPluginForApi(@Path("api") String apiNameOrId, @Body Plugin plugin);
24 |
25 | @GET("/apis/{api}/plugins/{id}")
26 | Call getPluginForApi(@Path("api") String apiNameOrId, @Path("id") String pluginId);
27 |
28 | @PATCH("/apis/{api}/plugins/{id}")
29 | Call updatePluginForApi(@Path("api") String apiNameOrId, @Path("id") String pluginNameOrId, @Body Plugin request);
30 |
31 | @PUT("/apis/{api}/plugins")
32 | Call createOrUpdatePluginForApi(@Path("api") String apiNameOrId, @Body Plugin plugin);
33 |
34 | @DELETE("/apis/{api}/plugins/{id}")
35 | Call deletePluginForApi(@Path("api") String apiNameOrId, @Path("id") String pluginNameOrId);
36 |
37 | @GET("/apis/{api}/plugins/")
38 | Call listPluginsForApi(@Path("api") String apiNameOrId, @Query("id") String pluginNameOrId, @Query("api_id") String apiId,
39 | @Query("consumer_id") String consumerId, @Query("name") String name, @Query("size") Long size, @Query("offset") String offset);
40 |
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitApiService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.internal.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.api.Api;
4 | import com.github.vaibhavsinha.kong.model.admin.api.ApiList;
5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
6 | import retrofit2.Call;
7 | import retrofit2.http.*;
8 |
9 | /**
10 | * Created by vaibhav on 12/06/17.
11 | */
12 | public interface RetrofitApiService {
13 |
14 | @POST("apis/")
15 | Call createApi(@Body Api request);
16 |
17 | @GET("apis/{id}")
18 | Call getApi(@Path("id") String nameOrId);
19 |
20 | @PATCH("apis/{id}")
21 | Call updateApi(@Path("id") String nameOrId, @Body Api request);
22 |
23 | @Deprecated
24 | @PUT("apis/")
25 | Call createOrUpdateApi(@Body Api request);
26 |
27 | @DELETE("apis/{id}")
28 | Call deleteApi(@Path("id") String nameOrId);
29 |
30 | @GET("apis/")
31 | Call listApis(@Query("id") String id, @Query("upstream_url") String upstreamUrl, @Query("name") String name, @Query("retries") Long retries, @Query("size") Long size, @Query("offset") String offset);
32 |
33 |
34 | @GET("apis/{id}/plugins")
35 | Call listApiPlugins(@Path("id") String nameOrId);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitCertificateService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.internal.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.certificate.Certificate;
4 | import com.github.vaibhavsinha.kong.model.admin.certificate.CertificateList;
5 | import retrofit2.Call;
6 | import retrofit2.http.*;
7 |
8 | /**
9 | * Created by vaibhav on 12/06/17.
10 | */
11 | public interface RetrofitCertificateService {
12 |
13 | @POST("certificates/")
14 | Call createCertificate(@Body Certificate request);
15 |
16 | @GET("certificates/{id}")
17 | Call getCertificate(@Path("id") String sniOrId);
18 |
19 | @PATCH("certificates/{id}")
20 | Call updateCertificate(@Path("id") String sniOrId, @Body Certificate request);
21 |
22 | @PUT("certificates/")
23 | Call createOrUpdateCertificate(@Body Certificate request);
24 |
25 | @DELETE("certificates/{id}")
26 | Call deleteCertificate(@Path("id") String sniOrId);
27 |
28 | @GET("certificates/")
29 | Call listCertificates();
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitConsumerService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.internal.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer;
4 | import com.github.vaibhavsinha.kong.model.admin.consumer.ConsumerList;
5 | import retrofit2.Call;
6 | import retrofit2.http.*;
7 |
8 | /**
9 | * Created by vaibhav on 12/06/17.
10 | */
11 | public interface RetrofitConsumerService {
12 |
13 | @POST("consumers/")
14 | Call createConsumer(@Body Consumer request);
15 |
16 | @GET("consumers/{id}")
17 | Call getConsumer(@Path("id") String usernameOrId);
18 |
19 | @PATCH("consumers/{id}")
20 | Call updateConsumer(@Path("id") String usernameOrId, @Body Consumer request);
21 |
22 | @PUT("consumers/")
23 | Call createOrUpdateConsumer(@Body Consumer request);
24 |
25 | @DELETE("consumers/{id}")
26 | Call deleteConsumer(@Path("id") String usernameOrId);
27 |
28 | @GET("consumers/")
29 | Call listConsumers(@Query("id") String id, @Query("custom_id") String customId, @Query("username") String username, @Query("size") Long size, @Query("offset") String offset);
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitPluginRepoService.java:
--------------------------------------------------------------------------------
1 | package com.github.vaibhavsinha.kong.internal.admin;
2 |
3 | import com.github.vaibhavsinha.kong.model.admin.plugin.EnabledPlugins;
4 | import retrofit2.Call;
5 | import retrofit2.http.GET;
6 | import retrofit2.http.Path;
7 |
8 | /**
9 | * Created by fanhua on 2017-08-05.
10 | */
11 | public interface RetrofitPluginRepoService {
12 |
13 | @GET("/plugins/enabled")
14 | Call retrieveEnabledPlugins();
15 |
16 |
17 | @GET("/plugins/schema/{plugin}")
18 | Call