mirror of
https://github.com/rancher/norman.git
synced 2025-09-10 03:29:14 +00:00
add insecure flag, fix collection link, add yaml tags
This commit is contained in:
committed by
Darren Shepherd
parent
ee25c89cfd
commit
a978cad0e8
@@ -36,6 +36,7 @@ type ClientOpts struct {
|
|||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
CACerts string
|
CACerts string
|
||||||
|
Insecure bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientOpts) getAuthHeader() string {
|
func (c *ClientOpts) getAuthHeader() string {
|
||||||
@@ -176,6 +177,15 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
|
|||||||
client.Transport = tr
|
client.Transport = tr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.Insecure {
|
||||||
|
tr := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: opts.Insecure,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client.Transport = tr
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", opts.URL, nil)
|
req, err := http.NewRequest("GET", opts.URL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rancher/norman/types"
|
"github.com/rancher/norman/types"
|
||||||
@@ -170,16 +169,9 @@ func (a *APIOperations) DoCreate(schemaType string, createObj interface{}, respO
|
|||||||
return errors.New("Resource type [" + schemaType + "] is not creatable")
|
return errors.New("Resource type [" + schemaType + "] is not creatable")
|
||||||
}
|
}
|
||||||
|
|
||||||
var collectionURL string
|
// using collection link to post doesn't help the resources under project or cluster, because they need a projectId or clusterId in the path
|
||||||
collectionURL, ok = schema.Links[COLLECTION]
|
// for example, v3/projects/foo/apps, v3/cluster/bar/namespaces
|
||||||
if !ok {
|
return a.DoModify("POST", a.Opts.URL+"/"+schemaType, createObj, respObject)
|
||||||
// return errors.New("Failed to find collection URL for [" + schemaType + "]")
|
|
||||||
// This is a hack to address https://github.com/rancher/cattle/issues/254
|
|
||||||
re := regexp.MustCompile("schemas.*")
|
|
||||||
collectionURL = re.ReplaceAllString(schema.Links[SELF], schema.PluralName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.DoModify("POST", collectionURL, createObj, respObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *APIOperations) DoUpdate(schemaType string, existing *types.Resource, updates interface{}, respObject interface{}) error {
|
func (a *APIOperations) DoUpdate(schemaType string, existing *types.Resource, updates interface{}, respObject interface{}) error {
|
||||||
|
@@ -11,10 +11,12 @@ import (
|
|||||||
|
|
||||||
func funcs() template.FuncMap {
|
func funcs() template.FuncMap {
|
||||||
return template.FuncMap{
|
return template.FuncMap{
|
||||||
"capitalize": convert.Capitalize,
|
"capitalize": convert.Capitalize,
|
||||||
"upper": strings.ToUpper,
|
"unCapitalize": convert.Uncapitalize,
|
||||||
"toLower": strings.ToLower,
|
"upper": strings.ToUpper,
|
||||||
"hasGet": hasGet,
|
"toLower": strings.ToLower,
|
||||||
|
"hasGet": hasGet,
|
||||||
|
"hasPost": hasPost,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +28,10 @@ func hasGet(schema *types.Schema) bool {
|
|||||||
return contains(schema.CollectionMethods, http.MethodGet)
|
return contains(schema.CollectionMethods, http.MethodGet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasPost(schema *types.Schema) bool {
|
||||||
|
return contains(schema.CollectionMethods, http.MethodPost)
|
||||||
|
}
|
||||||
|
|
||||||
func contains(list []string, needle string) bool {
|
func contains(list []string, needle string) bool {
|
||||||
for _, i := range list {
|
for _, i := range list {
|
||||||
if i == needle {
|
if i == needle {
|
||||||
|
@@ -21,7 +21,7 @@ type {{.schema.CodeName}} struct {
|
|||||||
types.Resource
|
types.Resource
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- range $key, $value := .structFields}}
|
{{- range $key, $value := .structFields}}
|
||||||
{{$key}} {{$value.Type}} %BACK%json:"{{$value.Name}},omitempty"%BACK%
|
{{$key}} {{$value.Type}} %BACK%json:"{{$value.Name}},omitempty" yaml:"{{$value.Name}},omitempty"%BACK%
|
||||||
{{- end}}
|
{{- end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user