-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0a7c7c
commit de30620
Showing
21 changed files
with
495 additions
and
34 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
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,123 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/otto8-ai/otto8/apiclient/types" | ||
"github.com/otto8-ai/otto8/pkg/alias" | ||
"github.com/otto8-ai/otto8/pkg/api" | ||
v1 "github.com/otto8-ai/otto8/pkg/storage/apis/otto.otto8.ai/v1" | ||
"github.com/otto8-ai/otto8/pkg/system" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type EmailReceiverHandler struct { | ||
hostname string | ||
} | ||
|
||
func NewEmailReceiverHandler(hostname string) *EmailReceiverHandler { | ||
return &EmailReceiverHandler{ | ||
hostname: hostname, | ||
} | ||
} | ||
|
||
func (e *EmailReceiverHandler) Update(req api.Context) error { | ||
var ( | ||
id = req.PathValue("id") | ||
er v1.EmailReceiver | ||
) | ||
|
||
if err := alias.Get(req.Context(), req.Storage, &er, req.Namespace(), id); err != nil { | ||
return err | ||
} | ||
|
||
var manifest types.EmailReceiverManifest | ||
if err := req.Read(&manifest); err != nil { | ||
return err | ||
} | ||
|
||
er.Spec.EmailReceiverManifest = manifest | ||
|
||
if err := req.Update(&er); err != nil { | ||
return err | ||
} | ||
|
||
return req.Write(convertEmailReceiver(er, e.hostname)) | ||
} | ||
|
||
func (e *EmailReceiverHandler) Delete(req api.Context) error { | ||
var ( | ||
id = req.PathValue("id") | ||
) | ||
|
||
return req.Delete(&v1.EmailReceiver{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: id, | ||
Namespace: req.Namespace(), | ||
}, | ||
}) | ||
} | ||
|
||
func (e *EmailReceiverHandler) Create(req api.Context) error { | ||
var manifest types.EmailReceiverManifest | ||
if err := req.Read(&manifest); err != nil { | ||
return err | ||
} | ||
|
||
er := v1.EmailReceiver{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: system.EmailReceiverPrefix, | ||
Namespace: req.Namespace(), | ||
}, | ||
Spec: v1.EmailReceiverSpec{ | ||
EmailReceiverManifest: manifest, | ||
}, | ||
} | ||
|
||
if err := req.Create(&er); err != nil { | ||
return err | ||
} | ||
|
||
req.WriteHeader(http.StatusCreated) | ||
return req.Write(convertEmailReceiver(er, e.hostname)) | ||
} | ||
|
||
func convertEmailReceiver(emailReceiver v1.EmailReceiver, hostname string) *types.EmailReceiver { | ||
manifest := emailReceiver.Spec.EmailReceiverManifest | ||
er := &types.EmailReceiver{ | ||
Metadata: MetadataFrom(&emailReceiver), | ||
EmailReceiverManifest: manifest, | ||
AddressAssigned: emailReceiver.Status.AliasAssigned, | ||
} | ||
if hostname != "" && er.AddressAssigned { | ||
er.EmailAddress = emailReceiver.Spec.User + "@" + hostname | ||
} | ||
return er | ||
} | ||
|
||
func (e *EmailReceiverHandler) ByID(req api.Context) error { | ||
var ( | ||
er v1.EmailReceiver | ||
id = req.PathValue("id") | ||
) | ||
|
||
if err := alias.Get(req.Context(), req.Storage, &er, req.Namespace(), id); err != nil { | ||
return err | ||
} | ||
|
||
return req.Write(convertEmailReceiver(er, e.hostname)) | ||
} | ||
|
||
func (e *EmailReceiverHandler) List(req api.Context) error { | ||
var emailReceiverList v1.EmailReceiverList | ||
if err := req.List(&emailReceiverList); err != nil { | ||
return err | ||
} | ||
|
||
var resp types.EmailReceiverList | ||
for _, er := range emailReceiverList.Items { | ||
resp.Items = append(resp.Items, *convertEmailReceiver(er, e.hostname)) | ||
} | ||
|
||
return req.Write(resp) | ||
} |
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
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,46 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dustin/go-humanize" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type EmailReceivers struct { | ||
root *Otto8 | ||
Quiet bool `usage:"Only print IDs of agents" short:"q"` | ||
Wide bool `usage:"Print more information" short:"w"` | ||
Output string `usage:"Output format (table, json, yaml)" short:"o" default:"table"` | ||
} | ||
|
||
func (l *EmailReceivers) Customize(cmd *cobra.Command) { | ||
cmd.Aliases = []string{"emailreceiver", "er"} | ||
} | ||
|
||
func (l *EmailReceivers) Run(cmd *cobra.Command, _ []string) error { | ||
ers, err := l.root.Client.ListEmailReceivers(cmd.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if ok, err := output(l.Output, ers); ok || err != nil { | ||
return err | ||
} | ||
|
||
if l.Quiet { | ||
for _, emailReceiver := range ers.Items { | ||
fmt.Println(emailReceiver.ID) | ||
} | ||
return nil | ||
} | ||
|
||
w := newTable("ID", "NAME", "DESCRIPTION", "WORKFLOW", "ADDRESS", "CREATED") | ||
for _, er := range ers.Items { | ||
w.WriteRow(er.ID, er.Name, truncate(er.Description, l.Wide), er.Workflow, | ||
er.EmailAddress, | ||
humanize.Time(er.Created.Time)) | ||
} | ||
|
||
return w.Err() | ||
} |
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,14 @@ | ||
# Required to be set to webhook | ||
type: emailreceiver | ||
|
||
# A display name for you webhook | ||
name: "%NAME%" | ||
|
||
# A description of your webhook | ||
description: "" | ||
|
||
# Required the user portion of the [email protected] email address that will be created | ||
user: "" | ||
|
||
# The workflow ID or workflow alias that this email receiver will trigger | ||
workflow: "" |
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
Oops, something went wrong.