foremanhttp

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package foremanhttp provides an embeddable admin JSON API for a Foreman client.

Index

Examples

Constants

View Source
const RequestIDHeader = "X-Request-Id"

RequestIDHeader carries the request id.

Variables

This section is empty.

Functions

func Handler

func Handler(client *foreman.Client) http.Handler

Handler returns the admin JSON API for client.

Example
package main

import (
	"net/http"

	"github.com/thnhdatle/foreman"
	"github.com/thnhdatle/foreman/foremanhttp"
)

func main() {
	var client *foreman.Client
	mux := http.NewServeMux()
	requireAdmin := func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if r.Header.Get("Authorization") != "Bearer secret-from-config" {
				http.Error(w, "forbidden", http.StatusForbidden)
				return
			}
			next.ServeHTTP(w, r)
		})
	}
	mux.Handle("/admin/foreman/", requireAdmin(http.StripPrefix("/admin/foreman", foremanhttp.Handler(client))))
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL