-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big cleanup, contrib is no longer submodule but regular directory, no…
…n actual modules archived
- Loading branch information
Showing
30 changed files
with
1,100 additions
and
449 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
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
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,2 @@ | ||
# rye-contrib | ||
repo for contributed, third party or in general less-official bindings and builtin functions. It's a submodule of rye repo. |
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,127 @@ | ||
//go:build b_aws | ||
// +build b_aws | ||
|
||
package aws | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/refaktor/rye/env" | ||
"github.com/refaktor/rye/evaldo" | ||
|
||
"fmt" | ||
|
||
"github.com/go-gomail/gomail" | ||
|
||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/ses" | ||
"github.com/aws/aws-sdk-go-v2/service/ses/types" | ||
//"github.com/aws/aws-sdk-go/aws" | ||
//"github.com/aws/aws-sdk-go/aws/client" | ||
//"github.com/aws/aws-sdk-go/aws/session" | ||
//"github.com/aws/aws-sdk-go/service/ses" | ||
) | ||
|
||
var Builtins_aws = map[string]*env.Builtin{ | ||
|
||
"new-aws-session": { | ||
Argsn: 1, | ||
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object { | ||
switch region := arg0.(type) { | ||
case env.String: | ||
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region.Value)) | ||
fmt.Println(cfg) | ||
fmt.Println(err) | ||
if err != nil { | ||
return evaldo.MakeError(ps, "Error creating new AWS session: "+err.Error()) | ||
} | ||
return *env.NewNative(ps.Idx, cfg, "aws-session") | ||
default: | ||
return evaldo.MakeError(ps, "A1 not String") | ||
} | ||
}, | ||
}, | ||
|
||
"aws-session//open-ses": { | ||
Argsn: 1, | ||
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object { | ||
switch cfg := arg0.(type) { | ||
case env.Native: | ||
|
||
svc := ses.NewFromConfig(cfg.Value.(aws.Config)) | ||
//svc := ses.New(sess.Value.(client.ConfigProvider)) | ||
fmt.Println(svc) | ||
return *env.NewNative(ps.Idx, svc, "aws-ses-session") | ||
default: | ||
return evaldo.MakeError(ps, "Arg 1 not native.") | ||
} | ||
}, | ||
}, | ||
|
||
"aws-ses-session//send-raw": { | ||
Argsn: 4, | ||
Doc: "[ ses-session* gomail-message from-email recipients ]", | ||
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object { | ||
switch svc := arg0.(type) { | ||
case env.Native: | ||
switch msg := arg1.(type) { // gomail-message | ||
case env.Native: | ||
switch recps := arg2.(type) { // recipients | ||
case env.Block: | ||
switch fromMl := arg3.(type) { // recipients | ||
case env.Email: | ||
|
||
var recipients []string | ||
for rec := range recps.Series.S { | ||
switch rec2 := recps.Series.S[rec].(type) { | ||
case env.String: | ||
recipients = append(recipients, rec2.Value) | ||
case env.Email: | ||
recipients = append(recipients, rec2.Address) | ||
} | ||
} | ||
|
||
fmt.Println(recipients) | ||
|
||
fmt.Println(msg) | ||
|
||
fromEmail := fromMl.Address | ||
|
||
fmt.Println(recipients) | ||
|
||
var emailRaw bytes.Buffer | ||
msg.Value.(*gomail.Message).WriteTo(&emailRaw) | ||
|
||
// create new raw message | ||
message := types.RawMessage{Data: emailRaw.Bytes()} | ||
|
||
fmt.Println("111") | ||
input := &ses.SendRawEmailInput{Source: &fromEmail, Destinations: recipients, RawMessage: &message} | ||
|
||
fmt.Println("222") | ||
// send raw email | ||
_, err := svc.Value.(*ses.Client).SendRawEmail(context.TODO(), input) | ||
if err != nil { | ||
return evaldo.MakeError(ps, err.Error()) | ||
} | ||
fmt.Println("SHOULD SEND") | ||
default: | ||
return evaldo.MakeError(ps, "A4 not String") | ||
|
||
} | ||
default: | ||
return evaldo.MakeError(ps, "A3 not Block") | ||
} | ||
default: | ||
return evaldo.MakeError(ps, "A2 not Native") | ||
} | ||
default: | ||
return evaldo.MakeError(ps, "A1 not Native") | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !b_aws | ||
// +build !b_aws | ||
|
||
package aws | ||
|
||
import ( | ||
"github.com/refaktor/rye/env" | ||
) | ||
|
||
var Builtins_aws = map[string]*env.Builtin{} |
Oops, something went wrong.