Skip to content

Commit af1af19

Browse files
committed
chore: wip
1 parent 30ea591 commit af1af19

File tree

8 files changed

+56
-21
lines changed

8 files changed

+56
-21
lines changed

storage/framework/.stacks/core/buddy/src/commands/cloud.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from 'node:process'
22
import { intro, italic, log, outro, prompts, runCommand, runCommandSync, underline } from '@stacksjs/cli'
3-
import { addJumpBox, deleteCdkRemnants, deleteJumpBox, deleteLogGroups, deleteParameterStore, deleteStacksBuckets, deleteStacksFunctions, getJumpBoxInstanceId } from '@stacksjs/cloud'
3+
import { addJumpBox, deleteCdkRemnants, deleteIamUsers, deleteJumpBox, deleteLogGroups, deleteParameterStore, deleteStacksBuckets, deleteStacksFunctions, getJumpBoxInstanceId } from '@stacksjs/cloud'
44
import { path as p } from '@stacksjs/path'
55
import type { CLI, CloudCliOptions } from '@stacksjs/types'
66
import { ExitCode } from '@stacksjs/types'
@@ -122,9 +122,12 @@ export function cloud(buddy: CLI) {
122122
process.exit(ExitCode.Success)
123123
}
124124

125-
log.info(` ${italic('ℹ️ Removing your cloud resources takes a while to complete.')}`)
126-
log.info(` ${italic('Please note, your backups will not yet be deleted. Though,')}`)
127-
log.info(` ${italic('Backups are scheduled to delete themselves in 30 days.')}`)
125+
// eslint-disable-next-line no-console
126+
console.log(` ${italic('ℹ️ Removing your cloud resources takes a while to complete.')}`)
127+
// eslint-disable-next-line no-console
128+
console.log(` ${italic('Please note, your backups will not yet be deleted. Though,')}`)
129+
// eslint-disable-next-line no-console
130+
console.log(` ${italic('Backups are scheduled to delete themselves in 30 days.')}`)
128131

