airshipctl/pkg/document/plugin/templater/extlib/yaml.go
Alexey Odinokov 47df361761 Implement genCAEx and genSignedCertEx with Subj support
The original sprig-library implementation of
genCA and genSignedCert may accept only CN parameter
which isn't enough for K8s admin certificate.
That certification must have O=system:masters, e.g.
/CN=admin/O=system:masters

This PR introduces the set of functions that
insted of cn accept subj argument that may have
a form compatible with openssl -subj parameter.
If the first symbol isn't '/' subj behaves as
cn argument.

The set of new functions that accept subj arg is:
genCAEx
genCAWithKeyEx
genSignedCertEx
genSignedCertWithKeyEx

Since the implementaion required to copy some
non-exported helper functions from sprig,
the decision was made to separate all go-template
extension functions into a separate package:
extlib. This package can be reused in other
go-applications, it's just necessary to use
GenericFuncMap function to get function-map.

Change-Id: I0ffddee2e597323803bf5f1b54f315ded424b7be
2021-01-29 16:43:32 +00:00

33 lines
909 B
Go

/*
Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
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 extlib
import (
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// Render input yaml as output yaml
// This function is from the Helm project:
// https://github.com/helm/helm
// Copyright The Helm Authors
func toYaml(v interface{}) string {
data, err := yaml.Marshal(v)
if err != nil {
// Swallow errors inside of a template.
return ""
}
return string(data)
}