fix style, fix bucket url

This commit is contained in:
Sina Blattmann 2023-07-13 10:17:53 +02:00
parent be18b291af
commit 8a50af825e
3 changed files with 74 additions and 76 deletions

View File

@ -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<FetchResult<DataRecord>> => {

View File

@ -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,

View File

@ -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<Response>
{
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<Response> {
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}`;
}