129132
// sleep for 2 seconds to get the user to read the message
130133
await new Promise(resolve => setTimeout(resolve, 2000))
@@ -206,7 +209,7 @@ export function cloud(buddy: CLI) {
206209
.action(async () => {
207210
const startTime = await intro('buddy cloud:cleanup')
208211

209-
log.info(`ℹ️ ${italic('Cleaning up your cloud resources will take a while to complete. Please be patient.')}`)
212+
log.info(`Cleaning up your cloud resources will take a while to complete. Please be patient.`)
210213

211214
// sleep for 2 seconds to get the user to read the message
212215
await new Promise(resolve => setTimeout(resolve, 2000))
@@ -274,6 +277,14 @@ export function cloud(buddy: CLI) {
274277
process.exit(ExitCode.FatalError)
275278
}
276279

280+
log.info('Removing any IAM users...')
281+
const result8 = await deleteIamUsers()
282+
283+
if (result8.isErr()) {
284+
await outro('While deleting the Stacks log groups, there was an issue', { startTime, useSeconds: true }, result8.error)
285+
process.exit(ExitCode.FatalError)
286+
}
287+
277288
// TODO: needs to delete all Backup Vaults
278289
// TODO: needs to delete all KMS keys
279290

storage/framework/.stacks/core/cloud/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const region = 'us-east-1' // currently, us-east-1 is the only fully-supported r
2323
let timestamp
2424

2525
if (!appKey) {
26-
log.info('Please set an application key. `buddy key:generate` is your friend, in this case.')
26+
log.info('Please set an application key. You may need to run `buddy key:generate`.')
2727
process.exit(ExitCode.InvalidArgument)
2828
}
2929

storage/framework/.stacks/core/cloud/src/cloud/ai.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ export class AiStack {
2424
// Defining the Node.js Lambda function
2525
const aiLambda = new lambda.Function(scope, 'LambdaFunction', {
2626
runtime: lambda.Runtime.NODEJS_18_X,
27-
handler: 'ai-lambda.handler',
28-
code: lambda.Code.fromAsset('ai-lambda'),
27+
handler: 'index.handler',
28+
code: lambda.Code.fromAsset('lambda'),
2929
// layers: [awsSdkLayer],
3030
})
3131

32-
const api = new apigateway.LambdaRestApi(scope, 'ApiGateway', {
32+
const api = new apigateway.LambdaRestApi(scope, "ApiGateway", {
3333
handler: aiLambda,
3434
})
3535

storage/framework/.stacks/core/cloud/src/cloud/permissions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ export class PermissionsStack {
1515
const users = config.team.members
1616
const password = env.AWS_DEFAULT_PASSWORD || string.random()
1717

18-
for (const userName in users) {
18+
for (const name in users) {
1919
// const userEmail = users[userName]
20-
const name = `User${string.pascalCase(teamName)}${string.pascalCase(userName)}`
21-
const user = new iam.User(scope, name, {
20+
const id = `User${string.pascalCase(teamName)}${string.pascalCase(name)}`
21+
const userName = string.slug(`${teamName}-${name}`)
22+
const user = new iam.User(scope, id, {
2223
userName,
2324
password: SecretValue.unsafePlainText(password),
2425
passwordResetRequired: true,

storage/framework/.stacks/core/cloud/src/helpers.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { err, handleError, ok } from '@stacksjs/error-handling'
1414
import { log } from '@stacksjs/logging'
1515
import { path as p } from '@stacksjs/path'
1616
import { rimraf } from '@stacksjs/utils'
17+
import { slug } from '@stacksjs/strings'
1718

1819
const appEnv = config.app.env === 'local' ? 'dev' : config.app.env
1920
const cloudName = `stacks-cloud-${appEnv}`
@@ -188,6 +189,29 @@ export async function deleteJumpBox(stackName?: string) {
188189
return await deleteEc2Instance(jumpBoxId, stackName)
189190
}
190191

192+
export async function deleteIamUsers() {
193+
const iam = new IAM({ region: 'us-east-1' })
194+
const data = await iam.listUsers({})
195+
const teamName = slug(config.team.name)
196+
const users = data.Users?.filter(user => user.UserName?.includes(teamName)) || []
197+
198+
if (!users || users.length === 0)
199+
return ok(`No Stacks IAM users found for team ${teamName}`)
200+
201+
const promises = users.map((user) => {
202+
// eslint-disable-next-line no-console
203+
console.log(`Deleting IAM user: ${user.UserName}`)
204+
return iam.deleteUser({ UserName: user.UserName || '' })
205+
})
206+
207+
await Promise.all(promises).catch((error: Error) => {
208+
console.error(`Error deleting user: ${error}`)
209+
return err(handleError('Error deleting Stacks IAM users', error))
210+
})
211+
212+
return ok(`Stacks IAM users deleted for team ${teamName}`)
213+
}
214+
191215
export async function deleteStacksBuckets() {
192216
try {
193217
const s3 = new S3({ region: 'us-east-1' })

storage/framework/.stacks/core/utils/src/helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { CliOptions, Manifest, StacksError, SyncSubprocess } from '@stacksj
1010
import type { NpmScript } from '@stacksjs/enums'
1111
import { Action } from '@stacksjs/enums'
1212
import { parse } from 'yaml'
13-
import { semver } from './versions'
13+
// import { semver } from './versions'
1414
import app from '~/config/app'
1515
import ui from '~/config/ui'
1616

@@ -52,10 +52,10 @@ export async function installIfVersionMismatch() {
5252
const requiredBunVersion = '0.8.1'
5353
const installedBunVersion = process.version
5454

55-
if (!semver.satisfies(installedBunVersion, requiredBunVersion)) {
56-
log.warn(`Installed Bun version ${italic(installedBunVersion)} does not satisfy required version ${italic(requiredBunVersion)}. Adding it to your environment. One moment...`)
57-
await runCommand(`tea +bun.sh${requiredBunVersion} >/dev/null 2>&1`)
58-
}
55+
// if (!semver.satisfies(installedBunVersion, requiredBunVersion)) {
56+
// log.warn(`Installed Bun version ${italic(installedBunVersion)} does not satisfy required version ${italic(requiredBunVersion)}. Adding it to your environment. One moment...`)
57+
// await runCommand(`tea +bun.sh${requiredBunVersion} >/dev/null 2>&1`)
58+
// }
5959
}
6060

6161
export async function frameworkVersion(): Promise<string> {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { version } from '../package.json'
2-
import { semver } from 'bun'
2+
// import { semver } from 'bun'
33

4-
export { version, semver }
4+
export { version}
5+
// export { version, semver }

storage/framework/types/auto-imports.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,6 @@ declare module 'vue' {
14741474
readonly searchFilters: UnwrapRef<typeof import('../.stacks/core/search-engine/src/index')['searchFilters']>
14751475
readonly searchParams: UnwrapRef<typeof import('../.stacks/core/search-engine/src/index')['searchParams']>
14761476
readonly securityPath: UnwrapRef<typeof import('../.stacks/core/path/src/index')['securityPath']>
1477-
readonly semver: UnwrapRef<typeof import('../.stacks/core/utils/src/versions')['semver']>
14781477
readonly sep: UnwrapRef<typeof import('../.stacks/core/path/src/index')['sep']>
14791478
readonly serve: UnwrapRef<typeof import('../.stacks/core/router/src/server')['serve']>
14801479
readonly server: UnwrapRef<typeof import('../.stacks/core/server/src/index')['server']>
@@ -2358,7 +2357,6 @@ declare module '@vue/runtime-core' {
23582357
readonly searchFilters: UnwrapRef<typeof import('../.stacks/core/search-engine/src/index')['searchFilters']>
23592358
readonly searchParams: UnwrapRef<typeof import('../.stacks/core/search-engine/src/index')['searchParams']>
23602359
readonly securityPath: UnwrapRef<typeof import('../.stacks/core/path/src/index')['securityPath']>
2361-
readonly semver: UnwrapRef<typeof import('../.stacks/core/utils/src/versions')['semver']>
23622360
readonly sep: UnwrapRef<typeof import('../.stacks/core/path/src/index')['sep']>
23632361
readonly serve: UnwrapRef<typeof import('../.stacks/core/router/src/server')['serve']>
23642362
readonly server: UnwrapRef<typeof import('../.stacks/core/server/src/index')['server']>

0 commit comments

Comments
 (0)