This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: codegen sst module for ruby on rails projects
- Loading branch information
Showing
10 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'json' | ||
module SST | ||
class << self | ||
private | ||
|
||
def parse_resource(resource_name) | ||
env_var = "SST_RESOURCE_#{resource_name}" | ||
parse_json(ENV[env_var]) | ||
end | ||
|
||
def parse_json(json_string) | ||
return nil if json_string.nil? | ||
JSON.parse(json_string) | ||
rescue JSON::ParserError | ||
json_string # Return the original string if it's not valid JSON | ||
end | ||
|
||
end | ||
|
||
def MyService | ||
@MyService ||= parse_resource('MyService') | ||
end | ||
|
||
def MyVpc | ||
@MyVpc ||= parse_resource('MyVpc') | ||
end | ||
|
||
def MyBucket | ||
@MyBucket ||= parse_resource('MyBucket') | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.env | ||
|
||
# sst | ||
.sst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { auth } from "sst/auth"; | ||
|
||
const session = auth.sessions<{ | ||
user: { | ||
userID: string; | ||
}; | ||
}>(); | ||
|
||
const authorizer = () => | ||
auth.authorizer({ | ||
providers: {}, | ||
session, | ||
callbacks: { | ||
auth: { | ||
async allowClient() { | ||
return true; | ||
}, | ||
async success(ctx, input, req) { | ||
return ctx.session({ | ||
type: "user", | ||
properties: { | ||
userID: "ok", | ||
}, | ||
}); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
export default { | ||
fetch(event: any, ctx: any) { | ||
return authorizer().fetch(event, ctx); | ||
}, | ||
}; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "cloudflare-worker", | ||
"version": "1.0.0", | ||
"description": "", | ||
"type": "module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@cloudflare/workers-types": "^4.20240403.0", | ||
"sst": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* This file is auto-generated by SST. Do not edit. */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import "sst" | ||
export {} | ||
import "sst" | ||
declare module "sst" { | ||
export interface Resource { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference path="./.sst/platform/config.d.ts" /> | ||
|
||
export default $config({ | ||
app(input) { | ||
return { | ||
name: "cloudflare-auth", | ||
removal: input?.stage === "production" ? "retain" : "remove", | ||
home: "cloudflare", | ||
}; | ||
}, | ||
async run() { | ||
const auth = new sst.cloudflare.Auth("Auth", { | ||
authenticator: { | ||
handler: "./authenticator.ts", | ||
}, | ||
}); | ||
return { | ||
url: auth.url, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["esnext"], | ||
"types": ["@cloudflare/workers-types"], | ||
"moduleResolution": "bundler", | ||
"module": "ESNext", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package rails | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/sst/ion/internal/fs" | ||
"github.com/sst/ion/pkg/project/common" | ||
) | ||
|
||
func Generate(root string, links common.Links) error { | ||
projects := fs.FindDown(root, "config.ru") | ||
files := []io.Writer{} | ||
for _, project := range projects { | ||
// check if lib path exists | ||
if _, err := os.Stat(filepath.Join(filepath.Dir(project), "lib")); err == nil { | ||
path := filepath.Join(filepath.Dir(project), "lib", "sst.rb") | ||
file, _ := os.Create(path) | ||
files = append(files, file) | ||
} | ||
} | ||
writer := io.MultiWriter(files...) | ||
writer.Write([]byte(`require 'json' | ||
module SST | ||
class << self | ||
private | ||
def parse_resource(resource_name) | ||
env_var = "SST_RESOURCE_#{resource_name}" | ||
parse_json(ENV[env_var]) | ||
end | ||
def parse_json(json_string) | ||
return nil if json_string.nil? | ||
JSON.parse(json_string) | ||
rescue JSON::ParserError | ||
json_string # Return the original string if it's not valid JSON | ||
end | ||
end | ||
`, | ||
)) | ||
|
||
for name := range links { | ||
writer.Write([]byte(fmt.Sprintf(` | ||
def %s | ||
@%s ||= parse_resource('%s') | ||
end | ||
`, name, name, name))) | ||
} | ||
|
||
writer.Write([]byte("\nend")) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters