"
- }
- return rows
-}
-
-// GetContext gets cluster information from the airshipctl config
-func (c *client) GetContext() []*config.Context {
- return c.settings.Config.GetContexts()
-}
-
-// getContextTableRows turns an array of contexts into html table rows
-func getContextTableRows() string {
- info := c.GetContext()
-
- var rows string
- for _, context := range info {
- // TODO: all rows are editable, probably shouldn't be
- rows += "
" +
- context.NameInKubeconf + "
" +
- context.Manifest + "
" +
- context.KubeContext().LocationOfOrigin + "
" +
- context.KubeContext().Cluster + "
" +
- context.KubeContext().AuthInfo + "
" +
- "
"
- }
- return rows
-}
-
-// GetCredential gets user credentials from the airshipctl config
-func (c *client) GetCredential() []*config.AuthInfo {
- authinfo, err := c.settings.Config.GetAuthInfos()
- if err != nil {
- return []*config.AuthInfo{}
- }
-
- return authinfo
-}
-
-// getContextTableRows turns an array of contexts into html table rows
-func getCredentialTableRows() string {
- info := c.GetCredential()
-
- var rows string
- for _, credential := range info {
- // TODO: all rows are editable, probably shouldn't be
- rows += "
"
- }
- return rows
-}
-
-func getDefaultHTML() (string, error) {
- // go templates need an io writer, since we need a string this buffer can be converted
- var buff bytes.Buffer
-
- // TODO: make the node path dynamic or setable at compile time
- t, err := template.ParseFiles("./internal/integrations/ctl/templates/config.html")
-
- if err != nil {
- return "", err
- }
-
- // add contents to the page
- p := configPage{
- ClusterRows: getClusterTableRows(),
- ContextRows: getContextTableRows(),
- CredentialRows: getCredentialTableRows(),
- Title: "Config",
- Version: GetAirshipCTLVersion(),
- }
-
- // parse and merge the template
- err = template.Must(t, err).Execute(&buff, p)
- if err != nil {
- return "", err
- }
-
- return buff.String(), nil
-}
-
-// SetConfig will flop between requests so we don't have to have them all mapped as function calls
-func SetConfig(request configs.WsMessage) configs.WsMessage {
+// HandleConfigRequest will flop between requests so we don't have to have them all mapped as function calls
+func HandleConfigRequest(request configs.WsMessage) configs.WsMessage {
response := configs.WsMessage{
- Type: configs.AirshipCTL,
- Component: configs.SetConfig,
+ Type: configs.AirshipCTL,
+ Component: configs.CTLConfig,
+ SubComponent: request.SubComponent,
}
var err error
var message string
switch request.SubComponent {
+ case configs.GetDefaults:
+ response.HTML, err = getConfigHTML()
case configs.SetContext:
message, err = setContext(request)
case configs.SetCluster:
@@ -161,6 +52,88 @@ func SetConfig(request configs.WsMessage) configs.WsMessage {
return response
}
+// GetCluster gets cluster information from the airshipctl config
+func (c *client) getCluster() []*config.Cluster {
+ return c.settings.Config.GetClusters()
+}
+
+// getClusterTableRows turns an array of cluster into html table rows
+func getClusterTableRows() string {
+ info := c.getCluster()
+
+ var rows string
+ for _, config := range info {
+ // TODO: all rows are editable, probably shouldn't be
+ rows += "
"
+ }
+ return rows
+}
+
+// GetContext gets cluster information from the airshipctl config
+func (c *client) getContext() []*config.Context {
+ return c.settings.Config.GetContexts()
+}
+
+// getContextTableRows turns an array of contexts into html table rows
+func getContextTableRows() string {
+ info := c.getContext()
+
+ var rows string
+ for _, context := range info {
+ // TODO: all rows are editable, probably shouldn't be
+ rows += "
" +
+ context.NameInKubeconf + "
" +
+ context.Manifest + "
" +
+ context.KubeContext().LocationOfOrigin + "
" +
+ context.KubeContext().Cluster + "
" +
+ context.KubeContext().AuthInfo + "
" +
+ "
"
+ }
+ return rows
+}
+
+// GetCredential gets user credentials from the airshipctl config
+func (c *client) getCredential() []*config.AuthInfo {
+ authinfo, err := c.settings.Config.GetAuthInfos()
+ if err != nil {
+ return []*config.AuthInfo{}
+ }
+
+ return authinfo
+}
+
+// getContextTableRows turns an array of contexts into html table rows
+func getCredentialTableRows() string {
+ info := c.getCredential()
+
+ var rows string
+ for _, credential := range info {
+ // TODO: all rows are editable, probably shouldn't be
+ rows += "
"
+ }
+ return rows
+}
+
+func getConfigHTML() (string, error) {
+ return getHTML("./internal/integrations/ctl/templates/config.html", ctlPage{
+ ClusterRows: getClusterTableRows(),
+ ContextRows: getContextTableRows(),
+ CredentialRows: getCredentialTableRows(),
+ Title: "Config",
+ Version: getAirshipCTLVersion(),
+ })
+}
+
// SetCluster will take ui cluster info, translate them into CTL commands and send a response back to the UI
func setCluster(request configs.WsMessage) (string, error) {
modified, err := config.RunSetCluster(&request.ClusterOptions, c.settings.Config, true)
diff --git a/internal/integrations/ctl/document.go b/internal/integrations/ctl/document.go
new file mode 100755
index 0000000..212ce45
--- /dev/null
+++ b/internal/integrations/ctl/document.go
@@ -0,0 +1,67 @@
+/*
+ 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 ctl
+
+import (
+ "fmt"
+
+ "opendev.org/airship/airshipctl/pkg/document/pull"
+ "opendev.org/airship/airshipui/internal/configs"
+)
+
+// HandleBaremetalRequest will flop between requests so we don't have to have them all mapped as function calls
+func HandleDocumentRequest(request configs.WsMessage) configs.WsMessage {
+ response := configs.WsMessage{
+ Type: configs.AirshipCTL,
+ Component: configs.Document,
+ SubComponent: request.SubComponent,
+ }
+
+ var err error
+ var message string
+ switch request.SubComponent {
+ case configs.GetDefaults:
+ response.HTML, err = getDocumentHTML()
+ case configs.DocPull:
+ message, err = c.docPull()
+ default:
+ err = fmt.Errorf("Subcomponent %s not found", request.SubComponent)
+ }
+
+ if err != nil {
+ response.Error = err.Error()
+ } else {
+ response.Message = message
+ }
+
+ return response
+}
+
+func (c *client) docPull() (string, error) {
+ var message string
+ settings := pull.Settings{AirshipCTLSettings: c.settings}
+ err := settings.Pull()
+ if err == nil {
+ message = fmt.Sprintf("Success")
+ }
+
+ return message, err
+}
+
+func getDocumentHTML() (string, error) {
+ return getHTML("./internal/integrations/ctl/templates/document.html", ctlPage{
+ Title: "Document",
+ Version: getAirshipCTLVersion(),
+ })
+}
diff --git a/internal/integrations/ctl/templates/baremetal.html b/internal/integrations/ctl/templates/baremetal.html
new file mode 100755
index 0000000..897d184
--- /dev/null
+++ b/internal/integrations/ctl/templates/baremetal.html
@@ -0,0 +1,5 @@
+