APIs

APIs are used primarily to expose custom HTTP endpoints on the Orchestrator server. These HTTP endpoints can serve custom HTML pages or help facilitate arbitrary identity flows. The API extensions can also be used for other tasks such as running a custom script.

Configuration Properties

The apis block takes a list of APIs.

Name

name represents the name of the API.

Serve Service Extension

serveSE is used to define a custom API Service Extension. For more details on how to define an extension, please see the Service Extension docs.

Examples

apis:
  - name: exampleAPI
    serveSE:
      funcName: Serve
      file: /etc/maverics/extensions/api.go
ℹ️
In order to register HTTP endpoints on the Orchestrator’s server, the router found in the github.com/strata-io/service-extension/router package must be used. The extension below demonstrates how to register an endpoint.

/etc/maverics/extensions/api.go

package main

import (
	"fmt"
	"net/http"

	"github.com/strata-io/service-extension/orchestrator"
)

func Serve(api orchestrator.Orchestrator) error {
	var (
		logger = api.Logger()
		router = api.Router()
	)

	logger.Info("se", "exposing custom API")

	err := router.HandleFunc("/error.html", func(rw http.ResponseWriter, req *http.Request) {
		logger.Info("se", "received error page request")

		_, _ = rw.Write([]byte(errorPageText))
	})
	if err != nil {
		return fmt.Errorf("failed to register route: %w", err)
	}

	return nil
}

const errorPageText = "Oops, it looks like there was an error. Please contact [email protected] for help."