Move template and keystore functions to internal packages
This commit is contained in:
committed by
Arthur Barr
parent
6abbbb0394
commit
77eb7381e7
@@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ibm-messaging/mq-container/internal/command"
|
"github.com/ibm-messaging/mq-container/internal/command"
|
||||||
"github.com/ibm-messaging/mq-container/internal/logger"
|
"github.com/ibm-messaging/mq-container/internal/logger"
|
||||||
|
"github.com/ibm-messaging/mq-container/internal/mqtemplate"
|
||||||
"github.com/ibm-messaging/mq-container/internal/name"
|
"github.com/ibm-messaging/mq-container/internal/name"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -85,7 +86,7 @@ func configureLogger() error {
|
|||||||
|
|
||||||
func configureWeb(qmName string) error {
|
func configureWeb(qmName string) error {
|
||||||
out := "/etc/mqm/web/installations/Installation1/angular.persistence/admin.json"
|
out := "/etc/mqm/web/installations/Installation1/angular.persistence/admin.json"
|
||||||
return processTemplateFile("/etc/mqm/admin.json.tpl", out, map[string]string{"QueueManagerName": qmName})
|
return mqtemplate.ProcessTemplateFile("/etc/mqm/admin.json.tpl", out, map[string]string{"QueueManagerName": qmName}, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logTerminationf(format string, args ...interface{}) {
|
func logTerminationf(format string, args ...interface{}) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/ibm-messaging/mq-container/internal/mqtemplate"
|
||||||
)
|
)
|
||||||
|
|
||||||
func updateMQSC(appPasswordRequired bool) error {
|
func updateMQSC(appPasswordRequired bool) error {
|
||||||
@@ -30,7 +32,7 @@ func updateMQSC(appPasswordRequired bool) error {
|
|||||||
if os.Getenv("MQ_DEV") == "true" {
|
if os.Getenv("MQ_DEV") == "true" {
|
||||||
const mqscTemplate string = mqsc + ".tpl"
|
const mqscTemplate string = mqsc + ".tpl"
|
||||||
// Re-configure channel if app password not set
|
// Re-configure channel if app password not set
|
||||||
err := processTemplateFile(mqsc+".tpl", mqsc, map[string]string{"ChckClnt": checkClient})
|
err := mqtemplate.ProcessTemplateFile(mqsc+".tpl", mqsc, map[string]string{"ChckClnt": checkClient}, log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,20 +21,22 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/ibm-messaging/mq-container/internal/command"
|
"github.com/ibm-messaging/mq-container/internal/command"
|
||||||
|
"github.com/ibm-messaging/mq-container/internal/keystore"
|
||||||
|
"github.com/ibm-messaging/mq-container/internal/mqtemplate"
|
||||||
)
|
)
|
||||||
|
|
||||||
func configureWebTLS(cms *KeyStore) error {
|
func configureWebTLS(cms *keystore.KeyStore) error {
|
||||||
dir := "/run/runmqdevserver/tls"
|
dir := "/run/runmqdevserver/tls"
|
||||||
ks := NewJKSKeyStore(filepath.Join(dir, "key.jks"), cms.Password)
|
ks := keystore.NewJKSKeyStore(filepath.Join(dir, "key.jks"), cms.Password)
|
||||||
ts := NewJKSKeyStore(filepath.Join(dir, "trust.jks"), cms.Password)
|
ts := keystore.NewJKSKeyStore(filepath.Join(dir, "trust.jks"), cms.Password)
|
||||||
|
|
||||||
log.Debug("Creating key store")
|
log.Debug("Creating key store")
|
||||||
err := ks.Create()
|
err := ks.Create(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Debug("Creating trust store")
|
log.Debug("Creating trust store")
|
||||||
err = ts.Create()
|
err = ts.Create(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -104,14 +106,14 @@ func configureTLS(qmName string, inputFile string, passPhrase string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cms := NewCMSKeyStore(keyFile, passPhrase)
|
cms := keystore.NewCMSKeyStore(keyFile, passPhrase)
|
||||||
|
|
||||||
err = cms.Create()
|
err = cms.Create(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cms.CreateStash()
|
err = cms.CreateStash(log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -145,11 +147,11 @@ func configureTLS(qmName string, inputFile string, passPhrase string) error {
|
|||||||
const mqsc string = "/etc/mqm/20-dev-tls.mqsc"
|
const mqsc string = "/etc/mqm/20-dev-tls.mqsc"
|
||||||
const mqscTemplate string = mqsc + ".tpl"
|
const mqscTemplate string = mqsc + ".tpl"
|
||||||
|
|
||||||
err = processTemplateFile(mqscTemplate, mqsc, map[string]string{
|
err = mqtemplate.ProcessTemplateFile(mqscTemplate, mqsc, map[string]string{
|
||||||
"SSLKeyR": filepath.Join(dir, "key"),
|
"SSLKeyR": filepath.Join(dir, "key"),
|
||||||
"CertificateLabel": newLabel,
|
"CertificateLabel": newLabel,
|
||||||
"SSLCipherSpec": sslCipherSpec,
|
"SSLCipherSpec": sslCipherSpec,
|
||||||
})
|
}, log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
package main
|
|
||||||
|
// Package keystore contains code to create and update keystores
|
||||||
|
package keystore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@@ -23,6 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ibm-messaging/mq-container/internal/command"
|
"github.com/ibm-messaging/mq-container/internal/command"
|
||||||
|
"github.com/ibm-messaging/mq-container/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KeyStore describes information about a keystore file
|
// KeyStore describes information about a keystore file
|
||||||
@@ -54,7 +57,7 @@ func NewCMSKeyStore(filename, password string) *KeyStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a key store, if it doesn't already exist
|
// Create a key store, if it doesn't already exist
|
||||||
func (ks *KeyStore) Create() error {
|
func (ks *KeyStore) Create(log *logger.Logger) error {
|
||||||
_, err := os.Stat(ks.Filename)
|
_, err := os.Stat(ks.Filename)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Keystore already exists so we should refresh it by deleting it.
|
// Keystore already exists so we should refresh it by deleting it.
|
||||||
@@ -95,7 +98,7 @@ func (ks *KeyStore) Create() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateStash creates a key stash, if it doesn't already exist
|
// CreateStash creates a key stash, if it doesn't already exist
|
||||||
func (ks *KeyStore) CreateStash() error {
|
func (ks *KeyStore) CreateStash(log *logger.Logger) error {
|
||||||
extension := filepath.Ext(ks.Filename)
|
extension := filepath.Ext(ks.Filename)
|
||||||
stashFile := ks.Filename[0:len(ks.Filename)-len(extension)] + ".sth"
|
stashFile := ks.Filename[0:len(ks.Filename)-len(extension)] + ".sth"
|
||||||
log.Debugf("TLS stash file: %v", stashFile)
|
log.Debugf("TLS stash file: %v", stashFile)
|
||||||
@@ -13,7 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
package main
|
|
||||||
|
// Package mqtemplate contains code to process template files
|
||||||
|
package mqtemplate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -21,12 +23,12 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/ibm-messaging/mq-container/internal/command"
|
"github.com/ibm-messaging/mq-container/internal/command"
|
||||||
|
"github.com/ibm-messaging/mq-container/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// processTemplateFile takes a Go templateFile, and processes it with the
|
// ProcessTemplateFile takes a Go templateFile, and processes it with the
|
||||||
// supplied data, writing to destFile
|
// supplied data, writing to destFile
|
||||||
func processTemplateFile(templateFile, destFile string, data interface{}) error {
|
func ProcessTemplateFile(templateFile, destFile string, data interface{}, log *logger.Logger) error {
|
||||||
// Re-configure channel if app password not set
|
|
||||||
t, err := template.ParseFiles(templateFile)
|
t, err := template.ParseFiles(templateFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
Reference in New Issue
Block a user