Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3bf6c2fe
Commit
3bf6c2fe
authored
Nov 21, 2015
by
Patrick Bray
Committed by
Stephane Nicoll
Jan 26, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for SendGrid ApiKey
See gh-4574
parent
f9fd849a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
3 deletions
+53
-3
SendGridAutoConfiguration.java
...oot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
+29
-3
SendGridProperties.java
...ework/boot/autoconfigure/sendgrid/SendGridProperties.java
+13
-0
SendGridAutoConfigurationTests.java
...utoconfigure/sendgrid/SendGridAutoConfigurationTests.java
+11
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
View file @
3bf6c2fe
...
...
@@ -22,11 +22,13 @@ import org.apache.http.impl.client.HttpClientBuilder;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.AnyNestedCondition
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
/**
...
...
@@ -37,7 +39,7 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
@ConditionalOnClass
(
SendGrid
.
class
)
@Conditional
OnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"username"
)
@Conditional
(
SendGridAutoConfiguration
.
SendGridPropertyCondition
.
class
)
@EnableConfigurationProperties
(
SendGridProperties
.
class
)
public
class
SendGridAutoConfiguration
{
...
...
@@ -47,15 +49,39 @@ public class SendGridAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
SendGrid
.
class
)
public
SendGrid
sendGrid
()
{
SendGrid
sendGrid
=
new
SendGrid
(
this
.
properties
.
getUsername
(),
this
.
properties
.
getPassword
());
SendGrid
sendGrid
;
if
(
this
.
properties
.
getApikey
()
!=
null
)
{
sendGrid
=
new
SendGrid
(
this
.
properties
.
getApikey
());
}
else
{
sendGrid
=
new
SendGrid
(
this
.
properties
.
getUsername
(),
this
.
properties
.
getPassword
());
}
if
(
this
.
properties
.
isProxyConfigured
())
{
HttpHost
proxy
=
new
HttpHost
(
this
.
properties
.
getProxy
().
getHost
(),
this
.
properties
.
getProxy
().
getPort
());
sendGrid
.
setClient
(
HttpClientBuilder
.
create
().
setProxy
(
proxy
)
.
setUserAgent
(
"sendgrid/"
+
sendGrid
.
getVersion
()
+
";java"
).
build
());
}
return
sendGrid
;
}
static
class
SendGridPropertyCondition
extends
AnyNestedCondition
{
SendGridPropertyCondition
()
{
super
(
ConfigurationPhase
.
PARSE_CONFIGURATION
);
}
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"username"
)
private
class
SendGridUserProperty
{
}
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"apikey"
)
private
class
SendGridApiKeyProperty
{
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridProperties.java
View file @
3bf6c2fe
...
...
@@ -37,11 +37,24 @@ public class SendGridProperties {
*/
private
String
password
;
/**
* SendGrid api key.
*/
private
String
apikey
;
/**
* Proxy configuration.
*/
private
Proxy
proxy
;
public
String
getApikey
()
{
return
this
.
apikey
;
}
public
void
setApikey
(
final
String
apikey
)
{
this
.
apikey
=
apikey
;
}
public
String
getUsername
()
{
return
this
.
username
;
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java
View file @
3bf6c2fe
...
...
@@ -58,6 +58,17 @@ public class SendGridAutoConfigurationTests {
assertEquals
(
"secret"
,
ReflectionTestUtils
.
getField
(
sendGrid
,
"password"
));
}
@Test
public
void
expectedSendGridBeanCreated_UsingApiKey
()
{
loadContext
(
"spring.sendgrid.apikey:SG.SECRET-API-KEY"
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
assertEquals
(
"SG.SECRET-API-KEY"
,
ReflectionTestUtils
.
getField
(
sendGrid
,
"password"
));
}
@Test
(
expected
=
NoSuchBeanDefinitionException
.
class
)
public
void
autoConfigurationNotFiredWhenPropertiesNotSet
()
{
loadContext
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment