diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2019-10-08 17:51:53 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-11-06 10:04:19 +0100 |
commit | 58d04f69bb33f17cfe6db3d9885fe4c9adabd2d1 (patch) | |
tree | bc48a5c0b0e2884ffa6ec2b61c99326844f030ba /server/sonar-db-dao/src/main/java/org/sonar | |
parent | f8c9b9c8b3e7040907e0ded89511f86b827449ad (diff) | |
download | sonarqube-58d04f69bb33f17cfe6db3d9885fe4c9adabd2d1.tar.gz sonarqube-58d04f69bb33f17cfe6db3d9885fe4c9adabd2d1.zip |
SONAR-12512 Allow configuration of multiple GitHub instances
Diffstat (limited to 'server/sonar-db-dao/src/main/java/org/sonar')
8 files changed, 312 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java index f5cca91191f..add145bf020 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import org.sonar.core.platform.Module; import org.sonar.db.alm.AlmAppInstallDao; +import org.sonar.db.alm.setting.AlmSettingDao; import org.sonar.db.alm.OrganizationAlmBindingDao; import org.sonar.db.alm.ProjectAlmBindingDao; import org.sonar.db.ce.CeActivityDao; @@ -115,6 +116,7 @@ public class DaoModule extends Module { GroupMembershipDao.class, GroupPermissionDao.class, AlmAppInstallDao.class, + AlmSettingDao.class, ProjectAlmBindingDao.class, InternalComponentPropertiesDao.class, InternalPropertiesDao.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java index 33fbf8d2662..fea23b1b590 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java @@ -24,6 +24,7 @@ import java.util.Map; import org.sonar.db.alm.AlmAppInstallDao; import org.sonar.db.alm.OrganizationAlmBindingDao; import org.sonar.db.alm.ProjectAlmBindingDao; +import org.sonar.db.alm.setting.AlmSettingDao; import org.sonar.db.ce.CeActivityDao; import org.sonar.db.ce.CeQueueDao; import org.sonar.db.ce.CeScannerContextDao; @@ -99,6 +100,7 @@ public class DbClient { private final QualityProfileExportDao qualityProfileExportDao; private final PropertiesDao propertiesDao; private final AlmAppInstallDao almAppInstallDao; + private final AlmSettingDao almSettingDao; private final ProjectAlmBindingDao projectAlmBindingDao; private final InternalComponentPropertiesDao internalComponentPropertiesDao; private final InternalPropertiesDao internalPropertiesDao; @@ -165,6 +167,7 @@ public class DbClient { map.put(dao.getClass(), dao); } almAppInstallDao = getDao(map, AlmAppInstallDao.class); + almSettingDao = getDao(map, AlmSettingDao.class); projectAlmBindingDao = getDao(map, ProjectAlmBindingDao.class); schemaMigrationDao = getDao(map, SchemaMigrationDao.class); authorizationDao = getDao(map, AuthorizationDao.class); @@ -241,6 +244,10 @@ public class DbClient { return almAppInstallDao; } + public AlmSettingDao almSettingDao() { + return almSettingDao; + } + public ProjectAlmBindingDao projectAlmBindingsDao() { return projectAlmBindingDao; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index e9bf8807ba5..09cce2fab5a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -38,6 +38,7 @@ import org.sonar.db.alm.AlmAppInstallMapper; import org.sonar.db.alm.OrganizationAlmBindingMapper; import org.sonar.db.alm.ProjectAlmBindingDto; import org.sonar.db.alm.ProjectAlmBindingMapper; +import org.sonar.db.alm.setting.AlmSettingMapper; import org.sonar.db.ce.CeActivityMapper; import org.sonar.db.ce.CeQueueMapper; import org.sonar.db.ce.CeScannerContextMapper; @@ -224,6 +225,7 @@ public class MyBatis implements Startable { Class<?>[] mappers = { ActiveRuleMapper.class, AlmAppInstallMapper.class, + AlmSettingMapper.class, AnalysisPropertiesMapper.class, AuthorizationMapper.class, BranchMapper.class, diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ALM.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ALM.java new file mode 100644 index 00000000000..e99482e3ed8 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ALM.java @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.alm.setting; + +import java.util.Locale; + +public enum ALM { + GITHUB, + BITBUCKET, + AZURE_DEVOPS; + + public static ALM fromId(String almId) { + return ALM.valueOf(almId.toUpperCase(Locale.ENGLISH)); + } + + public String getId() { + return this.name().toLowerCase(Locale.ENGLISH); + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDao.java new file mode 100644 index 00000000000..d416dcb72f7 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDao.java @@ -0,0 +1,73 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.alm.setting; + +import java.util.List; +import java.util.Optional; +import org.sonar.api.utils.System2; +import org.sonar.core.util.UuidFactory; +import org.sonar.db.Dao; +import org.sonar.db.DbSession; + +public class AlmSettingDao implements Dao { + + private final System2 system2; + private final UuidFactory uuidFactory; + + public AlmSettingDao(System2 system2, UuidFactory uuidFactory) { + this.system2 = system2; + this.uuidFactory = uuidFactory; + } + + private static AlmSettingMapper getMapper(DbSession dbSession) { + return dbSession.getMapper(AlmSettingMapper.class); + } + + public void insert(DbSession dbSession, AlmSettingDto almSettingDto) { + String uuid = uuidFactory.create(); + long now = system2.now(); + getMapper(dbSession).insert(almSettingDto, uuid, now); + almSettingDto.setUuid(uuid); + almSettingDto.setCreatedAt(now); + almSettingDto.setUpdatedAt(now); + } + + public Optional<AlmSettingDto> selectByUuid(DbSession dbSession, String uuid) { + return Optional.ofNullable(getMapper(dbSession).selectByUuid(uuid)); + } + + public Optional<AlmSettingDto> selectByKey(DbSession dbSession, String key) { + return Optional.ofNullable(getMapper(dbSession).selectByKey(key)); + } + + public List<AlmSettingDto> selectAll(DbSession dbSession) { + return getMapper(dbSession).selectAll(); + } + + public void delete(DbSession dbSession, AlmSettingDto almSettingDto){ + getMapper(dbSession).deleteByKey(almSettingDto.getKey()); + } + + public void update(DbSession dbSession, AlmSettingDto almSettingDto) { + long now = system2.now(); + getMapper(dbSession).update(almSettingDto, now); + almSettingDto.setUpdatedAt(now); + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java new file mode 100644 index 00000000000..82f5db0b6d2 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDto.java @@ -0,0 +1,127 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.alm.setting; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class AlmSettingDto { + + private String uuid; + private String key; + private String rawAlm; + private String url; + private String appId; + private String privateKey; + private String personalAccessToken; + private long updatedAt; + private long createdAt; + + String getUuid() { + return uuid; + } + + void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getKey() { + return key; + } + + public AlmSettingDto setKey(String key) { + this.key = key; + return this; + } + + public ALM getAlm() { + return ALM.fromId(rawAlm); + } + + public AlmSettingDto setAlm(ALM alm) { + rawAlm = alm.getId(); + return this; + } + + public String getRawAlm() { + return rawAlm; + } + + public AlmSettingDto setRawAlm(String rawAlm) { + this.rawAlm = rawAlm; + return this; + } + + @CheckForNull + public String getUrl() { + return url; + } + + public AlmSettingDto setUrl(@Nullable String url) { + this.url = url; + return this; + } + + @CheckForNull + public String getAppId() { + return appId; + } + + public AlmSettingDto setAppId(@Nullable String appId) { + this.appId = appId; + return this; + } + + @CheckForNull + public String getPrivateKey() { + return privateKey; + } + + public AlmSettingDto setPrivateKey(@Nullable String privateKey) { + this.privateKey = privateKey; + return this; + } + + @CheckForNull + public String getPersonalAccessToken() { + return personalAccessToken; + } + + public AlmSettingDto setPersonalAccessToken(@Nullable String personalAccessToken) { + this.personalAccessToken = personalAccessToken; + return this; + } + + long getUpdatedAt() { + return updatedAt; + } + + void setUpdatedAt(long updatedAt) { + this.updatedAt = updatedAt; + } + + long getCreatedAt() { + return createdAt; + } + + void setCreatedAt(long createdAt) { + this.createdAt = createdAt; + } +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingMapper.java new file mode 100644 index 00000000000..584cd4a648c --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingMapper.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.alm.setting; + +import java.util.List; +import javax.annotation.CheckForNull; +import org.apache.ibatis.annotations.Param; + +public interface AlmSettingMapper { + + @CheckForNull + AlmSettingDto selectByUuid(@Param("uuid") String uuid); + + @CheckForNull + AlmSettingDto selectByKey(@Param("key") String key); + + List<AlmSettingDto> selectAll(); + + void insert(@Param("dto") AlmSettingDto almSettingDto, @Param("uuid") String uuid, @Param("now") long now); + + void update(@Param("dto") AlmSettingDto almSettingDto, @Param("now") long now); + + void deleteByKey(@Param("key") String key); +} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/package-info.java new file mode 100644 index 00000000000..1e3bea4ce3a --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.db.alm.setting; + +import javax.annotation.ParametersAreNonnullByDefault; + |