-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move ceremony command to R2 #3648
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
S3Client, | ||
UploadPartCommand, | ||
} from '@aws-sdk/client-s3' | ||
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager' | ||
import { getSignedUrl } from '@aws-sdk/s3-request-presigner' | ||
import { Credentials } from '@aws-sdk/types/dist-types/credentials' | ||
import { Assert, ErrorUtils, Logger } from '@ironfish/sdk' | ||
|
@@ -42,6 +43,14 @@ class UploadLastMultipartError extends UploadToBucketError {} | |
class UploadReadFileError extends UploadToBucketError {} | ||
class UploadFailedError extends UploadToBucketError {} | ||
|
||
const R2_SECRET_NAME = 'r2-prod-access-key' | ||
const R2_ENDPOINT = `https://a93bebf26da4c2fe205f71c896afcf89.r2.cloudflarestorage.com` | ||
|
||
export type R2Secret = { | ||
r2AccessKeyId: string | ||
r2SecretAccessKey: string | ||
} | ||
|
||
export async function uploadToBucket( | ||
s3: S3Client, | ||
filePath: string, | ||
|
@@ -309,6 +318,31 @@ export function getS3Client( | |
}) | ||
} | ||
|
||
export function getR2S3Client(credentials: { | ||
r2AccessKeyId: string | ||
r2SecretAccessKey: string | ||
}): S3Client { | ||
return new S3Client({ | ||
region: 'auto', | ||
endpoint: R2_ENDPOINT, | ||
credentials: { | ||
accessKeyId: credentials.r2AccessKeyId, | ||
secretAccessKey: credentials.r2SecretAccessKey, | ||
}, | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are binary compatible with S3, so I wouldnt expect this to exist. There is no difference in the client. I would just expect these to be parameters that you pass into getS3Client but we can refactor this later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which things would be parameters? |
||
|
||
export async function getR2Credentials(): Promise<R2Secret | undefined> { | ||
const client = new SecretsManagerClient({ region: 'us-east-1' }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about this region config. If the ceremony server has terraform config, it prob wont need it. |
||
const command = new GetSecretValueCommand({ SecretId: R2_SECRET_NAME }) | ||
const response = await client.send(command) | ||
if (response.SecretString === undefined) { | ||
return | ||
} else { | ||
return JSON.parse(response.SecretString) as R2Secret | ||
} | ||
} | ||
|
||
export async function getCognitoIdentityCredentials(): Promise<Credentials> { | ||
const identityPoolId = 'us-east-1:3ebc542a-6ac4-4c5d-9558-1621eadd2382' | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the bucket, right? I assume it's like an account name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its the dev testing url. We will replace it with ironfish.network domain name when close to launch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that is basically a link to the bucket