OpenAPI specification and related artifacts for HashiCorp Nomad

Overview

This repository contains the HashiCorp Nomad OpenAPI specification and related artifacts.

The OpenAPI specification defines a machine-readable schema for describing HTTP APIs. From an OpenAPI specification, clients and servers for your project can be generated in a number of programming languages.

Quick start

The latest version of the OpenAPI specification for the Version 1 Nomad HTTP API can be found in this repository at v1/openapi.yaml. This file is itself a generated file and should not be edited directly. You can use this file to generate a client for the Nomad HTTP API in the language of your choice.

The OpenAPI ecosystem has a number of existing code generators to choose from. This repository uses the OpenAPI Generator project to generate a test client in Golang that is then used to validate the generated specification.

To generate a ruby client using the OpenAPI Generator, you can use the following docker command from the root of this repository.

$ mkdir -p /tmp/nomad-openapi && docker run \
	--rm \
	-v "$PWD:/local" \
	-v "/tmp/nomad-openapi:/output" \
	openapitools/openapi-generator-cli:v5.2.0 generate -i /local/v1/openapi.yaml -g ruby -o /output/

Generating a client in a different language should be as straightforward as changing the -g argument in the command above to your language of choice. Check the OpenAPI Generators page for a full list of supported languages.

This repository is currently experimental, and, as such, there is no guarantee of support at this time.

Community Guidelines

The HashiCorp community is a mixture of professionals, volunteers, students, and employees who collaborate to make HashiCorp tools better. Community members play a variety of roles, including mentor, teacher, or connector. If you would like to contribute to HashiCorp products, review our community guidelines which can be found online here.

Issues and Questions

If you have any issues or questions using this pacakge, please raise a Gitub issue in this repository. Issues raised in the main Nomad repository will be redirected here.

Motivation

The OpenAPI specification is ideal if you are working in a greenfield scenario, and can write your specification first. This spec first approach is highly recommended and widely supported by many of the tool vendors and experts in the OpenAPI space.

Sadly, this approach leaves brownfield projects with an existing API that either predates the OpenAPI specification, or for whatever reason was built with a code first approach, to their own devices in terms of generating a specification from existing code. The code found in the generator directory is one such device. It is highly, experimental, and subject to change.

Contributing

The v1/openapi.yaml specification file is a generated file that should not be edited manually.

The README file in the generator directory contains a detailed technical overview as well as instructions on how to contribute.

Client and API packages are not officially supported packages

The client and api found in this repository are not officially supported packages. They exist here to be consumed by unit tests as a means of validating the specification produced by the generator package.

