From 8a50af825eb7adb765371773302ea8cf97fcec15 Mon Sep 17 00:00:00 2001 From: Sina Blattmann Date: Thu, 13 Jul 2023 10:17:53 +0200 Subject: [PATCH] fix style, fix bucket url --- .../Context/S3CredentialsContextProvider.tsx | 20 ++- .../src/components/Layout/InnovenergyTab.tsx | 1 - .../Frontend/src/dataCache/S3/S3Access.ts | 129 +++++++++--------- 3 files changed, 74 insertions(+), 76 deletions(-) diff --git a/typescript/Frontend/src/components/Context/S3CredentialsContextProvider.tsx b/typescript/Frontend/src/components/Context/S3CredentialsContextProvider.tsx index e41be783d..476dd263e 100644 --- a/typescript/Frontend/src/components/Context/S3CredentialsContextProvider.tsx +++ b/typescript/Frontend/src/components/Context/S3CredentialsContextProvider.tsx @@ -29,17 +29,15 @@ const S3CredentialsContextProvider = ({ console.log("creds", s3Credentials); const saveS3Credentials = (credentials: S3Credentials, id: string) => { - //const s3Bucket = id + "-3e5b3069-214a-43ee-8d85-57d72000c19d"; - /* const s3Bucket = "saliomameiringen"; - - setS3Credentials({ s3Bucket, ...credentials });*/ - setS3Credentials({ - s3Region: "sos-ch-dk-2", - s3Provider: "exo.io", - s3Key: "EXO15c0bf710e158e9b83270f0a", - s3Secret: "Dd5jYSiZtt_Zt5Ba5mDmaiLCdASUaKLfduSKY-SU-lg", - s3Bucket: "saliomameiringen", - }); + const s3Bucket = id + "-3e5b3069-214a-43ee-8d85-57d72000c19d"; + setS3Credentials({ s3Bucket, ...credentials }); + /* setS3Credentials({ + s3Region: "sos-ch-dk-2", + s3Provider: "exo.io", + s3Key: "EXO15c0bf710e158e9b83270f0a", + s3Secret: "Dd5jYSiZtt_Zt5Ba5mDmaiLCdASUaKLfduSKY-SU-lg", + s3Bucket: "saliomameiringen", + });*/ }; const fetchData = (timestamp: UnixTime): Promise> => { diff --git a/typescript/Frontend/src/components/Layout/InnovenergyTab.tsx b/typescript/Frontend/src/components/Layout/InnovenergyTab.tsx index 49336713e..2a5fea9e8 100644 --- a/typescript/Frontend/src/components/Layout/InnovenergyTab.tsx +++ b/typescript/Frontend/src/components/Layout/InnovenergyTab.tsx @@ -21,7 +21,6 @@ const InnovenergyTab = (props: any) => { borderTopRightRadius: "0.3rem", padding: ".5rem 1rem", textDecoration: "none", - transition: `color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out`, "&.Mui-selected": { backgroundColor: "#eaecf1", color: colors.black, diff --git a/typescript/Frontend/src/dataCache/S3/S3Access.ts b/typescript/Frontend/src/dataCache/S3/S3Access.ts index eeb90b795..294247187 100644 --- a/typescript/Frontend/src/dataCache/S3/S3Access.ts +++ b/typescript/Frontend/src/dataCache/S3/S3Access.ts @@ -1,77 +1,78 @@ -import {sha1Hmac} from "./Sha1"; -import {Utf8} from "./Utf8"; -import {toBase64} from "./UInt8Utils"; +import { sha1Hmac } from "./Sha1"; +import { Utf8 } from "./Utf8"; +import { toBase64 } from "./UInt8Utils"; -export class S3Access -{ - constructor - ( - readonly bucket: string, - readonly region: string, - readonly provider: string, - readonly key: string, - readonly secret: string - ) - {} +export class S3Access { + constructor( + readonly bucket: string, + readonly region: string, + readonly provider: string, + readonly key: string, + readonly secret: string + ) {} - get host() : string { return `${this.bucket}.${this.region}.${this.provider}` } - get url() : string { return `https://${this.host}` } + get host(): string { + return `${this.region}.${this.provider}`; + } - public get(s3Path : string): Promise - { - const method = "GET"; - const auth = this.createAuthorizationHeader(method, s3Path, ""); - const url = this.url + "/" + s3Path - const headers = {"Host": this.host, "Authorization": auth}; + get url(): string { + return `https://${this.host}`; + } - try - { - return fetch(url, {method: method, mode: "cors", headers: headers}) - } - catch - { - return Promise.reject() - } + public get(s3Path: string): Promise { + const method = "GET"; + const auth = this.createAuthorizationHeader(method, s3Path, ""); + const url = this.url + "/" + this.bucket + "/" + s3Path; + const headers = { Host: this.host, Authorization: auth }; + + try { + return fetch(url, { method: method, mode: "cors", headers: headers }); + } catch { + return Promise.reject(); } + } - private createAuthorizationHeader(method: string, - s3Path: string, - date: string) - { - return createAuthorizationHeader - ( - method, - this.bucket, - s3Path, - date, - this.key, - this.secret - ); - } + private createAuthorizationHeader( + method: string, + s3Path: string, + date: string + ) { + return createAuthorizationHeader( + method, + this.bucket, + s3Path, + date, + this.key, + this.secret + ); + } } -function createAuthorizationHeader(method: string, - bucket: string, - s3Path: string, - date: string, - s3Key: string, - s3Secret: string, - contentType: string = "", - md5Hash: string = "") -{ - // StringToSign = HTTP-Verb + "\n" + - // Content-MD5 + "\n" + - // Content-Type + "\n" + - // Date + "\n" + - // CanonicalizedAmzHeaders + - // CanonicalizedResource; +function createAuthorizationHeader( + method: string, + bucket: string, + s3Path: string, + date: string, + s3Key: string, + s3Secret: string, + contentType: string = "", + md5Hash: string = "" +) { + // StringToSign = HTTP-Verb + "\n" + + // Content-MD5 + "\n" + + // Content-Type + "\n" + + // Date + "\n" + + // CanonicalizedAmzHeaders + + // CanonicalizedResource; - const payload = Utf8.encode(`${method}\n${md5Hash}\n${contentType}\n${date}\n/${bucket}/${s3Path}`) + const payload = Utf8.encode( + `${method}\n${md5Hash}\n${contentType}\n${date}\n/${bucket}/${s3Path}` + ); - //console.log(`${method}\n${md5Hash}\n${contentType}\n${date}\n/${bucket}/${s3Path}`) + //console.log(`${method}\n${md5Hash}\n${contentType}\n${date}\n/${bucket}/${s3Path}`) - const secret = Utf8.encode(s3Secret) - const signature = toBase64(sha1Hmac(payload, secret)); + const secret = Utf8.encode(s3Secret); + const signature = toBase64(sha1Hmac(payload, secret)); - return `AWS ${s3Key}:${signature}` + return `AWS ${s3Key}:${signature}`; }