Skip to content
Snippets Groups Projects
Commit d39e003f authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Get puppet classes.

parent a4378c8e
No related branches found
No related tags found
No related merge requests found
...@@ -16,15 +16,21 @@ import ( ...@@ -16,15 +16,21 @@ import (
) )
var data []ResultRecord var data []ResultRecord
var client *http.Client
var password string
var classes map[float64]Puppetclass
func main() { func main() {
password := os.Args[1:][0] password = os.Args[1:][0]
classes = map[float64]Puppetclass{}
tr := &http.Transport { tr := &http.Transport {
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
} }
client := &http.Client { Transport: tr } client = &http.Client { Transport: tr }
// request, err := http.NewRequest("GET", "https://chapman.lysator.liu.se/api/hosts", nil) // request, err := http.NewRequest("GET", "https://chapman.lysator.liu.se/api/hosts", nil)
request, err := http.NewRequest("GET", "http://localhost:8000/hosts.json", nil) request, err := http.NewRequest("GET", "http://localhost:8000/hosts.json", nil)
...@@ -246,7 +252,82 @@ func (f File) Attr(ctx context.Context, a *fuse.Attr) error { ...@@ -246,7 +252,82 @@ func (f File) Attr(ctx context.Context, a *fuse.Attr) error {
return nil return nil
} }
type Puppetclass struct {
Profiles []struct {
Id float64
Name string
Created_at string
Updated_at string
}
/*
[{"id":433,"name":"profiles::elvisp","created_at":"2020-10-27T07:57:47.102Z","updated_at":"2020-10-27T07:57:47.102Z"},
{"id":243,"name":"profiles::service","created_at":"2020-08-16T15:07:23.431Z","updated_at":"2020-08-16T15:07:23.431Z"},
{"id":434,"name":"profiles::vitellary","created_at":"2020 -10-27T07:57:47.130Z","updated_at":"2020-10-27T07:57:47.130Z"}]}
*/
/*
{
"total": 3,
"subtotal": 3,
"page": 1,
"per_page": 50,
"search": null,
"sort": {
"by": null,
"order": null
},
"results": {"profiles":[{"id":433,"name":"profiles::elvisp","created_at":"2020-10-27T07:57:47.102Z","updated_at":"2020-10-27T07:57:47.102Z"},{"id":243,"name"
:"profiles::service","created_at":"2020-08-16T15:07:23.431Z","updated_at":"2020-08-16T15:07:23.431Z"},{"id":434,"name":"profiles::vitellary","created_at":"2020
-10-27T07:57:47.130Z","updated_at":"2020-10-27T07:57:47.130Z"}]}
}
*/
}
type PuppetclassMessage struct {
Total, Subtotal, Page/*, Per_page*/ float64
Results Puppetclass
}
func (f File) ReadAll(ctx context.Context) ([]byte, error) { func (f File) ReadAll(ctx context.Context) ([]byte, error) {
return []byte(fmt.Sprintf("%+v\n", f.record)), nil
var record Puppetclass
if val, ok := classes[f.record.Id]; ok {
record = val
} else {
url := fmt.Sprintf("https://chapman.lysator.liu.se/api/hosts/%d/puppetclasses", int(f.record.Id));
request, err := http.NewRequest("GET",url, nil)
if err != nil {
log.Fatal(err);
}
request.SetBasicAuth("hugo", password);
resp, err := client.Do(request)
if err != nil {
log.Fatal(err);
}
defer resp.Body.Close()
decoder := json.NewDecoder(resp.Body);
var m PuppetclassMessage
err = decoder.Decode(&m)
if err != nil {
log.Fatal(err);
}
classes[f.record.Id] = m.Results
record = m.Results
}
str := ""
for _, r := range record.Profiles {
str += r.Name + "\n"
}
//return []byte(fmt.Sprintf("%+v\n", f.record)), nil
return []byte(str), nil
// return []byte(greeting), nil // return []byte(greeting), nil
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment