-
Notifications
You must be signed in to change notification settings - Fork 85
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
3 changed files
with
68 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,41 @@ | ||
package io.gaia_app.credentials | ||
|
||
interface Credentials { | ||
fun toEnv(): List<String> | ||
import com.fasterxml.jackson.annotation.JsonSubTypes | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import org.springframework.data.annotation.Id | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME | ||
|
||
|
||
@JsonTypeInfo(use = NAME, include = PROPERTY, property = "provider") | ||
@JsonSubTypes( | ||
Type(value = AWSCredentials::class, name = "AWS"), | ||
Type(value = GCPCredentials::class, name = "GCP"), | ||
Type(value = AzureCredentials::class, name = "Azure") | ||
) | ||
abstract class Credentials { | ||
|
||
@Id | ||
lateinit var id: String | ||
|
||
abstract fun toEnv(): List<String> | ||
abstract fun provider(): String | ||
} | ||
|
||
data class AWSCredentials(val access_key:String, val secret_key:String):Credentials { | ||
override fun toEnv() = listOf("""AWS_ACCESS_KEY_ID=${access_key}""", """AWS_SECRET_ACCESS_KEY=${secret_key}""") | ||
data class AWSCredentials(val accessKey:String, val secretKey:String):Credentials() { | ||
override fun toEnv() = listOf("""AWS_ACCESS_KEY_ID=${accessKey}""", """AWS_SECRET_ACCESS_KEY=${secretKey}""") | ||
override fun provider() = "AWS" | ||
} | ||
|
||
data class GCPCredentials(val serviceAccountJSONContents:String):Credentials { | ||
data class GCPCredentials(val serviceAccountJSONContents:String):Credentials() { | ||
override fun toEnv() = listOf("""GOOGLE_CREDENTIALS=${serviceAccountJSONContents}""") | ||
override fun provider() = "GCP" | ||
} | ||
|
||
data class AzureCredentials(val clientId:String, val clientSecret:String):Credentials { | ||
data class AzureCredentials(val clientId:String, val clientSecret:String):Credentials() { | ||
override fun toEnv() = listOf("""ARM_CLIENT_ID=${clientId}""", """ARM_CLIENT_SECRET=${clientSecret}""") | ||
override fun provider() = "Azure" | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/io/gaia_app/credentials/CredentialsRepository.kt
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,5 @@ | ||
package io.gaia_app.credentials | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository | ||
|
||
interface CredentialsRepository: MongoRepository<Credentials, String> |
33 changes: 33 additions & 0 deletions
33
src/main/java/io/gaia_app/credentials/CredentialsRestController.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,33 @@ | ||
package io.gaia_app.credentials; | ||
|
||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/credentials") | ||
@Secured({"ROLE_USER","ROLE_ADMIN"}) | ||
public class CredentialsRestController { | ||
|
||
private CredentialsRepository credentialsRepository; | ||
|
||
public CredentialsRestController(CredentialsRepository credentialsRepository) { | ||
this.credentialsRepository = credentialsRepository; | ||
} | ||
|
||
@GetMapping | ||
public List<Credentials> getAllCredentials(){ | ||
return this.credentialsRepository.findAll(); | ||
} | ||
|
||
@PostMapping | ||
public Credentials createCredentials(@RequestBody Credentials credentials){ | ||
return this.credentialsRepository.save(credentials); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public Credentials updateCredentials(@RequestBody Credentials credentials, @PathVariable String id){ | ||
return this.credentialsRepository.save(credentials); | ||
} | ||
} |