Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
foremanFS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
foremanFS
Commits
d39e003f
Commit
d39e003f
authored
4 years ago
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Get puppet classes.
parent
a4378c8e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+84
-3
84 additions, 3 deletions
main.go
with
84 additions
and
3 deletions
main.go
+
84
−
3
View file @
d39e003f
...
@@ -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
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment