Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5bf27c7
refactored proto files generation
Avinash-Kamath Oct 27, 2024
81aeedf
remove .artifact files
Avinash-Kamath Oct 27, 2024
44aa3c4
remove .artifact files
Avinash-Kamath Oct 27, 2024
6243e2e
Initial Direactory Changes
Avinash-Kamath Oct 27, 2024
e1b8186
Add enable disable directory
Avinash-Kamath Oct 27, 2024
05cc66b
Add Webhook signature Check
Avinash-Kamath Oct 27, 2024
cb0f349
Add Tests for webhook signature validator
Avinash-Kamath Oct 28, 2024
b9ec0de
Add Tests for webhook signature validator
Avinash-Kamath Oct 28, 2024
392029f
Update dependencies
Avinash-Kamath Oct 28, 2024
7aaf703
Update dependencies
Avinash-Kamath Oct 28, 2024
8675b96
add build to make file
Avinash-Kamath Oct 28, 2024
6c86072
remove unused imports
Avinash-Kamath Oct 28, 2024
dde9a4b
Added Helper method to get directory by orgId
Avinash-Kamath Nov 6, 2024
0ccc26e
Added Helper method to get directory by orgId
Avinash-Kamath Nov 6, 2024
ac9b411
Create access token on first GRPC call
Avinash-Kamath Nov 8, 2024
882bdd3
remove proto files
Avinash-Kamath Nov 11, 2024
d3339a2
remove proto files
Avinash-Kamath Nov 12, 2024
3f83a20
remove proto files
Avinash-Kamath Nov 12, 2024
03a9d35
remove proto files
Avinash-Kamath Nov 12, 2024
31ee75f
remove proto files
Avinash-Kamath Nov 12, 2024
f8578bf
remove makefile
Avinash-Kamath Nov 12, 2024
9a1f8c9
fixed tests
Avinash-Kamath Nov 12, 2024
a2d1975
Fixed Get Primary Directory
Avinash-Kamath Nov 13, 2024
0669c45
Added Get Directory Method
Avinash-Kamath Nov 18, 2024
406af45
Add Wrapper for directory User Method
Avinash-Kamath Nov 20, 2024
e35aed7
Add Wrapper for directory Group Method
Avinash-Kamath Nov 20, 2024
0683df9
Add plugin for shading dependencies
Avinash-Kamath Nov 20, 2024
08a7be8
Add Javadoc for methods
Avinash-Kamath Nov 22, 2024
fff4dd8
updated version in README.md
Avinash-Kamath Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
*.env
makefile

### IntelliJ IDEA ###
proto/
### IntelliJ IDEA #git ##
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
Expand All @@ -12,6 +15,8 @@ target/
*.iml
*.ipr
.idea/
.artifacts/


### Eclipse ###
.apt_generated
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Add this dependency to your project's build file:

```gradle
implementation "com.scalekit:scalekit-sdk-java:1.0.1"
implementation "com.scalekit:scalekit-sdk-java:1.0.2"
```

### Maven users
Expand All @@ -41,7 +41,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.scalekit</groupId>
<artifactId>scalekit-sdk-java</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/buf.gen.yaml → buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ managed:


plugins:
- plugin: buf.build/grpc/java:v1.64.0
out: ./../../java/
- plugin: buf.build/grpc/java:v1.67.1 #corresponds to grpc-java v1.67.1
out: .artifacts
opt: paths=source_relative
- plugin: buf.build/protocolbuffers/java:v25.3 #corresponds to protobuf-java v3.25.3
out: ./../../java/
out: .artifacts
3 changes: 3 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- proto
81 changes: 71 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.scalekit</groupId>
<artifactId>scalekit-sdk-java</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -65,9 +65,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<io.grpc.version>1.67.1</io.grpc.version>

<io.grpc.version>1.64.0</io.grpc.version>
<io.grpc.protobuf>3.25.3</io.grpc.protobuf>
</properties>

