improved ckpt list

pull/552/head
Jingyi 2024-03-17 23:12:43 +08:00
parent c6384f778d
commit 2fe3b8004e
4 changed files with 80 additions and 4 deletions

View File

@ -91,6 +91,7 @@ export class Middleware extends Stack {
// if the resource manager is executed, it will recheck and create resources for stack // if the resource manager is executed, it will recheck and create resources for stack
bucketName: s3BucketName.valueAsString, bucketName: s3BucketName.valueAsString,
ecrImageTag: ecrImageTagParam.valueAsString, ecrImageTag: ecrImageTagParam.valueAsString,
version: 'v1.0.13',
}, },
); );

View File

@ -1,7 +1,12 @@
import { execFile } from 'child_process'; import { execFile } from 'child_process';
import { promises as fsPromises } from 'fs'; import { promises as fsPromises } from 'fs';
import { promisify } from 'util'; import { promisify } from 'util';
import { CreateTableCommand, CreateTableCommandInput, DynamoDBClient, UpdateTableCommand } from '@aws-sdk/client-dynamodb'; import {
CreateTableCommand,
CreateTableCommandInput,
DynamoDBClient, PutItemCommand, PutItemCommandInput,
UpdateTableCommand,
} from '@aws-sdk/client-dynamodb';
import { UpdateTableCommandInput } from '@aws-sdk/client-dynamodb/dist-types/commands/UpdateTableCommand'; import { UpdateTableCommandInput } from '@aws-sdk/client-dynamodb/dist-types/commands/UpdateTableCommand';
import { AttributeDefinition, KeySchemaElement } from '@aws-sdk/client-dynamodb/dist-types/models/models_0'; import { AttributeDefinition, KeySchemaElement } from '@aws-sdk/client-dynamodb/dist-types/models/models_0';
import { import {
@ -71,6 +76,7 @@ export async function handler(event: Event, context: Object) {
async function createAndCheckResources() { async function createAndCheckResources() {
await createBucket(); await createBucket();
await createTables(); await createTables();
await putItemUsersTable();
await createGlobalSecondaryIndex('SDInferenceJobTable'); await createGlobalSecondaryIndex('SDInferenceJobTable');
await createKms( await createKms(
'sd-extension-password-key', 'sd-extension-password-key',
@ -304,6 +310,70 @@ async function createTables() {
} }
async function putItemUsersTable() {
await putItem('MultiUserTable', {
kind: { S: 'role' },
sort_key: { S: 'IT Operator' },
creator: { S: 'ESD' },
permissions: {
L: [
{ S: 'train:all' },
{ S: 'checkpoint:all' },
{ S: 'inference:all' },
{ S: 'sagemaker_endpoint:all' },
{ S: 'user:all' },
{ S: 'role:all' },
],
},
});
await putItem('MultiUserTable', {
kind: { S: 'role' },
sort_key: { S: 'byoc' },
creator: { S: 'ESD' },
permissions: {
L: [
{ S: 'train:all' },
{ S: 'checkpoint:all' },
{ S: 'inference:all' },
{ S: 'sagemaker_endpoint:all' },
{ S: 'user:all' },
{ S: 'role:all' },
],
},
});
await putItem('MultiUserTable', {
kind: { S: 'user' },
sort_key: { S: 'api' },
creator: { S: 'ESD' },
roles: {
L: [
{
S: 'IT Operator',
},
],
},
});
}
async function putItem(tableName: string, item: any) {
try {
const putItemCommandInput: PutItemCommandInput = {
TableName: tableName,
Item: item,
};
const putItemCommand = new PutItemCommand(putItemCommandInput);
await ddbClient.send(putItemCommand);
console.log(`putItem into ${tableName}`);
console.log(item);
} catch (err: any) {
console.log(err);
}
}
async function createGlobalSecondaryIndex(tableName: string) { async function createGlobalSecondaryIndex(tableName: string) {
const params: UpdateTableCommandInput = { const params: UpdateTableCommandInput = {
TableName: tableName, TableName: tableName,
@ -344,7 +414,7 @@ async function createGlobalSecondaryIndex(tableName: string) {
const response = await ddbClient.send(command); const response = await ddbClient.send(command);
console.log('Success', response); console.log('Success', response);
} catch (error) { } catch (error) {
console.error('Error', error); console.log('Error', error);
} }
} }

View File

@ -12,6 +12,7 @@ import { ESD_FILE_VERSION } from './const';
export interface ResourceProviderProps { export interface ResourceProviderProps {
bucketName?: string; bucketName?: string;
ecrImageTag?: string; ecrImageTag?: string;
version?: string;
} }
export class ResourceProvider extends Construct { export class ResourceProvider extends Construct {
@ -91,6 +92,7 @@ export class ResourceProvider extends Construct {
actions: [ actions: [
'dynamodb:CreateTable', 'dynamodb:CreateTable',
'dynamodb:UpdateTable', 'dynamodb:UpdateTable',
'dynamodb:PutItem',
'sns:CreateTopic', 'sns:CreateTopic',
'iam:ListRolePolicies', 'iam:ListRolePolicies',
'iam:PutRolePolicy', 'iam:PutRolePolicy',

View File

@ -62,13 +62,16 @@ def handler(event, ctx):
result = [] result = []
for row in scan_rows: for row in scan_rows:
user = User(**(ddb_service.deserialize(row))) user = User(**(ddb_service.deserialize(row)))
password = "*"
if user.password:
password = '*' * 8 if not show_password else password_encryptor.decrypt(
key_id=kms_key_id, cipher_text=user.password).decode()
user_resp = { user_resp = {
'username': user.sort_key, 'username': user.sort_key,
'roles': user.roles, 'roles': user.roles,
'creator': user.creator, 'creator': user.creator,
'permissions': set(), 'permissions': set(),
'password': '*' * 8 if not show_password else password_encryptor.decrypt( 'password': password,
key_id=kms_key_id, cipher_text=user.password).decode(),
} }
for role in user.roles: for role in user.roles:
if role in roles_permission_lookup: if role in roles_permission_lookup: