package handler
import (
"fmt"
"github.com/goodrain/rainbond/pkg/component/mq"
apimodel "github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/mq/client"
)
type RegistryAuthSecretAction struct {
dbmanager db.Manager
mqclient client.MQClient
}
func CreateRegistryAuthSecretManager() *RegistryAuthSecretAction {
return &RegistryAuthSecretAction{
dbmanager: db.GetManager(),
mqclient: mq.Default().MqClient,
}
}
func (g *RegistryAuthSecretAction) AddOrUpdateRegistryAuthSecret(req *apimodel.AddOrUpdateRegistryAuthSecretStruct) error {
body := make(map[string]interface{})
body["action"] = "apply"
body["tenant_id"] = req.TenantID
body["secret_id"] = req.SecretID
body["domain"] = req.Domain
body["username"] = req.Username
body["password"] = req.Password
err := g.mqclient.SendBuilderTopic(client.TaskStruct{
Topic: client.WorkerTopic,
TaskType: "apply_registry_auth_secret",
TaskBody: body,
})
if err != nil {
return fmt.Errorf("unexpected error occurred while sending task: %v", err)
}
return nil
}
func (g *RegistryAuthSecretAction) DeleteRegistryAuthSecret(req *apimodel.DeleteRegistryAuthSecretStruct) error {
body := make(map[string]interface{})
body["action"] = "delete"
body["tenant_id"] = req.TenantID
body["secret_id"] = req.SecretID
err := g.mqclient.SendBuilderTopic(client.TaskStruct{
Topic: client.WorkerTopic,
TaskType: "apply_registry_auth_secret",
TaskBody: body,
})
if err != nil {
return fmt.Errorf("unexpected error occurred while sending task: %v", err)
}
return nil
}