Skip to content
settings.go 2.08 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
/*

Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.gnu.org/licenses/agpl-3.0.html

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package settings

import (
	"k8s.libre.sh/meta"

	"sigs.k8s.io/controller-runtime/pkg/client"
)

type Settings interface {
	GetMeta() meta.Instance
	GetSecretMeta() meta.Instance
	GetConfigMapMeta() meta.Instance
	GetConfig() Config
	SetDefaults()
	Init(c client.Client) error
}

func NewSettings(s Settings) *Component {
	return &Component{
		CommonMeta: s.GetMeta().(*meta.ObjectMeta),
		SecretMeta: s.GetSecretMeta().(*meta.ObjectMeta),
		ConfigMeta: s.GetConfigMapMeta().(*meta.ObjectMeta),
		ConfigSpec: &ConfigSpec{
			Sources:    s.GetConfig().GetSources(),
			Parameters: s.GetConfig().GetParameters(),
		},
	}
}

/* func GetObjects(s Settings) map[int]objects.Object {

	cm := &configmap.ConfigMap{
		ObjectMeta: &meta.ObjectMeta{},
	}

	secret := &secret.Secret{
		ObjectMeta: &meta.ObjectMeta{},
	}

	objs := make(map[int]objects.Object, 2)

	meta.SetObjectMeta(s.GetConfigMapMeta(), cm.ObjectMeta)
	meta.SetObjectMeta(s.GetSecretMeta(), secret.ObjectMeta)

	params := s.GetConfig()

	for _, p := range *params.GetParameters() {
		if p.MountType == parameters.MountEnvFile &&
			// TO FIX
			p.Type == parameters.SecretParameter &&
			len(p.Value) > 0 {
			secret.Parameters = append(secret.Parameters, p)
		}
		if p.MountType == parameters.MountEnvFile &&
			p.Type == parameters.ConfigParameter &&
			len(p.Value) > 0 {
			cm.Parameters = append(cm.Parameters, p)
		}
	}

	// TODO IMPROVE
	if len(cm.Parameters) > 0 {
		objs[0] = cm
	}

	if len(secret.Parameters) > 0 {
		if objs[0] == nil {
			objs[0] = secret

		} else {
			objs[1] = secret
		}
	}

	return objs
}
*/