Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Jan 11, 2024
1 parent 53d3e88 commit d1cfd38
Show file tree
Hide file tree
Showing 25 changed files with 612 additions and 169 deletions.
53 changes: 52 additions & 1 deletion cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/sst/ion/internal/util"
"github.com/sst/ion/pkg/global"
"github.com/sst/ion/pkg/project"
"github.com/sst/ion/pkg/project/provider"

cli "github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -81,6 +82,57 @@ func main() {
return nil
},
},
{
Name: "secrets",
Subcommands: []*cli.Command{
{
Name: "set",
ArgsUsage: "[key] [value]",
Action: func(cli *cli.Context) error {
p, err := initProject(cli)
if err != nil {
return err
}
if cli.Args().Len() != 2 {
return fmt.Errorf("key and value required")
}

key := cli.Args().Get(0)
value := cli.Args().Get(1)
backend := p.Backend()
secrets, err := provider.ListSecrets(backend, p.App().Name, p.App().Stage)
if err != nil {
return err
}
secrets[key] = value
err = provider.SetSecrets(backend, p.App().Name, p.App().Stage, secrets)
if err != nil {
return err
}
fmt.Println("Secret set")
return nil
},
},
{
Name: "list",
Action: func(cli *cli.Context) error {
p, err := initProject(cli)
if err != nil {
return err
}
backend := p.Backend()
secrets, err := provider.ListSecrets(backend, p.App().Name, p.App().Stage)
if err != nil {
return err
}
for key, value := range secrets {
fmt.Println(key, "=", value)
}
return nil
},
},
},
},
{
Name: "deploy",
Flags: []cli.Flag{},
Expand All @@ -102,7 +154,6 @@ func main() {
ui.Interrupt()
cancel()
}()

err = p.Stack.Run(ctx, &project.StackInput{
Command: "up",
OnEvent: ui.Trigger,
Expand Down
2 changes: 1 addition & 1 deletion cmd/sst/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (u *UI) Trigger(evt *project.StackEvent) {

if evt.DiagnosticEvent.Severity == "info" {
u.spinner.Disable()
fmt.Println(strings.TrimRight(evt.DiagnosticEvent.Message, " "))
fmt.Println(strings.TrimRight(evt.DiagnosticEvent.Message, " \n"))
u.spinner.Enable()
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions examples/test/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function handler() {
console.log(Resource.FOO);
return "Hello World";
}
48 changes: 31 additions & 17 deletions examples/test/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,38 @@ export default $config({
};
},
async run() {
const ws = new cloudflare.WorkerScript("WorkerScript", {
module: true,
name: "my_worker",
content: `
export default {
async fetch(request) {
return new Response("Hello, world!");
}
}
`,
accountId: $app.providers?.cloudflare?.accountId!,
const bucket = new sst.Bucket("MyBucket");
const secret = new sst.Secret("FOO");
const fn = new sst.Function("MyFunction", {
url: true,
link: [secret],
handler: "./src/index.handler",
});

/*
new cloudflare.WorkerRoute("WorkerRoute", {
scriptName: ws.name,
pattern: "*",
})
*/
return {
url: fn.url,
};

// const secret = new sst.Secret("MY_SECRET");

// const ws = new cloudflare.WorkerScript("WorkerScript", {
// link: [db],
// module: true,
// name: "my_worker",
// content: `
// export default {
// async fetch(request) {
// return new Response("Hello, world!");
// }
// }
// `,
// accountId: $app.providers?.cloudflare?.accountId!,
// });

// import { Resource } from "sst";

// new S3GetCommand({
// bucketName: Resource.MyBucket.bucketName,
// });
},
});
6 changes: 6 additions & 0 deletions examples/test/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare global {
export const Resource: {
FOO: string
}
}
export {}
2 changes: 1 addition & 1 deletion internal/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@pulumi/pulumi": "3.98.0",
"@pulumi/random": "4.15.0",
"@smithy/smithy-client": "2.1.18",
"@types/node": "20.10.5",
"@types/node": "^20.10.5",
"archiver": "6.0.1",
"esbuild": "0.19.10",
"glob": "10.3.10"
Expand Down
60 changes: 8 additions & 52 deletions internal/components/src/auto/run.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { PulumiFn } from "@pulumi/pulumi/automation";
import { runtime } from "@pulumi/pulumi";
import { initializeLinkRegistry } from "../components/link";

export async function run(program: PulumiFn) {
process.chdir($cli.paths.root);

runtime.registerStackTransformation(
(args: util.ResourceTransformationArgs) => {
if (
Expand All @@ -20,8 +22,9 @@ export async function run(program: PulumiFn) {
};
}
return undefined;
}
},
);

runtime.registerStackTransformation(
(args: util.ResourceTransformationArgs) => {
let normalizedName = args.name;
Expand All @@ -37,61 +40,14 @@ export async function run(program: PulumiFn) {

if (!normalizedName.match(/^[A-Z][a-zA-Z0-9]*$/)) {
throw new Error(
`Invalid component name "${normalizedName}". Component names must start with an uppercase letter and contain only alphanumeric characters.`
`Invalid component name "${normalizedName}". Component names must start with an uppercase letter and contain only alphanumeric characters.`,
);
}

return undefined;
}
},
);

const results = await program();
return results;

// const stack = await LocalWorkspace.createOrSelectStack(
// {
// program: async () => {
// runtime.registerStackTransformation(removalPolicyTransform);
// runtime.registerStackTransformation(validateNamesTransform);

// return program();
// },
// projectName: $app.name,
// stackName: $app.stage,
// },
// {
// pulumiHome: $cli.paths.home,
// projectSettings: {
// main: $cli.paths.root,
// name: $app.name,
// runtime: "nodejs",
// backend: {
// url: $cli.backend,
// },
// },
// envVars: {
// PULUMI_CONFIG_PASSPHRASE: "",
// PULUMI_SKIP_UPDATE_CHECK: "true",
// PULUMI_EXPERIMENTAL: "1",
// // PULUMI_SKIP_CHECKPOINTS: "true",
// NODE_PATH: $cli.paths.work + "/node_modules",
// ...$cli.env,
// },
// },
// );

// try {
// await stack[$cli.command as "up"]({
// onEvent: (evt) => {
// console.log("~j" + JSON.stringify(evt));
// },
// onOutput: console.log,
// logToStdErr: true,
// logVerbosity: 100,
// });
// } catch (e: any) {
// if (e.name === "ConcurrentUpdateError") {
// console.log("~j" + JSON.stringify({ ConcurrentUpdateEvent: {} }));
// }
// }
initializeLinkRegistry();
return await program();
}
30 changes: 23 additions & 7 deletions internal/components/src/components/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Input, ComponentResourceOptions, output } from "@pulumi/pulumi";
import {
Input,
ComponentResourceOptions,
output,
Output,
all,
} from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import { RandomId } from "@pulumi/random";
import { prefixName, hashNumberToString } from "./helpers/naming";
import { Component } from "./component";
import { AWSLinkable, Link, Linkable } from "./link";

/**
* Properties to create a DNS validated certificate managed by AWS Certificate Manager.
Expand All @@ -18,13 +25,13 @@ export interface BucketArgs {
};
}

export class Bucket extends Component {
export class Bucket extends Component implements Linkable {
public bucket: aws.s3.BucketV2;

constructor(
name: string,
args?: BucketArgs,
opts?: ComponentResourceOptions
opts?: ComponentResourceOptions,
) {
super("sst:sst:Bucket", name, args, opts);

Expand All @@ -39,15 +46,15 @@ export class Bucket extends Component {
bucket: randomId.dec.apply((dec) =>
prefixName(
name.toLowerCase(),
`-${hashNumberToString(parseInt(dec), 8)}`
)
`-${hashNumberToString(parseInt(dec), 8)}`,
),
),
forceDestroy: true,
...args?.nodes?.bucket,
},
{
parent,
}
},
);

output(blockPublicAccess).apply((blockPublicAccess) => {
Expand All @@ -62,7 +69,7 @@ export class Bucket extends Component {
ignorePublicAcls: true,
restrictPublicBuckets: true,
},
{ parent }
{ parent },
);
});

Expand All @@ -86,4 +93,13 @@ export class Bucket extends Component {
bucket: this.bucket,
};
}

public getSSTLink(): Link {
return {
type: `{ bucketName: string }`,
value: all([this.name]).apply(([bucketName]) => ({
bucketName,
})),
};
}
}
5 changes: 5 additions & 0 deletions internal/components/src/components/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class VisibleError extends Error {
constructor(...message: string[]) {
super(message.join("\n"));
}
}
Loading

0 comments on commit d1cfd38

Please sign in to comment.