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

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

Timothee Gosselin's avatar
Timothee Gosselin committed
    https://www.gnu.org/licenses/agpl-3.0.html
Timothee Gosselin's avatar
Timothee Gosselin committed

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/application/settings/parameters"

func OrderByResourceRef(s *ConfigSpec) (secrets, configMaps map[string]parameters.Parameters) {
Timothee Gosselin's avatar
Timothee Gosselin committed
	secrets = make(map[string]parameters.Parameters)
	configMaps = make(map[string]parameters.Parameters)
Timothee Gosselin's avatar
Timothee Gosselin committed

	for _, source := range s.Sources {
		if source.Type == "secret" {
			secrets[source.Ref] = parameters.Parameters{}
		} else if source.Type == "configmap" {
			configMaps[source.Ref] = parameters.Parameters{}
		}
	}

	// Then we get the sources that are provided for each parameters and will need a transformation
	for _, p := range *s.Parameters {
		if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.SecretParameter {
			secrets[p.ValueFrom.Ref] = append(secrets[p.ValueFrom.Ref], p)
		}
		if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.ConfigParameter {
			configMaps[p.ValueFrom.Ref] = append(configMaps[p.ValueFrom.Ref], p)
		}
	}

	return secrets, configMaps
}

/*
func OrderBySourceTypeAndRef(s *ConfigSpec) (orderedParams map[string]map[string]parameters.Parameters) {
Timothee Gosselin's avatar
Timothee Gosselin committed
	// We order the parameters by secret and configmap sources
Timothee Gosselin's avatar
Timothee Gosselin committed
	// First we get the sources provided that should be mounted untouched
	//	paramsByResourceName = make(map[string]parameters.Parameters)
	orderedParams = make(map[string]map[string]parameters.Parameters)
	orderedParams["secret"] = make(map[string]parameters.Parameters)
	orderedParams["configmap"] = make(map[string]parameters.Parameters)
	orderedParams["field"] = make(map[string]parameters.Parameters)
	orderedParams["templateValue"] = make(map[string]parameters.Parameters)

Timothee Gosselin's avatar
Timothee Gosselin committed
	for _, ref := range s.SecretRefs {
		orderedParams["secret"][ref] = parameters.Parameters{}
Timothee Gosselin's avatar
Timothee Gosselin committed
	}
	for _, ref := range s.ConfigRefs {
		orderedParams["configmap"][ref] = parameters.Parameters{}

Timothee Gosselin's avatar
Timothee Gosselin committed
	}

	// Then we get the sources that are provided for each parameters and will need a transformation
	for _, p := range *s.Parameters {
		if len(p.ValueFrom.Ref) > 0 {
			orderedParams[string(p.Type)][p.ValueFrom.Ref] = append(orderedParams[string(p.Type)][p.ValueFrom.Ref], p)

Timothee Gosselin's avatar
Timothee Gosselin committed
		}
	}
Timothee Gosselin's avatar
Timothee Gosselin committed
}