Skip to content

Commit 1835b05

Browse files
Init Tailscale Wrapper
1 parent 4b7f003 commit 1835b05

22 files changed

+620
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ out/
3939
.idea/uiDesigner.xml
4040
.idea/compiler.xml
4141
.idea/vcs.xml
42+
src/main/java/pl/indianbartonka/tailscale/Test.java

README.MD

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Tailscale Java Wrapper
2+
3+
A wrapper for the Tailscale API. For more information, visit the official [Tailscale API documentation](https://tailscale.com/api).
4+
5+
This example demonstrates how to use the `TailscaleClient` in Java to interact with the Tailscale API. It covers retrieving device details, updating device attributes, managing routes, and more.
6+
7+
## Prerequisites
8+
9+
- A Tailscale account.
10+
- A valid Tailscale [API key](https://login.tailscale.com/admin/settings/keys).
11+
12+
## Example Usage
13+
14+
```java
15+
final TailscaleClient client = new TailscaleClient("Organization Name", "API Token");
16+
17+
// You can also set a custom OkHttp client, Gson client, and a custom BaseUrl
18+
// TailscaleClient#setHttpClient
19+
// TailscaleClient#setGson
20+
// TailscaleClient#setBaseUrl
21+
22+
// Getting all network devices
23+
final List<Device> devices = client.getDevices();
24+
25+
final String deviceId = devices.get(0).id();
26+
final Device device = client.getDevice(deviceId);
27+
28+
System.out.println();
29+
System.out.println();
30+
31+
// Example of expiring a device
32+
System.out.println("Device expired: " + client.setExpire(deviceId));
33+
34+
// Example of changing the authorization status
35+
System.out.println("Authorization changed: " + client.setAuthorized(deviceId, true));
36+
37+
// Example of changing the device name
38+
System.out.println("Device name changed: " + client.setName(deviceId, "Device " + MessageUtil.generateCode(10)));
39+
40+
// Example of setting tags
41+
System.out.println("Tags set: " + client.setTags(deviceId, Map.of("tagKey", "tagValue")));
42+
43+
// Example of disabling key expiry
44+
System.out.println("Key expiry disabled: " + client.setKeyExpiryDisabled(deviceId, true));
45+
46+
// Example of setting an IP address
47+
System.out.println("IPv4 set: " + client.setIpV4(deviceId, "100.80.0.1"));
48+
49+
// Example of fetching device attributes
50+
final AttributesResponse attributesResponse = client.getAttributes(deviceId);
51+
System.out.println("Attributes: " + attributesResponse);
52+
53+
// Example of setting an attribute on the device
54+
final AttributesRequest attributesRequest = new AttributesRequest("value", "my_value");
55+
final boolean isSet = client.setAttributes(deviceId, "custom:Koo", attributesRequest);
56+
System.out.println("Attribute set: " + isSet);
57+
58+
// Example of deleting an attribute from the device
59+
final boolean isDeleted = client.deleteAttributes(deviceId, "custom:Koo");
60+
System.out.println("Attribute deleted: " + isDeleted);
61+
62+
// Example of working with routes
63+
System.out.println(client.getRoutes(deviceId));
64+
System.out.println(client.setRoutes(deviceId, new RoutesRequest(List.of("10.0.0.0/16", "192.168.1.0/24"))));
65+
System.out.println(client.getRoutes(deviceId));
66+
67+
// Example of deleting a device
68+
System.out.println("Device deleted: " + client.deleteDevice(deviceId));

pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>pl.indianbartonka.watchdog</groupId>
8+
<artifactId>tailscale-wrapper</artifactId>
9+
<version>1.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
<maven.compiler.target>17</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<repositories>
18+
<repository>
19+
<id>jitpack.io</id>
20+
<url>https://jitpack.io</url>
21+
</repository>
22+
</repositories>
23+
24+
<dependencies>
25+
<!-- It contains Jetbrains Annotations and Gson and manu other utils -->
26+
<dependency>
27+
<groupId>com.github.IndianBartonka</groupId>
28+
<artifactId>Indian-Utils</artifactId>
29+
<version>0.0.8.1</version>
30+
<scope>compile</scope>
31+
</dependency>
32+
33+
<!-- HTTP Requests -->
34+
<dependency>
35+
<groupId>com.squareup.okhttp3</groupId>
36+
<artifactId>okhttp</artifactId>
37+
<version>5.0.0-alpha.12</version>
38+
<scope>compile</scope>
39+
</dependency>
40+
</dependencies>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-compiler-plugin</artifactId>
47+
<version>3.8.1</version>
48+
<configuration>
49+
<source>17</source>
50+
<target>17</target>
51+
<compilerArgs>
52+
<arg>-parameters</arg>
53+
</compilerArgs>
54+
</configuration>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-shade-plugin</artifactId>
59+
<version>3.2.4</version>
60+
<executions>
61+
<execution>
62+
<phase>package</phase>
63+
<goals>
64+
<goal>shade</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
</plugins>
70+
<finalName>${project.name}-${project.version}</finalName>
71+
<resources>
72+
<resource>
73+
<directory>src/main/resources/</directory>
74+
<filtering>true</filtering>
75+
</resource>
76+
</resources>
77+
</build>
78+
79+
</project>

0 commit comments

Comments
 (0)