Skip to content

Commit

Permalink
Merge pull request #432 from FlowCI/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
gy2006 authored Sep 24, 2022
2 parents d573354 + 32d02ea commit 4a04e44
Show file tree
Hide file tree
Showing 66 changed files with 858 additions and 511 deletions.
18 changes: 9 additions & 9 deletions .run/Application - 1.run.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Application - 1" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<module name="core" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.flowci.core.Application" />
<option name="VM_PARAMETERS" value="-Xms1g -Xmx1g -Xmn600m -XX:-UseAdaptiveSizePolicy -XX:SurvivorRatio=4 -verbose:gc" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ACTIVE_PROFILES" />
<envs>
<env name="FLOWCI_AGENT_IMAGE" value="flowci/agent:dev" />
<env name="FLOWCI_AGENT_VOLUMES" value="name=pyenv,dest=/ci/python,script=init.sh,image=flowci/pyenv,init=init-pyenv-volume.sh" />
<env name="FLOWCI_AUTO_AGENT" value="false" />
<env name="FLOWCI_LOG_LEVEL" value="DEBUG" />
<env name="FLOWCI_PLUGIN_URL" value="https://raw.githubusercontent.com/FlowCI/plugins/develop/repository.json" />
<env name="FLOWCI_RABBITMQ_URI" value="amqp://guest:[email protected]:5672" />
<env name="FLOWCI_ZK_HOST" value="127.0.0.1" />
<env name="FLOWCI_AUTO_AGENT" value="false" />
<env name="FLOWCI_AGENT_VOLUMES" value="name=pyenv,dest=/ci/python,script=init.sh,image=flowci/pyenv,init=init-pyenv-volume.sh" />
<env name="FLOWCI_SERVER_PORT" value="8080" />
<env name="FLOWCI_SERVER_URL" value="http://localhost:8080" />
<env name="FLOWCI_TEMPLATES" value="https://raw.githubusercontent.com/FlowCI/templates/develop/templates.json" />
<env name="FLOWCI_AGENT_IMAGE" value="flowci/agent:dev" />
<env name="FLOWCI_SERVER_URL" value="http://192.168.31.173:8080" />
<env name="FLOWCI_ZK_HOST" value="127.0.0.1" />
</envs>
<module name="core" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.flowci.core.Application" />
<option name="VM_PARAMETERS" value="-Xms1g -Xmx1g -Xmn600m -XX:-UseAdaptiveSizePolicy -XX:SurvivorRatio=4 -verbose:gc" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.flowci.core.api.domain.CreateJobReport;
import com.flowci.core.api.service.OpenRestService;
import com.flowci.core.config.domain.Config;
import com.flowci.core.flow.domain.StatsCounter;
import com.flowci.core.flow.domain.MatrixCounter;
import com.flowci.core.job.domain.JobCache;
import com.flowci.core.job.service.CacheService;
import com.flowci.core.job.service.LoggingService;
Expand Down Expand Up @@ -92,7 +92,7 @@ public List<User> listFlowUserEmail(@PathVariable String name) {
@PostMapping("/flow/{name}/stats")
public void addStatsItem(@PathVariable String name,
@Validated @RequestBody AddStatsItem body) {
openRestService.saveStatsForFlow(name, body.getType(), StatsCounter.from(body.getData()));
openRestService.saveStatsForFlow(name, body.getType(), MatrixCounter.from(body.getData()));
}

@PostMapping("/flow/{name}/job/{number}/context")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.flowci.core.api.domain.CreateJobArtifact;
import com.flowci.core.api.domain.CreateJobReport;
import com.flowci.core.config.domain.Config;
import com.flowci.core.flow.domain.StatsCounter;
import com.flowci.core.flow.domain.MatrixCounter;
import com.flowci.core.secret.domain.Secret;
import com.flowci.core.user.domain.User;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -51,7 +51,7 @@ public interface OpenRestService {
/**
* Save statistic data for flow
*/
void saveStatsForFlow(String flowName, String statsType, StatsCounter counter);
void saveStatsForFlow(String flowName, String statsType, MatrixCounter counter);

/**
* Save uploaded job report with file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import com.flowci.core.config.service.ConfigService;
import com.flowci.core.flow.dao.FlowUserDao;
import com.flowci.core.flow.domain.Flow;
import com.flowci.core.flow.domain.StatsCounter;
import com.flowci.core.flow.domain.MatrixCounter;
import com.flowci.core.flow.service.FlowService;
import com.flowci.core.flow.service.StatsService;
import com.flowci.core.flow.service.MatrixService;
import com.flowci.core.job.dao.JobDao;
import com.flowci.core.job.domain.Job;
import com.flowci.core.job.domain.JobKey;
Expand Down Expand Up @@ -69,7 +69,7 @@ public class OpenRestServiceImpl implements OpenRestService {
private SecretService credentialService;

@Autowired
private StatsService statsService;
private MatrixService matrixService;

@Autowired
private ReportService reportService;
Expand Down Expand Up @@ -115,10 +115,10 @@ public Resource getResource(Secret secret, String file) {
}

@Override
public void saveStatsForFlow(String flowName, String statsType, StatsCounter counter) {
public void saveStatsForFlow(String flowName, String statsType, MatrixCounter counter) {
Flow flow = flowService.get(flowName);
int today = DateHelper.toIntDay(new Date());
statsService.add(flow.getId(), today, statsType, counter);
matrixService.add(flow.getId(), today, statsType, counter);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public PermissionMap actionMap() {

// developer
permissionMap.add(User.Role.Developer,
FlowAction.GET, FlowAction.LIST, FlowAction.LIST_BRANCH, FlowAction.GET, FlowAction.GET_YML);
FlowAction.GET, FlowAction.LIST, FlowAction.LIST_BRANCH, FlowAction.GET, FlowAction.GET_YML, FlowAction.LIST_USER);
permissionMap.add(User.Role.Developer, JobAction.ALL);
permissionMap.add(User.Role.Developer, SecretActions.LIST_NAME);
permissionMap.add(User.Role.Developer, AgentAction.GET, AgentAction.LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
*
*/

package com.flowci.core.auth;
package com.flowci.core.auth.controller;

import com.flowci.core.auth.domain.Tokens;
import com.flowci.core.auth.service.AuthService;
import com.flowci.core.user.domain.User;
import com.flowci.exception.AuthenticationException;
import com.google.common.base.Strings;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

@RestController()
@RequestMapping("/auth")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package com.flowci.core.auth;
package com.flowci.core.auth.controller;

import com.flowci.core.auth.annotation.Action;
import com.flowci.core.auth.service.AuthService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.flowci.core.user.domain.User;

import java.util.Optional;
import java.util.Set;

/**
* 'login' ->
Expand Down Expand Up @@ -65,4 +66,8 @@ public interface AuthService {
*/
Optional<User> get(String token);

/**
* Get action list by role
*/
Set<String> getActions(User.Role role);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.util.Objects;
import java.util.Optional;
import java.util.Set;

@Log4j2
@Service
Expand Down Expand Up @@ -159,6 +160,11 @@ public Optional<User> get(String token) {
return Optional.empty();
}

@Override
public Set<String> getActions(User.Role role) {
return permissionMap.get(role);
}

private User getUser(String email) {
try {
return userService.getByEmail(email);
Expand Down
20 changes: 14 additions & 6 deletions core/src/main/java/com/flowci/core/common/config/MongoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.flowci.core.common.mongo.VariableMapConverter;
import com.flowci.core.config.domain.SmtpConfig;
import com.flowci.core.config.domain.TextConfig;
import com.flowci.core.flow.domain.Flow;
import com.flowci.core.flow.domain.FlowGroup;
import com.flowci.core.git.domain.GitConfig;
import com.flowci.core.git.domain.GitConfigWithHost;
import com.flowci.core.job.domain.JobItem;
Expand Down Expand Up @@ -58,14 +60,17 @@
@EnableMongoAuditing(auditorAwareRef = "sessionManager")
public class MongoConfig extends AbstractMongoClientConfiguration {

@Autowired
private AppProperties appProperties;
private final AppProperties appProperties;

@Autowired
private MongoProperties mongoProperties;
private final MongoProperties mongoProperties;

@Autowired
private ObjectMapper objectMapper;
private final ObjectMapper objectMapper;

public MongoConfig(AppProperties appProperties, MongoProperties mongoProperties, ObjectMapper objectMapper) {
this.appProperties = appProperties;
this.mongoProperties = mongoProperties;
this.objectMapper = objectMapper;
}

@NonNull
@Override
Expand Down Expand Up @@ -97,6 +102,9 @@ public MongoMappingContext mongoMappingContext(MongoCustomConversions customConv
context.setAutoIndexCreation(true);

// add addPersistentEntity for subtypes since not registered if called within same thread
context.addEntity(Flow.class);
context.addEntity(FlowGroup.class);

context.addEntity(SmtpConfig.class);
context.addEntity(TextConfig.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void addInterceptors(InterceptorRegistry registry) {
.addPathPatterns("/users/**")
.excludePathPatterns("/users/default")
.addPathPatterns("/flows/**")
.addPathPatterns("/flow_groups/**")
.addPathPatterns("/jobs/**")
.addPathPatterns("/agents/**")
.addPathPatterns("/hosts/**")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.flowci.core.common.domain;

import com.flowci.core.flow.domain.Flow;
import com.flowci.util.StringHelper;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -26,6 +27,7 @@

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
* @author yang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@
package com.flowci.core.flow.controller;

import com.flowci.core.auth.annotation.Action;
import com.flowci.core.flow.domain.ConfirmOption;
import com.flowci.core.flow.domain.Flow;
import com.flowci.core.flow.domain.Flow.Status;
import com.flowci.core.flow.domain.FlowAction;
import com.flowci.core.flow.domain.Template;
import com.flowci.core.flow.domain.*;
import com.flowci.core.flow.service.FlowGroupService;
import com.flowci.core.flow.service.FlowItemService;
import com.flowci.core.flow.service.FlowService;
import com.flowci.core.user.domain.User;
import com.flowci.core.user.service.UserService;
import com.flowci.domain.SimpleAuthPair;
import com.flowci.domain.SimpleKeyPair;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -40,19 +37,32 @@
@RequestMapping("/flows")
public class FlowController {

@Autowired
private List<Template> templates;
private final List<Template> templates;

@Autowired
private UserService userService;
private final UserService userService;

@Autowired
private FlowService flowService;
private final FlowService flowService;

private final FlowGroupService flowGroupService;

private final FlowItemService flowItemService;

public FlowController(List<Template> templates,
UserService userService,
FlowService flowService,
FlowGroupService flowGroupService,
FlowItemService flowItemService) {
this.templates = templates;
this.userService = userService;
this.flowService = flowService;
this.flowGroupService = flowGroupService;
this.flowItemService = flowItemService;
}

@GetMapping
@Action(FlowAction.LIST)
public List<Flow> list() {
return flowService.list(Status.CONFIRMED);
public List<FlowItem> list() {
return flowItemService.list();
}

@GetMapping("/templates")
Expand All @@ -63,47 +73,32 @@ public List<Template> getTemplates() {

@GetMapping(value = "/{name}")
@Action(FlowAction.GET)
public Flow get(@PathVariable String name) {
return flowService.get(name);
public Flow get(@PathVariable String name, @RequestParam boolean group) {
var flow = flowService.get(name);
if (group && flow.hasParentId()) {
flow.setParent(flowGroupService.getById(flow.getParentId()));
}
return flow;
}

@GetMapping(value = "/{name}/exist")
@Action(FlowAction.CHECK_NAME)
public Boolean exist(@PathVariable String name) {
return flowService.exist(name);
return flowItemService.existed(name);
}

@PostMapping(value = "/{name}")
@Action(FlowAction.CREATE)
public Flow create(@PathVariable String name) {
return flowService.create(name);
}

@PostMapping(value = "/{name}/confirm")
@Action(FlowAction.CONFIRM)
public Flow confirm(@PathVariable String name, @RequestBody ConfirmOption option) {
return flowService.confirm(name, option);
public Flow create(@PathVariable String name, @RequestBody CreateOption option) {
return flowService.create(name, option);
}

@DeleteMapping("/{name}")
@Action(FlowAction.DELETE)
public Flow delete(@PathVariable String name) {
return flowService.delete(name);
}

/**
* Create credential for flow only
*/
@PostMapping("/{name}/secret/rsa")
@Action(FlowAction.SETUP_CREDENTIAL)
public String setupRSACredential(@PathVariable String name, @RequestBody SimpleKeyPair pair) {
return flowService.setSshRsaCredential(name, pair);
}

@PostMapping("/{name}/secret/auth")
@Action(FlowAction.SETUP_CREDENTIAL)
public String setupAuthCredential(@PathVariable String name, @RequestBody SimpleAuthPair pair) {
return flowService.setAuthCredential(name, pair);
var flow = flowService.get(name);
flowService.delete(flow);
return flow;
}

@PostMapping("/{name}/users")
Expand Down
Loading

0 comments on commit 4a04e44

Please sign in to comment.