-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
244 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ry/configuration/security/authentication/azure/AADOAuth2ResourceServerSecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.azbuilder.registry.configuration.security.authentication.azure; | ||
|
||
import com.azure.spring.aad.webapi.AADResourceServerWebSecurityConfigurerAdapter; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
|
||
@EnableWebSecurity | ||
@EnableGlobalMethodSecurity(prePostEnabled = true) | ||
@ConditionalOnProperty(prefix = "org.azbuilder.api.authentication", name = "type", havingValue = "AZURE") | ||
public class AADOAuth2ResourceServerSecurityConfig extends AADResourceServerWebSecurityConfigurerAdapter { | ||
/** | ||
* Add configuration logic as needed. | ||
*/ | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
super.configure(http); | ||
//http.authorizeRequests(requests -> requests.anyRequest().authenticated()); | ||
http.authorizeRequests() | ||
.antMatchers("/.well-known/**").permitAll() | ||
.and() | ||
.authorizeRequests() | ||
.anyRequest() | ||
.authenticated(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...builder/registry/configuration/security/authentication/local/LocalWebSecurityAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.azbuilder.registry.configuration.security.authentication.local; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.WebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@ConditionalOnProperty(prefix = "org.azbuilder.api.authentication", name = "type", havingValue = "LOCAL") | ||
public class LocalWebSecurityAdapter extends WebSecurityConfigurerAdapter { | ||
|
||
@Override | ||
public void configure(WebSecurity web) throws Exception { | ||
web.ignoring().antMatchers("/**"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
api-registry/src/main/java/org/azbuilder/registry/controller/ReadMeWebServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.azbuilder.registry.controller; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.azbuilder.registry.controller.model.ReadMe; | ||
import org.azbuilder.registry.service.module.ModuleService; | ||
import org.azbuilder.registry.service.readme.ReadMeServiceImpl; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@AllArgsConstructor | ||
@RestController | ||
@RequestMapping("/terraform/readme/v1") | ||
public class ReadMeWebServiceImpl { | ||
|
||
ModuleService moduleService; | ||
ReadMeServiceImpl readMeService; | ||
|
||
@GetMapping(value = "/{organization}/{module}/{provider}/{version}/download", produces = "application/json") | ||
public ResponseEntity<ReadMe> getModuleVersionPath(@PathVariable String organization, @PathVariable String module, @PathVariable String provider, @PathVariable String version) { | ||
ReadMe readMe = new ReadMe(); | ||
String moduleURL = moduleService.getModuleVersionPath(organization, module, provider, version); | ||
readMe.setUrl(moduleURL); | ||
readMe.setContent(readMeService.getContent(moduleURL)); | ||
return ResponseEntity.ok().body(readMe); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
api-registry/src/main/java/org/azbuilder/registry/controller/model/ReadMe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.azbuilder.registry.controller.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class ReadMe { | ||
private String content; | ||
private String url; | ||
} |
68 changes: 68 additions & 0 deletions
68
api-registry/src/main/java/org/azbuilder/registry/service/readme/ReadMeServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.azbuilder.registry.service.readme; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.FilenameUtils; | ||
import org.springframework.stereotype.Service; | ||
import org.zeroturnaround.zip.ZipUtil; | ||
|
||
import java.io.*; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Base64; | ||
import java.util.UUID; | ||
|
||
@AllArgsConstructor | ||
@Slf4j | ||
@Service | ||
public class ReadMeServiceImpl { | ||
|
||
private static final String README_DIRECTORY = "/.terraform-spring-boot/readme/"; | ||
|
||
public String getContent(String moduleURL) { | ||
String readmeText = new String(Base64.getEncoder().encode("NO README FILE".getBytes(StandardCharsets.UTF_8))); | ||
String userHomeDirectory = FileUtils.getUserDirectoryPath(); | ||
String gitModulePath = userHomeDirectory.concat( | ||
FilenameUtils.separatorsToSystem( | ||
README_DIRECTORY + "/" + UUID.randomUUID() | ||
)); | ||
File gitModuleFolder = new File(gitModulePath); | ||
|
||
try { | ||
FileUtils.forceMkdir(gitModuleFolder); | ||
FileUtils.cleanDirectory(gitModuleFolder); | ||
|
||
File gitModuleZip = new File(gitModuleFolder.getAbsolutePath() + "/module.zip"); | ||
FileUtils.copyURLToFile(new URL(moduleURL), gitModuleZip); | ||
|
||
ZipUtil.unpack(gitModuleZip, gitModuleFolder); | ||
|
||
File readmeFile = new File(gitModuleFolder.getAbsolutePath() + "/README.md"); | ||
readmeText = readFromInputStream(new FileInputStream(readmeFile)); | ||
|
||
readmeText = new String(Base64.getEncoder().encode(readmeText.getBytes(StandardCharsets.UTF_8))); | ||
|
||
FileUtils.cleanDirectory(gitModuleFolder); | ||
if (gitModuleFolder.delete()) | ||
log.info("Temp folder deleted..."); | ||
|
||
} catch (IOException e) { | ||
log.error(e.getMessage()); | ||
} | ||
|
||
return readmeText; | ||
} | ||
|
||
private String readFromInputStream(InputStream inputStream) throws IOException { | ||
StringBuilder resultStringBuilder = new StringBuilder(); | ||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
resultStringBuilder.append(line).append("\n"); | ||
} | ||
} | ||
return resultStringBuilder.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
server.port=8075 | ||
|
||
################################## | ||
#/.well-known/terraform.json Data# | ||
################################## | ||
org.azbuilder.registry.hostname=${AzBuilderRegistry} | ||
org.azbuilder.registry.clientId=${AzureAdAppClientId} | ||
org.azbuilder.registry.tenantid=${AzureAdAppTenantId} | ||
org.azbuilder.registry.scope=${AzureAdAppScope} | ||
|
||
##################### | ||
#Authentication Type# | ||
##################### | ||
org.azbuilder.api.authentication.type=${AuthenticationValidationTypeRegistry} | ||
|
||
####################################### | ||
#AZURE ACTIVE DIRECTORY AUTHENTICATION# | ||
####################################### | ||
azure.activedirectory.client-id=${AzureAdAppId} | ||
azure.activedirectory.app-id-uri=${AzureAdApiIdUri} | ||
|
||
################## | ||
#Terrakube Client# | ||
################## | ||
org.azbuilder.api.url=${AzBuilderApiUrl} | ||
org.azbuilder.api.clientId=${AzureAdAppClientId} | ||
org.azbuilder.api.clientSecret=${AzureAdAppClientSecret} | ||
org.azbuilder.api.tenantId=${AzureAdAppTenantId} | ||
org.azbuilder.api.scope=${AzureAdAppScope} | ||
|
||
################# | ||
#Storage Service# | ||
################# | ||
org.azbuilder.registry.plugin.storage.type=AzureStorageImpl | ||
org.azbuilder.registry.plugin.storage.azure.accountName=${AzureAccountName} | ||
org.azbuilder.registry.plugin.storage.azure.accountKey=${AzureAccountKey} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters