GithubHelp home page GithubHelp logo

robinbraemer / cloudflareapi Goto Github PK

View Code? Open in Web Editor NEW
58.0 2.0 21.0 166 KB

The most complete and extensible Cloudflare API v4 client library for Java.

Home Page: https://api.cloudflare.com/

License: Apache License 2.0

Java 100.00%
java-8 java cloudflare cloudflare-api api library dns oop client lib

cloudflareapi's Introduction

The Cloudflare - API/Library for Java

Jitpack-Month JitPack Travis License

This Cloudflare API/Library interacts with Cloudflare's fast API v4 and allows you to access every single feature (even if it isn't added yet) of Cloudflare's API faster and much easier!

To add a dependency on this Cloudflare-API/Library using Maven or Gradle use the following:

Maven:

<dependency>
  <groupId>com.github.robinbraemer</groupId>
  <artifactId>cloudflareapi</artifactId>
  <version>GIT_COMMIT_SHA</version>
</dependency>
	
<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

Gradle:

dependencies {
  compile 'com.github.robinbraemer:cloudflareapi:<GIT_COMMIT_SHA>'
}

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}

Features

  • easy to build cloudflare requests (builder pattern)
  • able to access every corner of cloudflare's api
  • parsing results as objects (object oriented representation)
  • it is an extremely flexible api
  • asynchronicity support
  • token & key+email authentication support

Getting Started

First, you define the access object.

String CF_API_TOKEN = "your_cloudflare_api_token";
CloudflareAccess cfAccess = new CloudflareAccess(CF_API_TOKEN);

Or use key+email authentication:

String CF_API_KEY = "your_cloudflare_api_key";
String CF_EMAIL = "[email protected]";
CloudflareAccess cfAccess = new CloudflareAccess(CF_API_KEY, CF_EMAIL);

Then you can create cloudflare requests.

CloudflareResponse<List<Zone>> response =
    new CloudflareRequest( Category.LIST_ZONES, cfAccess )
        .asObjectList( Zone.class );

Learn more about the Cloudflare - client library

Licensing

Licensed under the Apache License 2.0. See the LICENSE file for details.

cloudflareapi's People

Contributors

c-wolfe avatar dependabot[bot] avatar elifarley avatar janrabek avatar mj-mueller avatar renovate[bot] avatar robinbraemer avatar roboflax avatar zdmytriv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cloudflareapi's Issues

Example of getting the ID of a zone

Thank you for building this API wrapper.

Would it be possible, that you could provide an example of how to obtain the ID for a specific zone? Because most zone related methods rely on the zone ID and i would prefer not to hardcode it.

What i've got so far (with my very little JAVA experience):

CloudflareResponse<List<Zone>> response =
    new CloudflareRequest(Category.LIST_ZONES, cfAccess)
        .queryString("name", "mydomain.tld")
        .asObjectList(Zone.class);
        
String jsonString = response.getJson().toString();
String zoneID = JsonPath.read(jsonString, "$.result[0].id");

System.out.print(zoneID);

That seems to work, but i'm curious, if there's an easier way. It would be nice, if we could utilize the methods within the object classes (e.g. Zone.getId(), etc.). Maybe, that's already possible and i'm just too stupid to figure it out ๐Ÿ˜†

Add Cloudflare Tunnel support

Cloudflare API reference for Cloudflare Tunnel creation:
https://api.cloudflare.com/#cloudflare-tunnel-create-cloudflare-tunnel

Example Cloudflare API call to create a Cloudflare tunnel:

curl --request POST \
  --url https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/cfd_tunnel \
  --header 'Authorization: Bearer BEARER_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
	"name": "TUNNEL_NAME",
	"tunnel_secret": "TUNNEL_SECRET_ENCODED_IN_BASE64"
}'

Example of creating zone

Thank You for creating this library. Cloud flares API has a learning curve.

It would be very useful if you can add an example how to create a zone using the library in the wiki.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: renovate.json
Error type: Invalid JSON (parsing failed)
Message: Syntax error: expecting end of expression or separator near ] "pack

Publish to Maven Central

Obvious question: Can you please publish your library to Maven Central? It would make it a lot easier for end-users to work with it.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

maven
pom.xml
  • org.apache.maven.plugins:maven-compiler-plugin 3.11.0
  • org.apache.maven.plugins:maven-assembly-plugin 3.5.0
  • org.apache.maven.plugins:maven-source-plugin 3.2.1
  • junit:junit 4.13.2
  • org.apache.commons:commons-lang3 3.13.0
  • com.google.code.gson:gson 2.10.1
  • com.google.guava:guava 32.0.0-jre
  • org.projectlombok:lombok 1.18.26
  • io.joshworks.unirest:unirest-java 1.8.0

  • Check this box to trigger a request for Renovate to run again on this repository

Add Access Application creation support

Cloudflare API reference for Access Application creation:
https://api.cloudflare.com/#access-applications-create-access-application

Example Cloudflare API call to create Access Application:

curl --request POST \
  --url https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/access/apps \
  --header 'Authorization: Bearer BEARER_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
	"name": "ACCESS_APP_NAME",
	"logo_url": "",
	"allowed_idps": [],
	"auto_redirect_to_identity": false,
	"service_auth_401_redirect": false,
	"policies": [
		{
			"decision": "non_identity",
			"name": "POLICY_NAME",
			"include": [
				{
					"service_token": {
						"token_id": "SERVICE_TOKEN_ID"
					}
				}
			],
			"exclude": [],
			"require": [],
			"precedence": 1
		}
	],
	"session_duration": "24h",
	"app_launcher_visible": true,
	"app_groups": [],
	"selected_app_groups": [],
	"is_zt_ssh_app": false,
	"domain": "ZONE_FQDN"
}'

Question about listing and creating dns record.

Hey! i am happy there is a api but my question was if you may can provide a example of creating a dns record and or a dns list because i cannot figure it out :)

Edit: i figured out that you can use .identifiers(ZONEID) on the cloudflare object to add the zone id

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.