Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronus forked code #8

Merged
merged 6 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions apollo-portal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<!-- end of JDK 1.8+ -->
<!-- JDK 11+ -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,28 @@ public String consumerTokenSalt() {
return getValue("consumer.token.salt", "apollo-portal");
}

public boolean isEmailEnabled() {
return getBooleanProperty("email.enabled", false);
}

public String emailConfigHost() {
return getValue("email.config.host", "");
}

public String emailConfigUser() {
return getValue("email.config.user", "");
}

public String emailConfigPassword() {
return getValue("email.config.password", "");
}

public String emailSender() {
return getValue("email.sender");
String value = getValue("email.sender", "");
if (Strings.isNullOrEmpty(value)) {
value = emailConfigUser();
}
return value;
}

public String emailTemplateFramework() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.base.Strings;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -35,9 +36,9 @@ public ItemChangeSets resolve(long namespaceId, String configText, List<ItemDTO>
oldKeyMapItem.remove("");

String[] newItems = configText.split(ITEM_SEPARATOR);

if (isHasRepeatKey(newItems)) {
throw new BadRequestException("config text has repeat key please check.");
Set<String> repeatKeys = new HashSet<>();
if (isHasRepeatKey(newItems, repeatKeys)) {
throw new BadRequestException(String.format("Config text has repeated keys: %s, please check your input.", repeatKeys.toString()));
}

ItemChangeSets changeSets = new ItemChangeSets();
Expand Down Expand Up @@ -72,24 +73,24 @@ public ItemChangeSets resolve(long namespaceId, String configText, List<ItemDTO>
return changeSets;
}

private boolean isHasRepeatKey(String[] newItems) {
private boolean isHasRepeatKey(String[] newItems, @NotNull Set<String> repeatKeys) {
Set<String> keys = new HashSet<>();
int lineCounter = 1;
int keyCount = 0;
for (String item : newItems) {
if (!isCommentItem(item) && !isBlankItem(item)) {
keyCount++;
String[] kv = parseKeyValueFromItem(item);
if (kv != null) {
keys.add(kv[0].toLowerCase());
String key = kv[0].toLowerCase();
if(!keys.add(key)){
repeatKeys.add(key);
}
} else {
throw new BadRequestException("line:" + lineCounter + " key value must separate by '='");
}
}
lineCounter++;
}

return keyCount > keys.size();
return !repeatKeys.isEmpty();
}

private String[] parseKeyValueFromItem(String item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public List<String> getRecipients() {
return recipients;
}

public String getRecipientsString() {
return String.join(",", recipients);
}

public void setRecipients(List<String> recipients) {
this.recipients = recipients;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,101 @@
package com.ctrip.framework.apollo.portal.spi.defaultimpl;

import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.entity.bo.Email;
import com.ctrip.framework.apollo.portal.spi.EmailService;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.sun.mail.smtp.SMTPTransport;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.annotation.Resource;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DefaultEmailService implements EmailService{
public class DefaultEmailService implements EmailService {

private final Logger logger = LoggerFactory.getLogger(DefaultEmailService.class);

@Resource
private PortalConfig portalConfig;

@Override
public void send(Email email){
//do nothing
public void send(Email email) {
if (!portalConfig.isEmailEnabled()) {
return;
}

SMTPTransport t = null;
try {
Properties prop = System.getProperties();
Session session = Session.getInstance(prop, null);

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(email.getSenderEmailAddress()));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email.getRecipientsString(), false));
msg.setSubject(email.getSubject());
msg.setDataHandler(new DataHandler(new HTMLDataSource(email.getBody())));

String host = portalConfig.emailConfigHost();
String user = portalConfig.emailConfigUser();
String password = portalConfig.emailConfigPassword();

t = (SMTPTransport) session.getTransport("smtp");
t.connect(host, user, password);
msg.saveChanges();
t.sendMessage(msg, msg.getAllRecipients());
logger.debug("email response: {}", t.getLastServerResponse());
} catch (Exception e) {
logger.error("send email failed.", e);
Tracer.logError("send email failed.", e);
} finally {
if (t != null) {
try {
t.close();
} catch (Exception e) {
// nothing
}
}
}
}

static class HTMLDataSource implements DataSource {

private String html;

HTMLDataSource(String htmlString) {
html = htmlString;
}

@Override
public InputStream getInputStream() throws IOException {
if (html == null) {
throw new IOException("html message is null!");
}
return new ByteArrayInputStream(html.getBytes());
}

@Override
public OutputStream getOutputStream() throws IOException {
throw new IOException("This DataHandler cannot write HTML");
}

@Override
public String getContentType() {
return "text/html";
}

@Override
public String getName() {
return "HTMLDataSource";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextAdapter;
Expand Down Expand Up @@ -177,15 +178,20 @@ private UserInfo lookupUser(String member, List<String> userIds) {
}

private UserInfo searchUserById(String userId) {
return ldapTemplate.searchForObject(query().where(loginIdAttrName).is(userId),
ctx -> {
UserInfo userInfo = new UserInfo();
DirContextAdapter contextAdapter = (DirContextAdapter) ctx;
userInfo.setEmail(contextAdapter.getStringAttribute(emailAttrName));
userInfo.setName(contextAdapter.getStringAttribute(userDisplayNameAttrName));
userInfo.setUserId(contextAdapter.getStringAttribute(loginIdAttrName));
return userInfo;
});
try {
return ldapTemplate.searchForObject(query().where(loginIdAttrName).is(userId),
ctx -> {
UserInfo userInfo = new UserInfo();
DirContextAdapter contextAdapter = (DirContextAdapter) ctx;
userInfo.setEmail(contextAdapter.getStringAttribute(emailAttrName));
userInfo.setName(contextAdapter.getStringAttribute(userDisplayNameAttrName));
userInfo.setUserId(contextAdapter.getStringAttribute(loginIdAttrName));
return userInfo;
});
} catch (EmptyResultDataAccessException ex) {
// EmptyResultDataAccessException means no record found
return null;
}
}

/**
Expand Down Expand Up @@ -279,9 +285,14 @@ public UserInfo findByUserId(String userId) {
}
return null;
}
return ldapTemplate
.searchForObject(ldapQueryCriteria().and(loginIdAttrName).is(userId), ldapUserInfoMapper);

try {
return ldapTemplate
.searchForObject(ldapQueryCriteria().and(loginIdAttrName).is(userId), ldapUserInfoMapper);
} catch (EmptyResultDataAccessException ex) {
// EmptyResultDataAccessException means no record found
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,6 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio
}
);
namespace.commited = true;
toggleTextEditStatus(namespace);
}

function syntaxCheck(namespace) {
Expand Down
Empty file added docs/.nojekyll
Empty file.
11 changes: 11 additions & 0 deletions docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<img src="https://raw.githubusercontent.com/ctripcorp/apollo/master/doc/images/logo/logo-simple.png" alt="apollo-logo" width="30%">

> A reliable configuration management system

- Multiple environments and clusters support
- Configuration changes take effect in real time
- Versioned and grayscale releases management
- Great authentication, authorization and audit control

[GitHub](https://github.com/ctripcorp/apollo/)
[快速开始](zh/deployment/quick-start.md)
3 changes: 3 additions & 0 deletions docs/_navbar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Translations
- [:uk: English](/en/)
- [:cn: 中文](/zh/)
Binary file added docs/charts/apollo-portal-0.1.0.tgz
Binary file not shown.
Binary file added docs/charts/apollo-portal-0.1.1.tgz
Binary file not shown.
Binary file added docs/charts/apollo-service-0.1.0.tgz
Binary file not shown.
Binary file added docs/charts/apollo-service-0.1.1.tgz
Binary file not shown.
69 changes: 69 additions & 0 deletions docs/charts/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apiVersion: v1
entries:
apollo-portal:
- apiVersion: v2
appVersion: 1.7.1
created: "2020-08-16T22:21:06.70687+08:00"
description: A Helm chart for Apollo Portal
digest: 7c1b4efa13d4cc54a714b3ec836f609a8f97286c465789f6d807d1227cfc5b74
home: https://github.com/ctripcorp/apollo
icon: https://raw.githubusercontent.com/ctripcorp/apollo/master/apollo-portal/src/main/resources/static/img/logo-simple.png
maintainers:
- email: [email protected]
name: nobodyiam
url: https://github.com/nobodyiam
name: apollo-portal
type: application
urls:
- apollo-portal-0.1.1.tgz
version: 0.1.1
- apiVersion: v2
appVersion: 1.7.0
created: "2020-08-16T22:21:06.705726+08:00"
description: A Helm chart for Apollo Portal
digest: b838e4478f0c031093691defeffb5805d51189989db0eb9caaa2dc67905c8391
home: https://github.com/ctripcorp/apollo
icon: https://raw.githubusercontent.com/ctripcorp/apollo/master/apollo-portal/src/main/resources/static/img/logo-simple.png
maintainers:
- email: [email protected]
name: nobodyiam
url: https://github.com/nobodyiam
name: apollo-portal
type: application
urls:
- apollo-portal-0.1.0.tgz
version: 0.1.0
apollo-service:
- apiVersion: v2
appVersion: 1.7.1
created: "2020-08-16T22:21:06.708833+08:00"
description: A Helm chart for Apollo Config Service and Apollo Admin Service
digest: 787a26590d68735341b7839c14274492097fed4a0843fc9a1e5c692194199707
home: https://github.com/ctripcorp/apollo
icon: https://raw.githubusercontent.com/ctripcorp/apollo/master/apollo-portal/src/main/resources/static/img/logo-simple.png
maintainers:
- email: [email protected]
name: nobodyiam
url: https://github.com/nobodyiam
name: apollo-service
type: application
urls:
- apollo-service-0.1.1.tgz
version: 0.1.1
- apiVersion: v2
appVersion: 1.7.0
created: "2020-08-16T22:21:06.708165+08:00"
description: A Helm chart for Apollo Config Service and Apollo Admin Service
digest: 65c08f39b54ad1ac1d849cc841ce978bd6e95b0b6cbd2423d9f17f66bc7e8d3e
home: https://github.com/ctripcorp/apollo
icon: https://raw.githubusercontent.com/ctripcorp/apollo/master/apollo-portal/src/main/resources/static/img/logo-simple.png
maintainers:
- email: [email protected]
name: nobodyiam
url: https://github.com/nobodyiam
name: apollo-service
type: application
urls:
- apollo-service-0.1.0.tgz
version: 0.1.0
generated: "2020-08-16T22:21:06.703126+08:00"
1 change: 1 addition & 0 deletions docs/en/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
English version documentation of Apollo
5 changes: 5 additions & 0 deletions docs/en/_sidebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Getting started

- [Quick start](en/quick-start.md)

- [Releases](https://github.com/ctripcorp/apollo/releases)
8 changes: 8 additions & 0 deletions docs/en/quick-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Prepare

Wait for content...

```bash
content for copy
```
Loading