Преглед изворни кода

Merge pull request #119 from porter-dev/form-cluster-integration

Form cluster integration
sunguroku пре 5 година
родитељ
комит
d12a8d8b86

+ 1 - 0
dashboard/src/components/values-form/ValuesForm.tsx

@@ -62,6 +62,7 @@ export default class ValuesForm extends Component<PropsType, StateType> {
 
   // Initialize corresponding state fields for form blocks
   componentDidMount() {
+    console.log(this.props.sections)
     this.updateFormState();
   }
 

+ 2 - 1
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedChart.tsx

@@ -107,6 +107,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
               console.log(err);
               resolve(null);
             } else {
+              console.log(res.data)
               let { form } = res.data;
               console.log(form)
               resolve(form);
@@ -144,8 +145,8 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
       cluster_id: currentCluster.id,
     }, (err: any, res: any) => {
       if (err) {
-        setCurrentError(err);
         this.setState({ saveValuesStatus: 'error' });
+        console.log(err)
       } else {
         this.setState({ 
           saveValuesStatus: 'successful',

+ 1 - 0
dashboard/src/main/home/templates/expanded-template/ExpandedTemplate.tsx

@@ -44,6 +44,7 @@ export default class ExpandedTemplate extends Component<PropsType, StateType> {
       if (err) {
         this.setState({ loading: false, error: true });
       } else {
+        console.log(res.data);
         let { form, values, markdown, metadata } = res.data;
         let keywords = metadata.keywords;
         this.setState({ form, values, markdown, keywords, loading: false, error: false });

+ 22 - 6
internal/templater/parser/parser.go

@@ -47,6 +47,8 @@ func FormYAMLFromBytes(def *ClientConfigDefault, bytes []byte) (*models.FormYAML
 		}
 
 		for queryResKey, queryResVal := range queryRes {
+			fmt.Printf("PARSER: found value %s, %v\n", queryResKey, queryResVal)
+
 			data[queryResKey] = queryResVal
 		}
 	}
@@ -126,7 +128,9 @@ func formToLookupTable(def *ClientConfigDefault, form *models.FormYAML) map[*mod
 					lookup[content.Context] = formContextToContextConfig(def, content.Context)
 				}
 
-				if content.Value != "" {
+				fmt.Printf("PARSER: content value %v, variable %s\n", content.Value, content.Variable)
+
+				if content.Value != nil && fmt.Sprintf("%v", content.Value) != "" {
 					// TODO -- case on whether value is proper query string, if not resolve it to a
 					// proper query string
 					query, err := utils.NewQuery(
@@ -134,6 +138,12 @@ func formToLookupTable(def *ClientConfigDefault, form *models.FormYAML) map[*mod
 						fmt.Sprintf("%v", content.Value),
 					)
 
+					fmt.Printf(
+						"PARSER: added query %s, %s\n",
+						fmt.Sprintf("tabs[%d].sections[%d].contents[%d]", i, j, k),
+						fmt.Sprintf("%v", content.Value),
+					)
+
 					if err != nil {
 						continue
 					}
@@ -147,6 +157,12 @@ func formToLookupTable(def *ClientConfigDefault, form *models.FormYAML) map[*mod
 						fmt.Sprintf("{ .%v }", content.Variable),
 					)
 
+					fmt.Printf(
+						"PARSER: added query %s, %s\n",
+						fmt.Sprintf("tabs[%d].sections[%d].contents[%d]", i, j, k),
+						fmt.Sprintf("{ .%v }", content.Variable),
+					)
+
 					if err != nil {
 						continue
 					}
@@ -203,11 +219,11 @@ func formContextToContextConfig(def *ClientConfigDefault, context *models.FormCo
 
 		// identify object based on passed config
 		obj := &td.Object{
-			Group:     context.Config["Group"],
-			Version:   context.Config["Version"],
-			Resource:  context.Config["Resource"],
-			Namespace: context.Config["Namespace"],
-			Name:      context.Config["Name"],
+			Group:     context.Config["group"],
+			Version:   context.Config["version"],
+			Resource:  context.Config["resource"],
+			Namespace: context.Config["namespace"],
+			Name:      context.Config["name"],
 		}
 
 		res.TemplateReader = td.NewDynamicTemplateReader(def.DynamicClient, obj)

+ 2 - 3
internal/templater/utils/query.go

@@ -2,7 +2,6 @@ package utils
 
 import (
 	"fmt"
-	"reflect"
 
 	"github.com/porter-dev/porter/internal/templater"
 	"k8s.io/client-go/util/jsonpath"
@@ -44,11 +43,11 @@ func QueryValues(
 			continue
 		}
 
-		queryRes := make([]reflect.Value, 0)
+		queryRes := make([]interface{}, 0)
 
 		for ix := range fullResults {
 			for _, result := range fullResults[ix] {
-				queryRes = append(queryRes, reflect.ValueOf(result.Interface()))
+				queryRes = append(queryRes, result.Interface())
 			}
 		}
 

+ 37 - 0
internal/templater/utils/query_test.go

@@ -0,0 +1,37 @@
+package utils_test
+
+import (
+	"encoding/json"
+	"testing"
+
+	"github.com/porter-dev/porter/internal/templater"
+	"github.com/porter-dev/porter/internal/templater/utils"
+)
+
+type testType struct {
+	Value interface{} `json:"value,omitempty"`
+}
+
+func TestQueryValues(t *testing.T) {
+	vals := map[string]interface{}{
+		"testing": map[string]interface{}{
+			"hello": "there",
+		},
+	}
+
+	queries := make([]*templater.TemplateReaderQuery, 0)
+
+	query, _ := utils.NewQuery("test", `{ .testing }`)
+
+	queries = append(queries, query)
+
+	res, _ := utils.QueryValues(vals, queries)
+
+	test := &testType{
+		Value: res["test"],
+	}
+
+	bytes, _ := json.Marshal(test)
+
+	t.Errorf(string(bytes))
+}

+ 0 - 21
node_modules/@types/random-words/LICENSE

@@ -1,21 +0,0 @@
-    MIT License
-
-    Copyright (c) Microsoft Corporation.
-
-    Permission is hereby granted, free of charge, to any person obtaining a copy
-    of this software and associated documentation files (the "Software"), to deal
-    in the Software without restriction, including without limitation the rights
-    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-    copies of the Software, and to permit persons to whom the Software is
-    furnished to do so, subject to the following conditions:
-
-    The above copyright notice and this permission notice shall be included in all
-    copies or substantial portions of the Software.
-
-    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-    SOFTWARE

+ 0 - 16
node_modules/@types/random-words/README.md

@@ -1,16 +0,0 @@
-# Installation
-> `npm install --save @types/random-words`
-
-# Summary
-This package contains type definitions for random-words (https://github.com/punkave/random-words#readme).
-
-# Details
-Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/random-words.
-
-### Additional Details
- * Last updated: Tue, 08 Sep 2020 12:35:22 GMT
- * Dependencies: none
- * Global values: none
-
-# Credits
-These definitions were written by [Piotr Błażejewicz](https://github.com/peterblazejewicz).

+ 0 - 34
node_modules/@types/random-words/index.d.ts

@@ -1,34 +0,0 @@
-// Type definitions for random-words 1.1
-// Project: https://github.com/punkave/random-words#readme
-// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
-// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-
-/**
- * generates random words for use as sample text.
- * We use it to generate random blog posts when testing Apostrophe.
- */
-declare function words(
-    options?: words.Options & {
-        join: string;
-    },
-): string;
-declare function words(options: words.Options | number): string | string[];
-
-declare namespace words {
-    let wordList: string[];
-
-    interface Options {
-        exactly?: number;
-        formatter?: WordFormatter;
-        join?: string;
-        max?: number;
-        maxLength?: number;
-        min?: number;
-        separator?: string;
-        wordsPerString?: number;
-    }
-
-    type WordFormatter = (word: string, relativeIndex?: number) => string;
-}
-
-export = words;

+ 0 - 54
node_modules/@types/random-words/package.json

@@ -1,54 +0,0 @@
-{
-  "_from": "@types/random-words",
-  "_id": "@types/random-words@1.1.0",
-  "_inBundle": false,
-  "_integrity": "sha512-YZqkHIAGoXv6mlyEOwluhMjF9aotH2m9HrCCR+PNtES/ED00u5u4W7X1lWxc5AaFRKdKx+5orWTFW7iyGrZpOQ==",
-  "_location": "/@types/random-words",
-  "_phantomChildren": {},
-  "_requested": {
-    "type": "tag",
-    "registry": true,
-    "raw": "@types/random-words",
-    "name": "@types/random-words",
-    "escapedName": "@types%2frandom-words",
-    "scope": "@types",
-    "rawSpec": "",
-    "saveSpec": null,
-    "fetchSpec": "latest"
-  },
-  "_requiredBy": [
-    "#USER",
-    "/"
-  ],
-  "_resolved": "https://registry.npmjs.org/@types/random-words/-/random-words-1.1.0.tgz",
-  "_shasum": "7f4245faf2092caa6511f6fadda303162a3e3772",
-  "_spec": "@types/random-words",
-  "_where": "/Users/jusrhee/Documents/porter",
-  "bugs": {
-    "url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
-  },
-  "bundleDependencies": false,
-  "contributors": [
-    {
-      "name": "Piotr Błażejewicz",
-      "url": "https://github.com/peterblazejewicz"
-    }
-  ],
-  "dependencies": {},
-  "deprecated": false,
-  "description": "TypeScript definitions for random-words",
-  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme",
-  "license": "MIT",
-  "main": "",
-  "name": "@types/random-words",
-  "repository": {
-    "type": "git",
-    "url": "git+https://github.com/DefinitelyTyped/DefinitelyTyped.git",
-    "directory": "types/random-words"
-  },
-  "scripts": {},
-  "typeScriptVersion": "3.1",
-  "types": "index.d.ts",
-  "typesPublisherContentHash": "2cb4b703bd042634031da19d90d2c93ea8f42cdb8948a33990d439fd346eff93",
-  "version": "1.1.0"
-}

+ 5 - 2
server/api/release_handler.go

@@ -2,6 +2,7 @@ package api
 
 import (
 	"encoding/json"
+	"fmt"
 	"net/http"
 	"net/url"
 	"strconv"
@@ -149,7 +150,9 @@ func (app *App) HandleGetRelease(w http.ResponseWriter, r *http.Request) {
 
 	for _, file := range release.Chart.Files {
 		if strings.Contains(file.Name, "form.yaml") {
-			formYAML, _ := parser.FormYAMLFromBytes(parserDef, file.Data)
+			formYAML, err := parser.FormYAMLFromBytes(parserDef, file.Data)
+			fmt.Println("FORM RESULT:", formYAML, err)
+
 			if err != nil {
 				break
 			}
@@ -159,7 +162,7 @@ func (app *App) HandleGetRelease(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
-	if err := json.NewEncoder(w).Encode(release); err != nil {
+	if err := json.NewEncoder(w).Encode(res); err != nil {
 		app.handleErrorFormDecoding(err, ErrReleaseDecode, w)
 		return
 	}

+ 7 - 0
server/api/template_handler.go

@@ -2,6 +2,7 @@ package api
 
 import (
 	"encoding/json"
+	"fmt"
 	"net/http"
 	"net/url"
 	"strings"
@@ -87,6 +88,8 @@ func (app *App) HandleReadTemplate(w http.ResponseWriter, r *http.Request) {
 		if strings.Contains(file.Name, "form.yaml") {
 			formYAML, err := parser.FormYAMLFromBytes(parserDef, file.Data)
 
+			fmt.Println("FORM RESULT:", formYAML, err)
+
 			if err != nil {
 				break
 			}
@@ -97,5 +100,9 @@ func (app *App) HandleReadTemplate(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
+	bytesRes, _ := json.Marshal(res)
+
+	fmt.Println("RAW RESPONSE:", string(bytesRes), res)
+
 	json.NewEncoder(w).Encode(res)
 }