-
Notifications
You must be signed in to change notification settings - Fork 15
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
71e4d50
commit 43907dc
Showing
61 changed files
with
1,397 additions
and
1,553 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package types | ||
|
||
type EmailReceiver struct { | ||
Metadata | ||
EmailReceiverManifest | ||
AliasAssigned bool `json:"aliasAssigned,omitempty"` | ||
} | ||
|
||
type EmailReceiverManifest struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Alias string `json:"alias"` | ||
Workflow string `json:"workflow"` | ||
AllowedSenders []string `json:"allowedSenders,omitempty"` | ||
} | ||
|
||
type EmailReceiverList List[EmailReceiver] |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,55 @@ | ||
package alias | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
|
||
"github.com/otto8-ai/nah/pkg/name" | ||
"github.com/otto8-ai/nah/pkg/router" | ||
v1 "github.com/otto8-ai/otto8/pkg/storage/apis/otto.otto8.ai/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
kclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func Get(ctx context.Context, c kclient.Client, obj v1.Aliasable, namespace string, name string) error { | ||
errLookup := c.Get(ctx, router.Key(namespace, name), obj.(kclient.Object)) | ||
if kclient.IgnoreNotFound(errLookup) != nil { | ||
return errLookup | ||
} else if errLookup == nil { | ||
return nil | ||
} | ||
|
||
gvk, err := c.GroupVersionKindFor(obj.(kclient.Object)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var alias v1.Alias | ||
if err := c.Get(ctx, router.Key(namespace, Key(gvk, obj, name)), &alias); apierrors.IsNotFound(err) { | ||
return errLookup | ||
} else if err != nil { | ||
return errors.Join(errLookup, err) | ||
} else if alias.Spec.TargetKind != gvk.Kind { | ||
return errLookup | ||
} | ||
|
||
return c.Get(ctx, router.Key(alias.Spec.TargetNamespace, alias.Spec.TargetName), obj.(kclient.Object)) | ||
} | ||
|
||
func keyFromName(scope, id string) string { | ||
return strings.ToLower(name.SafeHashConcatName(id, scope)) | ||
} | ||
|
||
func getScope(gvk schema.GroupVersionKind, obj v1.Aliasable) string { | ||
if scoped, ok := obj.(v1.AliasScoped); ok && scoped.GetAliasScope() != "" { | ||
return scoped.GetAliasScope() | ||
} | ||
|
||
return gvk.Kind | ||
} | ||
|
||
func Key(gvk schema.GroupVersionKind, obj v1.Aliasable, id string) string { | ||
return keyFromName(getScope(gvk, obj), id) | ||
} |
Oops, something went wrong.