ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
89
services/oci-l4-relay-guest/main.go
Normal file
89
services/oci-l4-relay-guest/main.go
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const defaultConfigPath = "/etc/oci-l4-relay/config.json"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fatal(errors.New("expected bootstrap, reconcile, admission, smtp-deny, logs, status, health, or telemetry"))
|
||||
}
|
||||
flags := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
|
||||
configPath := flags.String("config", defaultConfigPath, "configuration path")
|
||||
_ = flags.Parse(os.Args[2:])
|
||||
configuration, err := loadConfig(*configPath)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer cancel()
|
||||
switch os.Args[1] {
|
||||
case "bootstrap":
|
||||
err = bootstrap(ctx, configuration)
|
||||
case "reconcile":
|
||||
err = reconcile(ctx, configuration)
|
||||
case "admission":
|
||||
if flags.NArg() != 1 {
|
||||
fatal(errors.New("admission expects refresh or restore"))
|
||||
}
|
||||
err = runAdmissionOperation(ctx, configuration, flags.Arg(0))
|
||||
case "smtp-deny":
|
||||
if flags.NArg() != 1 {
|
||||
fatal(errors.New("smtp-deny expects refresh or restore"))
|
||||
}
|
||||
err = runSMTPDenyOperation(ctx, configuration, flags.Arg(0))
|
||||
case "logs":
|
||||
if flags.NArg() != 1 || flags.Arg(0) != "update" {
|
||||
fatal(errors.New("logs expects update"))
|
||||
}
|
||||
err = updateLogCredential(ctx, configuration)
|
||||
case "status":
|
||||
err = reportStatus(configuration, false)
|
||||
case "health":
|
||||
err = reportStatus(configuration, true)
|
||||
case "telemetry":
|
||||
err = reportTelemetry(ctx, configuration)
|
||||
default:
|
||||
err = fmt.Errorf("unknown command %q", os.Args[1])
|
||||
}
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func runSMTPDenyOperation(ctx context.Context, configuration config, operation string) error {
|
||||
if configuration.MailRelayAddress == "" {
|
||||
return nil
|
||||
}
|
||||
switch operation {
|
||||
case "refresh":
|
||||
return updateSMTPDeny(ctx, configuration)
|
||||
case "restore":
|
||||
return restoreSMTPDeny(ctx, configuration)
|
||||
default:
|
||||
return fmt.Errorf("unknown SMTP deny operation %q", operation)
|
||||
}
|
||||
}
|
||||
|
||||
func runAdmissionOperation(ctx context.Context, configuration config, operation string) error {
|
||||
switch operation {
|
||||
case "refresh":
|
||||
return updateAdmission(ctx, configuration)
|
||||
case "restore":
|
||||
return restoreAdmission(ctx, configuration)
|
||||
default:
|
||||
return fmt.Errorf("unknown admission operation %q", operation)
|
||||
}
|
||||
}
|
||||
|
||||
func fatal(err error) {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Loading…
Reference in a new issue