deprecator

package module
v0.0.0-...-20fa161 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 8 Imported by: 0

README

Deprecator

KrakenD middleware for deprecating endpoints.

Installation

Load the middleware as part of the KrakenD handler factory chain:

handlerFactory = deprecator.HandlerFactory(handlerFactory)

Quick Start

With the following extra_config, KrakenD will reject requests to the /user/v1 endpoint starting at 08:00 on 2022-04-10 (see deprecate date). For rejected requests, status, body and headers are set as specified in the response config.

Deprecation and Sunset headers are set for all responses, both for rejected and accepted requests, and irrespective of the time and date of the request. The sunset date should be set to the officially communicated deprecation date; the heads_up configuration can be used to specify time windows during which the endpoint will reject all requests prior to its actual deprecation.

"endpoints": [
  {
    "endpoint": "/user/v1",
    "output_encoding": "no-op",
    "backend": [{
      "host": [ "http://localhost:8080" ],
      "url_pattern": "/__health",
      "encoding": "no-op"
    }],
    "extra_config": {
      "moritzploss/deprecator": {
        "sunset": "2022-04-07T08:00:00+00:00",
        "deprecate": "2022-04-10T08:00:00+00:00",
        "heads_up": {
          "duration": "30m",
          "dates": [
            "2022-04-07T08:00:00+00:00",
            "2022-04-08T08:00:00+00:00",
            "2022-04-09T08:00:00+00:00"
          ]
        },
        "response": {
          "headers": { "Link": "https://myapi.com/api/spec" },
          "body": { "error": "endpoint /user/v1 is deprecated" },
          "status": 410
        }
      }
    }
  }
]

Documentation

Index

Constants

View Source
const Namespace = "moritzploss/deprecator"

Variables

This section is empty.

Functions

func HeadsUpFactory

func HeadsUpFactory(cfg *Config) func(t time.Time) bool

Types

type Config

type Config struct {
	Sunset    time.Time `json:"sunset"`
	Deprecate time.Time `json:"deprecate"`
	HeadsUp   HeadsUp   `json:"heads_up"`
	Response  Response  `json:"response"`
}

func ConfigGetter

func ConfigGetter(e config.ExtraConfig) (*Config, bool)

type Duration

type Duration struct {
	time.Duration
}

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type HeadsUp

type HeadsUp struct {
	Duration Duration    `json:"duration"`
	Dates    []time.Time `json:"dates"`
}

type Rejector

type Rejector func(c *gin.Context) bool

func RejectorFactory

func RejectorFactory(cfg *Config) Rejector

type Response

type Response struct {
	Status  int                    `json:"status"`
	Body    map[string]interface{} `json:"body"`
	Headers map[string]string      `json:"headers"`
}

Jump to

Keyboard shortcuts

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