<dependencies>
Expand All @@ -78,19 +77,24 @@
<version>${io.grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${io.grpc.version}</version>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.25.5</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.64.0</version>
<artifactId>grpc-stub</artifactId>
<version>${io.grpc.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${io.grpc.protobuf}</version>
<version>3.25.5</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${io.grpc.version}</version>
</dependency>
<dependency>
<groupId>build.buf</groupId>
Expand Down Expand Up @@ -155,7 +159,7 @@
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
<autoPublish>false</autoPublish>
</configuration>
</plugin>

Expand Down Expand Up @@ -209,6 +213,63 @@
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<!-- Relocate common libraries -->
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>com.scalekit.shaded.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>com.scalekit.shaded.google</shadedPattern>
</relocation>
<relocation>
<pattern>io.grpc</pattern>
<shadedPattern>com.scalekit.shaded.grpc</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<excludes>
<exclude>org.projectlombok:lombok</exclude>
<exclude>javax.annotation:javax.annotation-api</exclude>
<exclude>org.slf4j:slf4j-nop</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/LICENSE.*</exclude>
<exclude>META-INF/NOTICE.*</exclude>
<exclude>META-INF/*</exclude>
<exclude>module-info.class</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>


</plugins>
</build>
</project>
31 changes: 21 additions & 10 deletions src/main/java/com/scalekit/ScalekitClient.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.scalekit;

import com.scalekit.api.AuthClient;
import com.scalekit.api.ConnectionClient;
import com.scalekit.api.DomainClient;
import com.scalekit.api.OrganizationClient;
import com.scalekit.api.impl.ScalekitAuthClient;
import com.scalekit.api.impl.ScalekitConnectionClient;
import com.scalekit.api.impl.ScalekitDomainClient;
import com.scalekit.api.impl.ScalekitOrganizationClient;
import com.scalekit.api.*;
import com.scalekit.api.impl.*;
import com.scalekit.exceptions.APIException;
import com.scalekit.internal.ScalekitCredentials;
import com.scalekit.webhooks.ScalekitWebhook;
import com.scalekit.webhooks.Webhook;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

Expand All @@ -28,15 +24,18 @@ public class ScalekitClient {

private final ScalekitAuthClient authenticationClient;

private final DirectoryClient directoryClient ;

private final Webhook webhook;

public ScalekitClient(String siteName, String clientId, String clientSecret) {

Environment.configure(siteName,clientId,clientSecret);
Environment environment = Environment.defaultConfig();


authenticationClient = new ScalekitAuthClient();
String token = authenticationClient.getClientAccessToken();
ScalekitCredentials credentials = new ScalekitCredentials(token);
ScalekitCredentials credentials = new ScalekitCredentials(authenticationClient);
try {
URL url = URI.create(environment.siteName).toURL();
// Managed channel automatically handles channel closing
Expand All @@ -48,6 +47,10 @@ public ScalekitClient(String siteName, String clientId, String clientSecret) {
organizationClient = new ScalekitOrganizationClient(channel, credentials);
domainClient = new ScalekitDomainClient(channel, credentials);
connectionClient = new ScalekitConnectionClient(channel, credentials);
directoryClient = new ScalekitDirectoryClient(channel, credentials);

webhook = new ScalekitWebhook();

} catch (MalformedURLException e) {
throw new APIException("invalid environment URL, error:" + e.getMessage());
}
Expand All @@ -72,4 +75,12 @@ public AuthClient authentication() {
return this.authenticationClient;
}

public Webhook webhook() {
return this.webhook;
}

public DirectoryClient directories() {
return this.directoryClient;
}

}
23 changes: 23 additions & 0 deletions src/main/java/com/scalekit/api/DirectoryClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.scalekit.api;

import com.scalekit.api.util.ListDirectoryGroupResponse;
import com.scalekit.api.util.ListDirectoryResourceOptions;
import com.scalekit.api.util.ListDirectoryUserResponse;
import com.scalekit.grpc.scalekit.v1.directories.*;

public interface DirectoryClient {

Directory getDirectory(String directoryId, String organizationId);

ListDirectoriesResponse listDirectories(String organizationId);

ListDirectoryUserResponse listDirectoryUsers(String directoryId, String organizationId, ListDirectoryResourceOptions options);

ListDirectoryGroupResponse listDirectoryGroups(String directoryId, String organizationId, ListDirectoryResourceOptions options);

ToggleDirectoryResponse enableDirectory(String directoryId, String organizationId);

ToggleDirectoryResponse disableDirectory(String directoryId, String organizationId);

Directory getPrimaryDirectoryByOrganizationId(String organizationId);
}
2 changes: 2 additions & 0 deletions src/main/java/com/scalekit/api/OrganizationClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface OrganizationClient {

Link generatePortalLink(String organizationId);

Organization updateOrganizationSettings(String organizationId, List<OrganizationSettingsFeature> settings);

}
28 changes: 28 additions & 0 deletions src/main/java/com/scalekit/api/impl/ScalekitAuthClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public String getClientAccessToken(){
}
}


/**
* getAuthorizationUrl generates an authorization URL
* @param redirectUri: The redirect URI
* @param options: The AuthorizationUrlOptions
* @return URL: The authorization URL
* @throws APIException: If an error occurs
*/
public URL getAuthorizationUrl(String redirectUri, AuthorizationUrlOptions options){
List<String> scopes = new ArrayList<>();
scopes.add("openid");
Expand Down Expand Up @@ -114,6 +122,12 @@ public URL getAuthorizationUrl(String redirectUri, AuthorizationUrlOptions optio
}
}

/**
* validateAccessToken validates an access token
* @param jwt: The JWT token
* @return boolean: True if the token is valid
* @throws APIException: If an error occurs
*/
public boolean validateAccessToken(String jwt) throws APIException{
try {
// TODO Optimization - Cache the keys
Expand All @@ -137,6 +151,14 @@ public boolean validateAccessToken(String jwt) throws APIException{
}
}

/**
* authenticateWithCode authenticates with a code
* @param code: The code
* @param redirectUri: The redirect URI
* @param options: The AuthenticationOptions
* @return AuthenticationResponse: The authentication response
* @throws APIException: If an error occurs
*/
public AuthenticationResponse authenticateWithCode(String code, String redirectUri, AuthenticationOptions options) {
if (code == null || code.isEmpty() || redirectUri == null || redirectUri.isEmpty()) {
throw new APIException("code and redirect uri are required");
Expand Down Expand Up @@ -202,6 +224,12 @@ private AuthenticationResponse authenticate(Map<String, String> requestData) thr
return objectMapper.readValue(response.body(), AuthenticationResponse.class);
}

/**
* getIdpInitiatedLoginClaims gets the claims from an idpInitiatedLoginToken
* @param idpInitiatedLoginToken: The idpInitiatedLoginToken
* @return IdpInitiatedLoginClaims: The claims
* @throws APIException: If an error occurs
*/
public IdpInitiatedLoginClaims getIdpInitiatedLoginClaims(String idpInitiatedLoginToken) throws APIException {
try {
boolean isTokenValid = validateAccessToken(idpInitiatedLoginToken);
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/scalekit/api/impl/ScalekitConnectionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ScalekitConnectionClient(ManagedChannel channel, ScalekitCredentials cred
}


/*
/**
* getConnectionById retrieves a connection by its ID
* @param connectionId: The connection ID
* @param organizationId: The organization ID
Expand All @@ -47,7 +47,7 @@ public Connection getConnectionById(String connectionId, String organizationId)
}
}

/*
/**
* listConnectionsByDomain retrieves a list of connections by domain
* @param domain: The domain
* @return List<Connection>: The list of connections
Expand All @@ -66,7 +66,7 @@ public ListConnectionsResponse listConnectionsByDomain(String domain) {
}
}

/*
/**
* listConnectionsByOrganization retrieves a list of connections by organization
* @param organizationId: The organization ID
* @return List<Connection>: The list of connections
Expand All @@ -86,6 +86,14 @@ public ListConnectionsResponse listConnectionsByOrganization(String organization
}
}


/**
* enableConnection enables a connection by its ID and organization ID
* @param connectionId: The connection ID
* @param organizationId: The organization ID
* @return ToggleConnectionResponse: The response after enabling the connection
* @throws APIException: If an error occurs
*/
@Override
public ToggleConnectionResponse enableConnection(String connectionId, String organizationId) {
ToggleConnectionRequest request = ToggleConnectionRequest.newBuilder()
Expand All @@ -101,6 +109,13 @@ public ToggleConnectionResponse enableConnection(String connectionId, String org

}

/**
* disableConnection disables a connection by its ID and organization ID
* @param connectionId: The connection ID
* @param organizationId: The organization ID
* @return ToggleConnectionResponse: The response after disabling the connection
* @throws APIException: If an error occurs
*/
@Override
public ToggleConnectionResponse disableConnection(String connectionId, String organizationId) {
ToggleConnectionRequest request = ToggleConnectionRequest.newBuilder()
Expand Down
Loading