Skip to content

Commit

Permalink
Merge branch 'master' of github.com:klboke/apollo
Browse files Browse the repository at this point in the history
  • Loading branch information
klboke committed Sep 22, 2023
2 parents 1e228d3 + 7a43e83 commit 5c6954f
Show file tree
Hide file tree
Showing 37 changed files with 1,011 additions and 116 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "CodeQL"

on:
push:
branches: [ 'master' ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ 'master' ]
schedule:
- cron: '25 18 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'java' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Apollo 2.2.0
* [[Multi-Database Support][h2] Support run on h2](https://github.com/apolloconfig/apollo/pull/4851)
* [Fix the issue that env special case handling is missing in some case](https://github.com/apolloconfig/apollo/pull/4887)
* [Fix the issue that namespace content being cleared when identical content is pasted into the namespace](https://github.com/apolloconfig/apollo/pull/4922)
* [feat(openapi): allow user create app via openapi](https://github.com/apolloconfig/apollo/pull/4954)
* [Support grayscale feature for non-properties namespaces](https://github.com/apolloconfig/apollo/pull/4952)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/13?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public BadRequestException(String msgtpl, Object... args) {
setHttpStatus(HttpStatus.BAD_REQUEST);
}

public static BadRequestException ownerNameIsBlank() {
return new BadRequestException("ownerName can not be blank");
}

public static BadRequestException orgIdIsBlank() {
return new BadRequestException("orgId can not be blank");
}

public static BadRequestException itemAlreadyExists(String itemKey) {
return new BadRequestException("item already exists for itemKey:%s", itemKey);
}
Expand Down Expand Up @@ -92,6 +100,14 @@ public static BadRequestException appAlreadyExists(String appId) {
return new BadRequestException("app already exists for appId:%s", appId);
}

public static BadRequestException appIdIsBlank() {
return new BadRequestException("appId can not be blank");
}

public static BadRequestException appNameIsBlank() {
return new BadRequestException("app name can not be blank");
}

public static BadRequestException clusterNotExists(String clusterName) {
return new BadRequestException("cluster not exists for clusterName:%s", clusterName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@ public static NotFoundException appNotFound(String appId) {
return new NotFoundException("app not found for appId:%s", appId);
}

public static NotFoundException roleNotFound(String roleName) {
return new NotFoundException(
"role not found for roleName:%s, please check apollo portal DB table 'Role'",
roleName
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
package com.ctrip.framework.apollo.common.exception;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class NotFoundExceptionTest {

Expand All @@ -33,49 +34,54 @@ public void testConstructor() {
clusterName, namespaceName, key);
e2 = new NotFoundException(
String.format("item not found for %s %s %s %s", appId, clusterName, namespaceName, key));
Assert.assertEquals(e1.getMessage(), e2.getMessage());
assertEquals(e1.getMessage(), e2.getMessage());
}

@Test
public void testAppNotFoundException() {
NotFoundException exception = NotFoundException.appNotFound(appId);
Assert.assertEquals(exception.getMessage(), "app not found for appId:app-1001");
assertEquals(exception.getMessage(), "app not found for appId:app-1001");
}

@Test
public void testClusterNotFoundException() {
NotFoundException exception = NotFoundException.clusterNotFound(appId, clusterName);
Assert.assertEquals(exception.getMessage(), "cluster not found for appId:app-1001 clusterName:test");
assertEquals(exception.getMessage(), "cluster not found for appId:app-1001 clusterName:test");
}

@Test
public void testNamespaceNotFoundException() {
NotFoundException exception = NotFoundException.namespaceNotFound(appId, clusterName, namespaceName);
Assert.assertEquals(exception.getMessage(), "namespace not found for appId:app-1001 clusterName:test namespaceName:application");
assertEquals(exception.getMessage(), "namespace not found for appId:app-1001 clusterName:test namespaceName:application");

exception = NotFoundException.namespaceNotFound(66);
Assert.assertEquals(exception.getMessage(), "namespace not found for namespaceId:66");
assertEquals(exception.getMessage(), "namespace not found for namespaceId:66");
}

@Test
public void testReleaseNotFoundException() {
NotFoundException exception = NotFoundException.releaseNotFound(66);
Assert.assertEquals(exception.getMessage(), "release not found for releaseId:66");
assertEquals(exception.getMessage(), "release not found for releaseId:66");
}

@Test
public void testItemNotFoundException(){
NotFoundException exception = NotFoundException.itemNotFound(66);
Assert.assertEquals(exception.getMessage(), "item not found for itemId:66");
assertEquals(exception.getMessage(), "item not found for itemId:66");

exception = NotFoundException.itemNotFound("test.key");
Assert.assertEquals(exception.getMessage(), "item not found for itemKey:test.key");
assertEquals(exception.getMessage(), "item not found for itemKey:test.key");

exception = NotFoundException.itemNotFound(appId, clusterName, namespaceName, "test.key");
Assert.assertEquals(exception.getMessage(), "item not found for appId:app-1001 clusterName:test namespaceName:application itemKey:test.key");
assertEquals(exception.getMessage(), "item not found for appId:app-1001 clusterName:test namespaceName:application itemKey:test.key");

exception = NotFoundException.itemNotFound(appId, clusterName, namespaceName, 66);
Assert.assertEquals(exception.getMessage(), "item not found for appId:app-1001 clusterName:test namespaceName:application itemId:66");
assertEquals(exception.getMessage(), "item not found for appId:app-1001 clusterName:test namespaceName:application itemId:66");
}

@Test
void roleNotFound() {
NotFoundException exception = NotFoundException.roleNotFound("CreateApplication+SystemRole");
assertEquals(exception.getMessage(), "role not found for roleName:CreateApplication+SystemRole, please check apollo portal DB table 'Role'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.ctrip.framework.apollo.openapi.auth;

import static com.ctrip.framework.apollo.portal.service.SystemRoleManagerService.SYSTEM_PERMISSION_TARGET_ID;

import com.ctrip.framework.apollo.openapi.service.ConsumerRolePermissionService;
import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil;
import com.ctrip.framework.apollo.portal.constant.PermissionType;
Expand Down Expand Up @@ -70,4 +72,9 @@ public boolean hasCreateClusterPermission(HttpServletRequest request, String app
return permissionService.consumerHasPermission(consumerAuthUtil.retrieveConsumerId(request),
PermissionType.CREATE_CLUSTER, appId);
}

public boolean hasCreateApplicationPermission(HttpServletRequest request) {
long consumerId = consumerAuthUtil.retrieveConsumerId(request);
return permissionService.consumerHasPermission(consumerId, PermissionType.CREATE_APPLICATION, SYSTEM_PERMISSION_TARGET_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.openapi.api.AppOpenApiService;
import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenCreateAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO;
import com.ctrip.framework.apollo.openapi.util.OpenApiBeanUtils;
import com.ctrip.framework.apollo.portal.component.PortalSettings;
import com.ctrip.framework.apollo.portal.entity.model.AppModel;
import com.ctrip.framework.apollo.portal.environment.Env;
import com.ctrip.framework.apollo.portal.service.AppService;
import com.ctrip.framework.apollo.portal.service.ClusterService;
Expand All @@ -37,6 +39,7 @@
*/
@Service
public class ServerAppOpenApiService implements AppOpenApiService {

private final PortalSettings portalSettings;
private final ClusterService clusterService;
private final AppService appService;
Expand All @@ -50,6 +53,26 @@ public ServerAppOpenApiService(
this.appService = appService;
}

private App convert(OpenAppDTO dto) {
return App.builder()
.appId(dto.getAppId())
.name(dto.getName())
.ownerName(dto.getOwnerName())
.orgId(dto.getOrgId())
.orgName(dto.getOrgName())
.ownerEmail(dto.getOwnerEmail())
.build();
}

/**
* @see com.ctrip.framework.apollo.portal.controller.AppController#create(AppModel)
*/
@Override
public void createApp(OpenCreateAppDTO req) {
App app = convert(req.getApp());
appService.createAppAndAddRolePermission(app, req.getAdmins());
}

@Override
public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
List<OpenEnvClusterDTO> envClusters = new LinkedList<>();
Expand Down
Loading

0 comments on commit 5c6954f

Please sign in to comment.