@@ -9,17 +9,25 @@ import {
99 GitHubRepository ,
1010 GitHubRepositoryRef
1111} from "../domain"
12+ import { RemoteConfig } from "@/app/api/remotes/[encryptedRemoteConfig]/route"
13+ import RsaEncryptionService from "@/common/encryption/EncryptionService"
14+ import { env } from "@/common"
1215
1316export default class GitHubProjectDataSource implements IProjectDataSource {
1417 private readonly repositoryDataSource : IGitHubRepositoryDataSource
1518 private readonly repositoryNameSuffix : string
19+ private readonly encryptionService : RsaEncryptionService
1620
1721 constructor ( config : {
1822 repositoryDataSource : IGitHubRepositoryDataSource
1923 repositoryNameSuffix : string
2024 } ) {
2125 this . repositoryDataSource = config . repositoryDataSource
2226 this . repositoryNameSuffix = config . repositoryNameSuffix
27+ this . encryptionService = new RsaEncryptionService ( {
28+ publicKey : Buffer . from ( env . getOrThrow ( "ENCRYPTION_PUBLIC_KEY_BASE_64" ) , "base64" ) . toString ( "utf-8" ) ,
29+ privateKey : Buffer . from ( env . getOrThrow ( "ENCRYPTION_PRIVATE_KEY_BASE_64" ) , "base64" ) . toString ( "utf-8" )
30+ } )
2331 }
2432
2533 async getProjects ( ) : Promise < Project [ ] > {
@@ -167,11 +175,34 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
167175 const existingVersionIdCount = versionIds . filter ( e => e == baseVersionId ) . length
168176 const versionId = baseVersionId + ( existingVersionIdCount > 0 ? existingVersionIdCount : "" )
169177 const specifications = remoteVersion . specifications . map ( e => {
170- return {
171- id : this . makeURLSafeID ( ( e . id || e . name ) . toLowerCase ( ) ) ,
172- name : e . name ,
173- url : "/api/remotes/EKNYViMOSUnJggD4c4UwEoOGkGKZIPjWtijfeoYqgrkRP%2FIwXa770oxwRsVTdVFzmbjWuartdrUhUjkq7EyT4m3NBQOph0UaRTQhFgxm4Q5v2KJ%2BkhJ6TTKwiEgEdS%2BdOvTzAzXtk80T4amaNdeET9JVGJo0y8G47qtUIZCWmyzxamTnOJYOhkj4NcH9XlyafghwUV%2FO%2FAShlzwscFPy%2BlDFuhl8jmYV4fvClI2%2F4iFyew%2Bg5LGvNXPTS8wEZcz9GBKrcgSE6ScK3oeAGesKPyYblkKiU7dAxi%2FlRs9jiKQId%2BEFLWFcDgNw8aLDyZjKMT2u4gF9dfLx4iRQhaJ7KQ%3D%3D"
174- }
178+ if ( e . auth ) {
179+ // decrypt username and password
180+ const username = this . encryptionService . decrypt ( e . auth . encryptedUsername )
181+ const password = this . encryptionService . decrypt ( e . auth . encryptedPassword )
182+ // construct remote config
183+ const remoteConfig : RemoteConfig = {
184+ url : e . url ,
185+ auth : {
186+ type : e . auth . type ,
187+ username,
188+ password
189+ }
190+ }
191+ // encrypt and encode remote config
192+ const encryptedRemoteConfig = encodeURIComponent ( this . encryptionService . encrypt ( JSON . stringify ( remoteConfig ) ) )
193+
194+ return {
195+ id : this . makeURLSafeID ( ( e . id || e . name ) . toLowerCase ( ) ) ,
196+ name : e . name ,
197+ url : `/api/remotes/${ encryptedRemoteConfig } `
198+ }
199+ } else {
200+ return {
201+ id : this . makeURLSafeID ( ( e . id || e . name ) . toLowerCase ( ) ) ,
202+ name : e . name ,
203+ url : `/api/proxy?url=${ encodeURIComponent ( e . url ) } `
204+ }
205+ }
175206 } )
176207 versions . push ( {
177208 id : versionId ,
0 commit comments