Skip to content

Commit 9218864

Browse files
authored
Merge pull request #8 from devondragon/3-more-component-issues-2
3 more component issues 2
2 parents b597fc4 + c1b6c12 commit 9218864

12 files changed

Lines changed: 225 additions & 153 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Add the following dependency to your `pom.xml`:
3636
<dependency>
3737
<groupId>com.digitalsanctuary</groupId>
3838
<artifactId>ds-spring-cf-turnstile</artifactId>
39-
<version>1.1.4</version>
39+
<version>1.1.5</version>
4040
</dependency>
4141
```
4242

@@ -46,7 +46,7 @@ Add the following dependency to your `build.gradle`:
4646

4747
```groovy
4848
dependencies {
49-
implementation 'com.digitalsanctuary:ds-spring-cf-turnstile:1.1.4'
49+
implementation 'com.digitalsanctuary:ds-spring-cf-turnstile:1.1.5'
5050
}
5151
```
5252

@@ -115,7 +115,7 @@ The Turnstile token is passed as a request parameter named `cf-turnstile-respons
115115

116116
```java
117117
...
118-
import com.digitalsanctuary.cf.turnstile.TurnstileValidationService; // Import the TurnstileValidationService
118+
import com.digitalsanctuary.cf.turnstile.service.TurnstileValidationService; // Import the TurnstileValidationService
119119
...
120120
@Autowired
121121
private TurnstileValidationService turnstileValidationService; // Inject the TurnstileValidationService

build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.vanniktech.maven.publish.JavaLibrary
1313
import com.vanniktech.maven.publish.JavadocJar
1414

1515
group 'com.digitalsanctuary.cf.turnstile'
16-
version '1.1.4'
16+
version '1.1.5'
1717
description = 'SpringBoot Cloudflare Turnstile Library'
1818

1919
ext {
@@ -135,3 +135,18 @@ mavenPublishing {
135135
tasks.named("publishMavenPublicationToMavenCentralRepository") {
136136
dependsOn("signMavenPublication")
137137
}
138+
139+
publishing {
140+
repositories {
141+
maven {
142+
name = 'reposiliteRepository'
143+
url = uri('https://reposilite.tr0n.io/private')
144+
credentials(PasswordCredentials)
145+
authentication {
146+
basic(BasicAuthentication)
147+
}
148+
}
149+
// more repositories can go here
150+
}
151+
}
152+

src/main/java/com/digitalsanctuary/cf/turnstile/TurnstileConfiguration.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.digitalsanctuary.cf.turnstile;
22

33
import org.springframework.boot.autoconfigure.AutoConfiguration;
4-
import org.springframework.boot.web.client.RestTemplateBuilder;
5-
import org.springframework.context.annotation.Bean;
64
import org.springframework.context.annotation.Configuration;
7-
import org.springframework.web.client.RestTemplate;
5+
import org.springframework.context.annotation.Import;
6+
import com.digitalsanctuary.cf.turnstile.config.TurnstileConfigProperties;
7+
import com.digitalsanctuary.cf.turnstile.config.TurnstileServiceConfig;
88
import jakarta.annotation.PostConstruct;
99
import lombok.extern.slf4j.Slf4j;
1010

1111
/**
12-
* A configuration class for the Spring AI Client.
12+
* A configuration class for the Cloudflare Turnstile Client Service.
1313
* <p>
1414
* This class is responsible for configuring the necessary components and dependencies required by the client.
1515
* </p>
@@ -21,22 +21,13 @@
2121
@Slf4j
2222
@Configuration
2323
@AutoConfiguration
24+
@Import({TurnstileServiceConfig.class, TurnstileConfigProperties.class})
2425
public class TurnstileConfiguration {
2526

26-
@Bean
27-
public RestTemplate turnstileRestTemplate(RestTemplateBuilder builder) {
28-
return builder.build();
29-
}
30-
31-
@Bean
32-
public TurnstileValidationService turnstileValidationService() {
33-
return new TurnstileValidationService(turnstileRestTemplate(new RestTemplateBuilder()));
34-
}
35-
3627
/**
3728
* Method executed after the bean initialization.
3829
* <p>
39-
* This method logs a message indicating that the DigitalSanctuary Spring AI Client has been loaded.
30+
* This method logs a message indicating that the DigitalSanctuary Cloudflare Turnstile Service has been loaded.
4031
* </p>
4132
*/
4233
@PostConstruct

src/main/java/com/digitalsanctuary/cf/turnstile/TurnstileValidationService.java

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.digitalsanctuary.cf.turnstile.config;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.context.annotation.PropertySource;
5+
import org.springframework.stereotype.Component;
6+
import lombok.Data;
7+
8+
/**
9+
* Configuration properties for Turnstile integration. This class holds the properties required to configure the Turnstile service, such as the secret
10+
* key, site key, and the URL for the Turnstile API.
11+
*/
12+
@Data
13+
@Component
14+
@PropertySource("classpath:config/turnstile.properties")
15+
@ConfigurationProperties(prefix = "ds.cf.turnstile")
16+
public class TurnstileConfigProperties {
17+
18+
/**
19+
* The secret key used for Turnstile API authentication.
20+
*/
21+
private String secret;
22+
23+
/**
24+
* The site key used for Turnstile API authentication.
25+
*/
26+
private String sitekey;
27+
28+
/**
29+
* The URL for the Turnstile API.
30+
*/
31+
private String url;
32+
33+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.digitalsanctuary.cf.turnstile.config;
2+
3+
import org.springframework.boot.web.client.RestTemplateBuilder;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.http.HttpHeaders;
7+
import org.springframework.http.MediaType;
8+
import org.springframework.web.client.RestClient;
9+
import org.springframework.web.client.RestTemplate;
10+
import com.digitalsanctuary.cf.turnstile.service.TurnstileValidationService;
11+
import lombok.RequiredArgsConstructor;
12+
import lombok.extern.slf4j.Slf4j;
13+
14+
/**
15+
* Configuration class for setting up Turnstile related beans. This class configures the RestTemplate and RestClient used for Turnstile API
16+
* interactions, and initializes the TurnstileValidationService.
17+
*/
18+
@Slf4j
19+
@Configuration
20+
@RequiredArgsConstructor
21+
public class TurnstileServiceConfig {
22+
23+
private final TurnstileConfigProperties properties;
24+
25+
/**
26+
* Creates a RestTemplate bean for Turnstile API interactions.
27+
*
28+
* @param builder the RestTemplateBuilder used to build the RestTemplate
29+
* @return a configured RestTemplate instance
30+
*/
31+
@Bean
32+
public RestTemplate turnstileRestTemplate(RestTemplateBuilder builder) {
33+
return builder.build();
34+
}
35+
36+
/**
37+
* Creates a TurnstileValidationService bean.
38+
*
39+
* @return a configured TurnstileValidationService instance
40+
*/
41+
@Bean
42+
public TurnstileValidationService turnstileValidationService() {
43+
return new TurnstileValidationService(turnstileRestClient(), properties);
44+
}
45+
46+
/**
47+
* Creates a RestClient bean for Turnstile API interactions.
48+
*
49+
* @return a configured RestClient instance
50+
*/
51+
@Bean(name = "turnstileRestClient")
52+
public RestClient turnstileRestClient() {
53+
log.info("Creating Turnstile REST client with endpoint: {}", properties.getUrl());
54+
return RestClient.builder().baseUrl(properties.getUrl()).defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
55+
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).build();
56+
}
57+
58+
}

src/main/java/com/digitalsanctuary/cf/turnstile/TurnstileResponse.java renamed to src/main/java/com/digitalsanctuary/cf/turnstile/dto/TurnstileResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.digitalsanctuary.cf.turnstile;
1+
package com.digitalsanctuary.cf.turnstile.dto;
22

33
import java.util.List;
44
import com.fasterxml.jackson.annotation.JsonProperty;

0 commit comments

Comments
 (0)