Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amine7536/goforeman
Go bindings for Foreman REST API
https://github.com/amine7536/goforeman
devops foreman golang rest-client
Last synced: 11 days ago
JSON representation
Go bindings for Foreman REST API
- Host: GitHub
- URL: https://github.com/amine7536/goforeman
- Owner: amine7536
- License: mit
- Created: 2017-05-12T14:52:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-04T13:07:30.000Z (over 6 years ago)
- Last Synced: 2024-06-20T05:08:37.058Z (5 months ago)
- Topics: devops, foreman, golang, rest-client
- Language: Go
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goforeman
Go bindings for Foreman REST APIHeavily inspired by DigitalOcean GoDo : https://github.com/digitalocean/godo
!! Work In Progress !!
## Usage
```go
package mainimport (
"context"
"crypto/tls"
"fmt"
"log"
"net/http"
"os""github.com/amine7536/goforeman"
)type AuthTransport struct {
*http.Transport
Username string
Password string
}func (t AuthTransport) RoundTrip(r *http.Request) (*http.Response, error) {
r.SetBasicAuth(t.Username, t.Password)
return t.Transport.RoundTrip(r)
}func main() {
foremanURL := os.Getenv("FOREMAN_URL")
foremanUser := os.Getenv("FOREMAN_USER")
foremanPassword := os.Getenv("FOREMAN_PASSWORD")client := http.Client{
Transport: AuthTransport{
&http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
foremanUser,
foremanPassword,
},
}foreman := goforeman.New(&client, foremanURL)
ctx := context.TODO()
hosts, _, err := foreman.Hosts.List(ctx)
if err != nil {
log.Fatalln(err.Error())
}for _, h := range hosts {
v, _, _ := foreman.Hosts.Get(ctx, h.Name)
if err != nil {
log.Fatalln(err.Error())
}
fmt.Println(v)
}d, _, err := foreman.Dashboard.Get(ctx)
if err != nil {
log.Fatalf("Error: %s", err.Error())
}
fmt.Println(d)facts, _, err := foreman.Facts.Get(ctx, "foremanserver.lab.local.dev")
if err != nil {
log.Fatalf("Error: %s", err.Error())
}
fmt.Println(facts)}
```