Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.0.15'
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-audi committed Nov 15, 2022
2 parents bf418c8 + 893713c commit ef6d52f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ info:
license:
name: MIT
url: https://github.com/tiki/l0-storage/blob/main/LICENSE
version: 0.0.14
version: 0.0.15
servers:
- url: https://storage.l0.mytiki.com
paths:
Expand All @@ -23,7 +23,7 @@ paths:
properties:
key:
type: string
block:
content:
type: string
responses:
"201":
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.mytiki</groupId>
<artifactId>l0_storage</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
<packaging>jar</packaging>

<name>L0 Storage</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.mytiki.l0_storage.utilities.SHAFacade;
import com.mytiki.spring_rest_api.ApiExceptionBuilder;
import com.nimbusds.jose.*;
import com.nimbusds.jose.util.Base64URL;
import com.nimbusds.jwt.JWTClaimsSet;
import org.bouncycastle.asn1.pkcs.RSAPublicKey;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -96,9 +95,15 @@ private void guardForSignature(TokenAOReq req){

private String buildPrefix(String uid, String pubKey) {
try {
String hashedCustomerId = Base64URL.encode(SHAFacade.sha3_256(uid)).toString();
String hashedCustomerId = Base64
.getUrlEncoder()
.withoutPadding()
.encodeToString(SHAFacade.sha3_256(uid));
byte[] pubKeyBytes = Base64.getDecoder().decode(pubKey);
String hashedPubKey = Base64URL.encode(SHAFacade.sha3_256(pubKeyBytes)).toString();
String hashedPubKey = Base64
.getUrlEncoder()
.withoutPadding()
.encodeToString(SHAFacade.sha3_256(pubKeyBytes));
return hashedCustomerId + "/" + hashedPubKey + "/";
} catch (NoSuchAlgorithmException e) {
throw new ApiExceptionBuilder(HttpStatus.EXPECTATION_FAILED)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mytiki/l0_storage/main/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public OpenAPI oenAPI(@Value("${springdoc.version}") String appVersion) {
.schema(new JsonSchema()
.type("object")
.addProperty("key", new StringSchema())
.addProperty("block", new StringSchema())
.addProperty("content", new StringSchema())
))))
.responses(new ApiResponses()
.addApiResponse("201",
Expand Down
2 changes: 1 addition & 1 deletion worker/upload/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "l0-storage-upload",
"version": "0.0.14",
"version": "0.0.15",
"type": "module",
"devDependencies": {
"@babel/core": "^7.20.2",
Expand Down
14 changes: 7 additions & 7 deletions worker/upload/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export default {
const body = await handleBody(request, env)
await handleAuth(request, env, body)

const blockBytes = new TextEncoder().encode(atob(body.block))
const wasabiRsp = await put(env.WASABI_ID, env.WASABI_SECRET, body.key, blockBytes)
const contentBytes = new TextEncoder().encode(atob(body.content))
const wasabiRsp = await put(env.WASABI_ID, env.WASABI_SECRET, body.key, contentBytes)
if (wasabiRsp.status !== 200) {
return Response.json({
message: 'Bucket upload failed',
help: 'Contact support'
}, { status: 424 })
}

const l0Rsp = await report(env.REMOTE_ID, env.REMOTE_SECRET, body.key, blockBytes.length)
const l0Rsp = await report(env.REMOTE_ID, env.REMOTE_SECRET, body.key, contentBytes.length)
if (l0Rsp.status !== 204) {
console.log('WARNING. Failed to report usage')
console.log(l0Rsp)
Expand Down Expand Up @@ -51,16 +51,16 @@ async function handleBody (request, env) {
} catch (error) {
throw Response.json({ message: 'Malformed body' }, { status: 400 })
}
if (body.key == null || body.block == null) {
if (body.key == null || body.content == null) {
throw Response.json({
message: 'Missing required parameter',
detail: 'Both key & block are required'
detail: 'Both key & content are required'
}, { status: 400 })
}
if (body.block.length > env.MAX_BYTES) {
if (body.content.length > env.MAX_BYTES) {
throw Response.json({
message: 'Request too large',
detail: 'Max block size is 1MB'
detail: 'Max content size is 1MB'
}, { status: 413 })
}
return body
Expand Down

0 comments on commit ef6d52f

Please sign in to comment.