Use authentication token from config for communication with Nomad

This commit is contained in:
Jan-Eric Hellenberg
2021-07-26 11:41:30 +02:00
committed by Jan-Eric Hellenberg
parent 23b726cef9
commit 3aa1227db6
7 changed files with 58 additions and 46 deletions

View File

@ -81,15 +81,15 @@ type APIClient struct {
// NewExecutorAPI creates a new api client.
// One client is usually sufficient for the complete runtime of the API.
func NewExecutorAPI(nomadURL *url.URL, nomadNamespace string) (ExecutorAPI, error) {
func NewExecutorAPI(nomadURL *url.URL, nomadNamespace, nomadToken string) (ExecutorAPI, error) {
client := &APIClient{apiQuerier: &nomadAPIClient{}}
err := client.init(nomadURL, nomadNamespace)
err := client.init(nomadURL, nomadNamespace, nomadToken)
return client, err
}
// init prepares an apiClient to be able to communicate to a provided Nomad API.
func (a *APIClient) init(nomadURL *url.URL, nomadNamespace string) error {
if err := a.apiQuerier.init(nomadURL, nomadNamespace); err != nil {
func (a *APIClient) init(nomadURL *url.URL, nomadNamespace, nomadToken string) error {
if err := a.apiQuerier.init(nomadURL, nomadNamespace, nomadToken); err != nil {
return fmt.Errorf("error initializing API querier: %w", err)
}
return nil