Owner
HashiCorp
Consistent workflows to provision, secure, connect, and run any infrastructure for any application.
HashiCorp
Comments
  • Acls api

    Acls api

    • added path templates for ACL Policies and ACL Tokens APIs
    • added 2 new in-path parameters in v1api.go:
    1. aclPolicyNameParam (added "acl" prefix to avoid potential conflicts with other policy names -- such as Sentinel)
    2. tokenAccessorParam
  • System api

    System api

    Issue: generator/system.go is supposed to use POST and not PUT, but Nomad's agent/system_endpoint.go only accepts PUT. As a result, the v1/system_test.go gets a 405 invalid method error which is absolutely valid.

    What I've tried: changing http.MethodPost to http.MethodPut, and make v1 builds successfully but then test will complain about v1/system.go's SystemApi

    How sure how to approach it at this point :(

  • Update for Nomad Variables

    Update for Nomad Variables

    Ready for review. I'll do a follow-up for Keyring once this has been merged so that I'm not reworking both with the same comments emerging from any misunderstanding I have of what I'm supposed to be doing here. ๐Ÿ˜€

    There's a few bits in the generator README that don't appear to be up-to-date, and I'm not sure if those are just not a problem anymore or if I'm got something silently failing:

    • The number of operations per path doesn't appear to be really capped at 3.
    • PUT being deprecated for POST isn't something that's happening in the v1 Nomad API as far as I've seen.
    • I'm not sure what a "test client" is but it doesn't seem to be referred to anywhere else in that doc other than at the end.

    Also, what's the expectations around the "higher level API" package here? I've done some spot checks and it doesn't actually look higher-level to me.

  • chore: Add new helper method to handle responses without `WriteMeta` or `QueryMeta`

    chore: Add new helper method to handle responses without `WriteMeta` or `QueryMeta`

    The Nomad OperatorAutopilotConfiguration handler supports PUT operations, and accepts WriteOpts parameters, but it does not set the index or any other WriteMeta values. OperatorServerHealth has the same issue but for GET.

    There aren't helpers in the api.go file yet that handle a responses with this shape. We need to add them so that the client WriteOpts or QueryOpts will be set. Currently, the workaround is to use ExecRequest which works for unit tests and simple scenarios, but silently ignore any WriteOpts or QueryOpts set by callers.

  • Add `nullable` property to arrays, objects and date-time strings

    Add `nullable` property to arrays, objects and date-time strings

    The Nomad API returns null values quite often for several fields. Without the nullable: true property OpenAPI clients will throw an error when trying to parse the response.

    Example from a Python script:

    nomad_client.exceptions.ApiTypeError: Invalid type for variable 'networks'. Required value type is list and passed type was NoneType at ['received_data'][0]['allocated_resources']['tasks']['redis']['networks']
    

    I set nullable: true to all array, object and date-time strings, but I didn't check if all these fields can actually be null.

    I think the impact of mistakenly setting a field as nullable is that the generated clients will use a different data type, so client consumers may need to check for null values even if the API never returns null.

    Since there's no official documentation on which fields can or cannot return a null maybe it's better to be safe? ๐Ÿ˜…

  • Operator api

    Operator api

    Hi @DerekStrickland ,

    I've been struggling with the Operator API a bit and will need you help in completing this.

    In generator/operator.go, the following are not implemented:

    • licenses
    • snapshots (get & restore), I'm just not sure how to handle the streaming output :|

    In v1/operator_tests.go, I have tests written for everything else, but also have a bunch commented out due to errors that I'm unsure of how to handle.

  • Handle TLS configuration correctly

    Handle TLS configuration correctly

    Currently, TLS is only configured if all of CA, client certificate and client key are provided. This also includes tlsSkipVerify, which makes it mostly useless as it is only respected if you also provide a CA and client cert.

    In addition, it's currently impossible to specify just the CA without setting a client certificate.

    We can fix this by setting only the configuration provided, which is also in line with how nomad behaves.

  • Missing nomad/v1/allocation/<id> endpoint

    Missing nomad/v1/allocation/ endpoint

    Hello,

    from what I can see there exists no such endpoint nomad/v1/allocation/<id> in the openapi spec.

    On my running instance (v1.2.3) I found the endpoint and it seems to return additional information.

    The only way to get my required information was to perform v1/allocations?resources=true&task_states=true which produces way more content than necessary and requires additional filtering on the allocation id of interest.

    Is there any chance that this endpoint will make it in the openapi spec?

    Thanks!

  • Status api

    Status api

    Hi @DerekStrickland !

    For the status-api, I find that the make tests fail consistently for TestGetStatusLeader and TestGetStatusPeers with the following:

    127.0.0.1:9732 2021-11-12T16:14:46.196-0500 [ERROR] http: request failed: method=GET path=/v1/status/leader error="No cluster leader" code=500
    127.0.0.1:9732 2021-11-12T16:14:46.197-0500 [DEBUG] http: request complete: method=GET path=/v1/status/leader duration=402.382ยตs
        status_test.go:16:
                    Error Trace:    status_test.go:16
                                                            api_test.go:33
                                                            status_test.go:11
                    Error:          Received unexpected error:
                                    500 Internal Server Error
                    Test:           TestGetStatusLeader
    127.0.0.1:9732 2021-11-12T16:14:46.197-0500 [DEBUG] http: shutting down http server
    

    But running the tests individually passes with no issue.

    GETs (using require.Contains to match only the IP and ':' as the port is a random high number port in the 9000's)

    • return value contains 127.0.0.1: for /v1/status/leader
    • returns list with 1 element for /v1/status/peers
    • returned list element value contains 127.0.0.1: for /v1/status/peers
  • question: Remove QueryOptions and WriteOptions embedded structs from models

    question: Remove QueryOptions and WriteOptions embedded structs from models

    ##Problem

    • Currently, the API exposes the RPC QueryOptions/WriteOptions on input/output structs returned from the primary Nomad API package.
    • This is confusing as a user because all of those options are also accepted as parameters (query or header).
    • It would be less confusing to users if the generated request/response models excluded those structs and could rely solely on the parameters.
    • Currently, the generated models have setters for the embedded struct fields, but the framework ignores them and instead consumes the passed parameters
    • Uninitiated contributors might easily make the mistake of bypassing the parameter parsing methodology if they rely on IntelliSense discovery rather than looking at existing implementations.
    • Inclusion of these embedded structs bloats the generated models, the payload size, and the generated YAML.
    • I'd like to remove these embedded structs from the request/response models, but I am unsure if it is safe to do so.
    • Generally, the handler code maps the input parameters to the RPC structs before making RPC calls, but not having been through all the handlers yet, I am unclear if this is always guaranteed.

    @schmichael @jrasell Can one of you weigh in on whether this will be safe to do, or point me in the direction of the best person to ask?

  • added ExecNoMetaQuery and ExecNoMetaWrite

    added ExecNoMetaQuery and ExecNoMetaWrite

    Updated the following to use the new helper functions:

    • v1/status.go
    • v1/operator.go

    I think this should be it, but opening it draft mode as I plan to do a quick review of the other endpoints to see if these new helpers fit there as well.

  • array and object nullable is not handled correctly, at least for python.

    array and object nullable is not handled correctly, at least for python.

    In the openapi spec, when the type is array, the generated python validation code will complain when the value is null, which the nomad restful API does return. For example, if I call:

        configuration = nomad_client.Configuration(host="http://127.0.01:4646/v1")
        api_client = nomad_client.ApiClient(configuration)
        api_instance = JobsApi(api_client)
        job_name = HELLO_WORLD_JOB_NAME
        job_status = api_instance.get_job(job_name)
        print(job_status)
    

    the get_job call should return a job, but a number of fields such as constraints are returned null, but it is defined as array type in the openapi spec. The same with object type. The openapi solution seems to be adding nullable: true to these fields, but there are a lot of them. Not sure what is the best solution to automatically fix this.

  • Python pip install `git+https://github.com/.../python/v1.git` not working

    Python pip install `git+https://github.com/.../python/v1.git` not working

    Hi,

    maybe I'm overlooking something but the pip install as mentioned in the readme doesn't work me

    ~/temp/foo via ๐Ÿ v3.9.12 (foovenv)
    โฏ pip install git+https://github.com/hashicorp/nomad-openapi/clients/python/v1.git
    Collecting git+https://github.com/hashicorp/nomad-openapi/clients/python/v1.git
      Cloning https://github.com/hashicorp/nomad-openapi/clients/python/v1.git to /private/var/folders/zt/4d___54j41q5xhgw80pcmtyh0000gn/T/pip-req-build-clmb4zx8
      Running command git clone --filter=blob:none --quiet https://github.com/hashicorp/nomad-openapi/clients/python/v1.git /private/var/folders/zt/4d___54j41q5xhgw80pcmtyh0000gn/T/pip-req-build-clmb4zx8
      remote: Not Found
      fatal: Repository 'https://github.com/hashicorp/nomad-openapi/clients/python/v1.git/' not found
      error: subprocess-exited-with-error
    
      ร— git clone --filter=blob:none --quiet https://github.com/hashicorp/nomad-openapi/clients/python/v1.git /private/var/folders/zt/4d___54j41q5xhgw80pcmtyh0000gn/T/pip-req-build-clmb4zx8 did not run successfully.
      โ”‚ exit code: 128
      โ•ฐโ”€> See above for output.
    

    Any suggestions?

Khan - An interactive CLI management tool for Nomad

Khan An interactive CLI management tool for Hashicorp's Nomad Why Nomad has a gr

Apr 26, 2022
Fast and light-weight API proxy firewall for request and response validation by OpenAPI specs.
Fast and light-weight API proxy firewall for request and response validation by OpenAPI specs.

Open Source API Firewall API Firewall is a high-performance proxy with API request and response validation based on OpenAPI/Swagger schema. It is desi

Jan 8, 2023
Create a new OpenAPI based blink-plugin

OpenAPI plugin template Create a new OpenAPI based blink-plugin. READ FIRST Getting the Repo Option 1: From Github Press Use this template Naming conv

Oct 14, 2021
A fully-featured OpenAPI generated HubSpot client for Go
A fully-featured OpenAPI generated HubSpot client for Go

This is a HubSpot Go client generated using openapi-generator. It includes packages for every OpenAPI spec listed in HubSpot's API directory. Installi

Dec 31, 2022
OpenAPI for Todolist RESTful API

Go API client for swagger OpenAPI for Todolist RESTful API Overview This API cli

Dec 18, 2021
An experimental OpenAPI -> Terraform Provider generator that does not yet function

tfpgen An experimental OpenAPI -> Terraform Provider generator that does not yet function. The goal is to allow developers to incrementally generate a

Feb 19, 2022
vault-init is a small utility for automating the initialization and unsealing of HashiCorp Vault.

vault-init vault-init is a small utility for automating the initialization and unsealing of HashiCorp Vault. It draws inspiration from kelseyhightower

Aug 17, 2022
Service that wrap up different movies-related APIs like IMDB and match it to streaming services
Service that wrap up different movies-related APIs like IMDB and match it to streaming services

Service that wrap up different movies-related APIs like IMDB and match it to streaming services. That way you can check in which platforms you can find your favorite movies.

Feb 10, 2022
Feb 7, 2022
Lol-champions-api - A REST API app for CRUD' ing informations related to League of Legends champions, written with Go

LOL-CHAMPIONS-API Just a REST API app for CRUD' ing informations related to Leag

Mar 17, 2022
A GitHub CLI extension that displays collaboration-related information about a GitHub repository.
A GitHub CLI extension that displays collaboration-related information about a GitHub repository.

collab-scanner GitHub CLI extension A GitHub CLI extension that displays collaboration-related information on a repository. Install gh extension insta

Dec 30, 2022
Serverless SOAR (Security Orchestration, Automation and Response) framework for automatic inspection and evaluation of security alert
Serverless SOAR (Security Orchestration, Automation and Response) framework for automatic inspection and evaluation of security alert

DeepAlert DeepAlert is a serverless framework for automatic response of security alert. Overview DeepAlert receives a security alert that is event of

Jan 3, 2023
Use AWS SQS as a clipboard to copy and paste across different systems and platforms

sqs_clipboard Use AWS SQS as a clipboard to copy and paste across different systems and platforms. Clipboard contents are encrypted in transit and at

Oct 16, 2022
A API scanner written in GOLANG to scan files recursively and look for API keys and IDs.

GO FIND APIS _____ ____ ______ _____ _ _ _____ _____ _____ _____ / ____|/ __ \ | ____|_ _| \ | | __ \ /\ | __ \_

Oct 25, 2021
A simple Go utility to display track information from, and send commands to, spotifyd from Tiling Window Managers like Sway and i3
A simple Go utility to display track information from, and send commands to, spotifyd from Tiling Window Managers like Sway and i3

Untitled Spotifyd Controller A simple Go utility to display track information from, and send commands to, spotifyd from Tiling Window Managers like Sw

Mar 8, 2022
planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport.

planet planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport. Get started starport chain serve serve command install

Oct 31, 2021
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

Dec 20, 2022
Todo-list - In this project using golang and mySql to create todo-list to Add and remove
Todo-list - In this project using golang and mySql to create todo-list to Add and remove

TODO-Fullstack-App-Go-Gin-Postgres-React This fullstack application creates a TODO List Web Page using the Go/Gin/Postgres/React Stack. Starting the a

Apr 7, 2022
Rest API to get KVB departures - Written in Go with hexagonal architecture and tracing via OpenTelemetry and Jaeger

KVB API Rest API to get upcoming departures per KVB train station Implemented in Go with hexagonal architecture and tracing via OpenTelemetry and Jaeg

May 7, 2022