Skip to content

Commit

Permalink
fjerner ubrukt kode
Browse files Browse the repository at this point in the history
  • Loading branch information
marensofier committed Aug 28, 2024
1 parent 1f43cd6 commit ba7d1aa
Showing 1 changed file with 0 additions and 51 deletions.
51 changes: 0 additions & 51 deletions src/main/kotlin/cryptoservice/controller/CryptoController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,18 @@ import cryptoservice.model.GCPAccessToken
import cryptoservice.service.DecryptionService
import cryptoservice.service.EncryptionService
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RestController
import java.net.URLDecoder
import java.nio.charset.StandardCharsets

@RestController
class CryptoController(
val encryptionService: EncryptionService,
val decryptionService: DecryptionService,
@Value("\${sops.ageKey}") val sopsAgePrivateKey: String,
) {
/* Dette er slik vi egentlig burde gjøre dekryptering, for at crypto-service kan være helt uavhengig av
* tjenesten som kaller den. Ettersom SOPS + age er avhengig av at det enten finnes en keys.txt-fil eller
* at `SOPS_AGE_KEY` er satt som miljøvariabel, så kan vi ikke gjøre det på denne måten enda. Det er mulig dette
* kan bli støttet i fremtiden ifølge dokumentasjonen til SOPS.
*/
@GetMapping("/decrypt-with-age-key")
fun decryptWithAgeKey(
@RequestHeader gcpAccessToken: String,
@RequestHeader agePrivateKey: String,
@RequestBody cipherText: String,
): ResponseEntity<String> {
// Bruk decryptionService.decrypt() og legg til agePrivateKey som inputparameter.

return ResponseEntity("Not implemented yet", HttpStatus.NOT_IMPLEMENTED)
}

@GetMapping("/decrypt")
fun decrypt(
@RequestHeader gcpAccessToken: String,
@RequestHeader agePrivateKey: String,
@RequestBody cipherText: String,
): ResponseEntity<String> {
val decryptedString = decryptionService.decrypt(cipherText, GCPAccessToken(gcpAccessToken), agePrivateKey)

return ResponseEntity.ok().body(decryptedString)
}

@PostMapping("/decrypt")
fun decryptPost(
@RequestHeader gcpAccessToken: String,
Expand All @@ -63,26 +32,6 @@ class CryptoController(
return ResponseEntity.ok().body(decryptedString)
}

@GetMapping("/encrypt")
fun encrypt(
text: String,
config: String,
gcpAccessToken: String,
riScId: String,
): ResponseEntity<String> {
// Hva skjer om decodingen feiler?
val urlDecodedText = URLDecoder.decode(text, StandardCharsets.UTF_8.toString())
val encryptedString =
encryptionService.encrypt(
text = urlDecodedText,
config = config,
gcpAccessToken = GCPAccessToken(gcpAccessToken),
riScId = riScId,
)

return ResponseEntity.ok().body(encryptedString)
}

@PostMapping("/encrypt")
fun encryptPost(
@RequestBody request: EncryptionRequest,
Expand Down

0 comments on commit ba7d1aa

Please sign in to comment.