diff --git a/pkg/boot/discovery.go b/pkg/boot/discovery.go index c7d79d014..2e9a5aa0f 100644 --- a/pkg/boot/discovery.go +++ b/pkg/boot/discovery.go @@ -102,13 +102,37 @@ func (fp *discovery) UpsertTenant(ctx context.Context, tenant string, body *Tena } func (fp *discovery) RemoveTenant(ctx context.Context, tenant string) error { - // TODO implement me - panic("implement me") + if err := fp.tenantOp.RemoveTenant(tenant); err != nil { + return errors.Wrapf(err, "failed to remove tenant '%s'", tenant) + } + return nil } func (fp *discovery) UpsertCluster(ctx context.Context, tenant, cluster string, body *ClusterBody) error { - // TODO implement me - panic("implement me") + op, ok := fp.centers[tenant] + if !ok { + return ErrorNoTenant + } + + cfg, err := fp.GetTenant(ctx, tenant) + if err != nil { + return err + } + + for _, newCluster := range cfg.DataSourceClusters { + if newCluster.Name == cluster { + newCluster.Type = body.Type + newCluster.Parameters = body.Parameters + newCluster.SqlMaxLimit = body.SqlMaxLimit + } + } + + err = op.Write(ctx, "clusters", cfg) + if err != nil { + return err + } + + return nil } func (fp *discovery) RemoveCluster(ctx context.Context, tenant, cluster string) error { diff --git a/pkg/config/config_writer.go b/pkg/config/config_writer.go index e494dfe85..5d2d6662e 100644 --- a/pkg/config/config_writer.go +++ b/pkg/config/config_writer.go @@ -48,9 +48,9 @@ func (c *configWriter) Write(ctx context.Context, item ConfigItem, cfg *Tenant) allKeyMap := c.pathInfo.ConfigKeyMapping ret := make(map[PathKey]string) - for i := range allKeyMap { - if allKeyMap[i] == string(item) { - ret[i] = allKeyMap[i] + for pathKey := range allKeyMap { + if allKeyMap[pathKey] == string(item) { + ret[pathKey] = allKeyMap[pathKey] } }