- Add internal handler support to ServiceAdapter (Handler field) - Dispatcher routes to internal handler when set (no reverse proxy) - GotifyClient: full CRUD (send/list/delete messages, CRUD applications) - Refactor notification handler: route by X-Resource header, not body format - Register notification as ServiceAdapter with auth required - Resources: send-email, send-message, list-messages, delete-message, delete-all-messages, list-applications, create-application, delete-application - Update examples: sendmsg-email.sh, gotify-crud.sh - Env vars: GOTIFY_URL, GOTIFY_APP_TOKEN, GOTIFY_CLIENT_TOKEN
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
package serviceadapter
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// Upstream defines an upstream target.
|
|
type Upstream struct {
|
|
URL string `json:"url" yaml:"url"`
|
|
TimeoutSeconds int32 `json:"timeoutSeconds" yaml:"timeoutSeconds"`
|
|
}
|
|
|
|
// Auth defines authentication requirements.
|
|
type Auth struct {
|
|
Required bool `json:"required" yaml:"required"`
|
|
Capability string `json:"capability,omitempty" yaml:"capability,omitempty"`
|
|
}
|
|
|
|
// Method defines an HTTP method endpoint.
|
|
type Method struct {
|
|
Verb string `json:"verb" yaml:"verb"`
|
|
UpstreamPath string `json:"upstreamPath" yaml:"upstreamPath"`
|
|
RequestSchema string `json:"requestSchema,omitempty" yaml:"requestSchema,omitempty"`
|
|
ResponseSchema string `json:"responseSchema,omitempty" yaml:"responseSchema,omitempty"`
|
|
Auth *Auth `json:"auth,omitempty" yaml:"auth,omitempty"`
|
|
}
|
|
|
|
// Resource defines a resource with multiple methods.
|
|
type Resource struct {
|
|
Name string `json:"name" yaml:"name"`
|
|
Methods []Method `json:"methods" yaml:"methods"`
|
|
Auth *Auth `json:"auth,omitempty" yaml:"auth,omitempty"`
|
|
}
|
|
|
|
// Spec is the ServiceAdapter spec.
|
|
type Spec struct {
|
|
ServiceName string `json:"serviceName" yaml:"serviceName"`
|
|
Upstream Upstream `json:"upstream" yaml:"upstream"`
|
|
Auth Auth `json:"auth" yaml:"auth"`
|
|
Retryable bool `json:"retryable,omitempty" yaml:"retryable,omitempty"`
|
|
Resources []Resource `json:"resources" yaml:"resources"`
|
|
}
|
|
|
|
// Status is the ServiceAdapter status.
|
|
type Status struct {
|
|
Ready bool `json:"ready,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
LastSyncTime *time.Time `json:"lastSyncTime,omitempty"`
|
|
}
|
|
|
|
// ServiceAdapter is a gateway service adapter.
|
|
// When Handler is set, the dispatcher routes directly to the internal handler
|
|
// instead of reverse-proxying to Spec.Upstream.URL.
|
|
type ServiceAdapter struct {
|
|
Name string // namespace/name
|
|
Namespace string
|
|
ServiceName string
|
|
Spec Spec
|
|
Status Status
|
|
CreatedAt time.Time
|
|
Handler http.Handler `json:"-" yaml:"-"` // internal handler (skip serialization)
|
|
}
|