-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/gov/cdc/usds/simplereport/config/SRProductionClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gov.cdc.usds.simplereport.config; | ||
|
||
import feign.RequestInterceptor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SRProductionClientConfiguration { | ||
|
||
@Value("${simple-report.production.devices-token}") | ||
private String token; | ||
|
||
@Bean | ||
public RequestInterceptor headerRequestInterceptor() { | ||
return template -> { | ||
template.header("Sr-Prod-Devices-Token", token); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.../src/main/java/gov/cdc/usds/simplereport/service/srprodclient/LiveSRProductionClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package gov.cdc.usds.simplereport.service.srprodclient; | ||
|
||
import gov.cdc.usds.simplereport.config.SRProductionClientConfiguration; | ||
import gov.cdc.usds.simplereport.db.model.DeviceType; | ||
import java.util.List; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
/** | ||
* This is intended to run in our lower envs NOT on PROD. This is the client used to make HTTP | ||
* requests to PROD's backend from our non-PROD envs. | ||
*/ | ||
@ConditionalOnProperty(value = "simple-report.production.client-enabled", havingValue = "true") | ||
@FeignClient( | ||
name = "sr-prod", | ||
url = "${simple-report.production.backend-url}", | ||
configuration = SRProductionClientConfiguration.class) | ||
public interface LiveSRProductionClient extends SRProductionClient { | ||
@Override | ||
@GetMapping(value = "/devices") | ||
List<DeviceType> getProdDeviceTypes(); | ||
} |
20 changes: 20 additions & 0 deletions
20
.../src/main/java/gov/cdc/usds/simplereport/service/srprodclient/MockSRProductionClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gov.cdc.usds.simplereport.service.srprodclient; | ||
|
||
import gov.cdc.usds.simplereport.api.model.errors.BadRequestException; | ||
import gov.cdc.usds.simplereport.db.model.DeviceType; | ||
import java.util.List; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* This is intended to run in our PROD env as an alternative to the LiveSRProductionClient, which | ||
* does not need to be run against PROD from PROD. | ||
*/ | ||
@Service | ||
@ConditionalOnProperty(value = "simple-report.production.client-enabled", havingValue = "false") | ||
public class MockSRProductionClient implements SRProductionClient { | ||
@Override | ||
public List<DeviceType> getProdDeviceTypes() { | ||
throw new BadRequestException("SRProductionClient not enabled for this environment"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/gov/cdc/usds/simplereport/service/srprodclient/SRProductionClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package gov.cdc.usds.simplereport.service.srprodclient; | ||
|
||
import gov.cdc.usds.simplereport.db.model.DeviceType; | ||
import java.util.List; | ||
|
||
public interface SRProductionClient { | ||
List<DeviceType> getProdDeviceTypes(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...java/gov/cdc/usds/simplereport/service/srproductionclient/MockSRProductionClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package gov.cdc.usds.simplereport.service.srproductionclient; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import gov.cdc.usds.simplereport.api.model.errors.BadRequestException; | ||
import gov.cdc.usds.simplereport.service.BaseServiceTest; | ||
import gov.cdc.usds.simplereport.service.srprodclient.SRProductionClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
@TestPropertySource(properties = {"simple-report.production.client-enabled=false"}) | ||
public class MockSRProductionClientTest extends BaseServiceTest<SRProductionClient> { | ||
|
||
@Test | ||
void getProdDeviceTypes_throwsException() { | ||
BadRequestException caught = | ||
assertThrows(BadRequestException.class, () -> _service.getProdDeviceTypes()); | ||
assertEquals("SRProductionClient not enabled for this environment", caught.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters