sr

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

README

sr · CircleCI Status GitHub license PRs Welcome

sr - simple library and CLI wrapper around confluent schema registry api

$ export SCHEMA_REGISTRY_URL=http://example.com
$ sr ls
["foo"]
$ sr add bar ~/Desktop/mt_event.json
{id:"998"}
$ sr ls
["foo", "bar"]
$ sr ls bar
[1]
$ sr ls bar 1
...schema that was added and version and name...
func main() {
   id, err := sr.Register(http.DefaultClient, "http://example.com", sr.Subject("foo"), sr.Schema(`{"type":"long"}`))
}

Documentation

Index

Constants

View Source
const (
	//Zero is a zero value for compatibility and is not returned by the schema registry
	Zero = Compatibility("")

	//None means no compatibility between schemas is expected
	None = Compatibility("NONE")

	//Full means both Forward and Backward compatibility is expected
	Full = Compatibility("FULL")

	//Forward compatibility means all previous schemas can read the compatible schema
	Forward = Compatibility("FORWARD")

	//Backward compatibility means the compatible schema can read all previous schemas
	Backward = Compatibility("BACKWARD")
)
View Source
const (
	//TestURLEnvVar is the url to run functional tests against
	TestURLEnvVar = "SR_TEST_SCHEMA_REGISTRY"
	//TestRequiredEnvVar if set to true will make tests fail
	TestRequiredEnvVar = "SR_TEST_REQUIRED"
)
View Source
const EmptySubject = Subject("")

EmptySubject is just a place holder for the empty string.

Variables

View Source
var EmptySchema = Schema("")

EmptySchema is the 'zero' value for a Schema

Functions

func CheckIsCompatibleRequest

func CheckIsCompatibleRequest(baseURL string, subject Subject, version string, body *SchemaJSON) (*http.Request, error)

CheckIsCompatibleRequest returns the http.Request for the POST /compatibility/subjects/<subject>/versions/<version> route

func GetConfigRequest

func GetConfigRequest(baseURL string) (*http.Request, error)

GetConfigRequest returns the http.Request for the GET /config route

func GetFunctionalTestURL

func GetFunctionalTestURL(t *testing.T) string

GetFunctionalTestURL skips, fails, or returns the config variable passed in

func GetSchemaRequest

func GetSchemaRequest(baseURL string, id uint32) (*http.Request, error)

GetSchemaRequest returns the http.Request for GET /schemas/ids/<id> route

func GetSubjectConfigRequest

func GetSubjectConfigRequest(baseURL string, subject Subject) (*http.Request, error)

GetSubjectConfigRequest returns the http.Request for the GET /config route

func GetVersionRequest

func GetVersionRequest(baseURL string, subject Subject, version string) (*http.Request, error)

GetVersionRequest returns the http.Request for the GET /subjects/<subject>/versions/<version> version can either be a number or 'latest'

func HandleFunctionalTestError

func HandleFunctionalTestError(t testing.TB, err error)

HandleFunctionalTestError will skip or fail based on whether SR_TEST_REQUIRED is set

func HasSchema

func HasSchema(client HTTPClient, url string, subject Subject, schema Schema) (version int, id int, err error)

HasSchema returns the version and id for a schema on a subject

func HasSchemaRequest

func HasSchemaRequest(baseURL string, subject Subject, body *SchemaJSON) (*http.Request, error)

HasSchemaRequest returns the http.Request for the POST /subjects/<subject>

func IsCompatible

func IsCompatible(client HTTPClient, url string, subject Subject, version string, schema Schema) (is bool, err error)

IsCompatible will return if the provided schema is compatible with the subject and version provided. Version can either be a numeric version or 'latest'

func IsFunctionalTestRequired

func IsFunctionalTestRequired() bool

IsFunctionalTestRequired returns whether SR_TEST_REQUIRED is set

func ListSubjectsRequest

func ListSubjectsRequest(baseURL string) (*http.Request, error)

ListSubjectsRequest returns the GET /subjects

func ListVersions

func ListVersions(client HTTPClient, url string, subject Subject) (versions []int, err error)

ListVersions returns the list of versions for a subject

func ListVersionsRequest

func ListVersionsRequest(baseURL string, subject Subject) (*http.Request, error)

ListVersionsRequest returns GET /subjects/<subject>/versions

func PutSubjectConfigRequest

func PutSubjectConfigRequest(baseURL string, subject Subject, body *ConfigPutJSON) (*http.Request, error)

PutSubjectConfigRequest returns the http.Request for the Put /config/<subject> route

func Register

func Register(client HTTPClient, url string, subject Subject, schema Schema) (id uint32, err error)

Register adds a schema to a subject and returns the new id

func RegisterRequest

func RegisterRequest(baseURL string, subject Subject, body *SchemaJSON) (*http.Request, error)

RegisterRequest returns the http.Request for the POST /subjects/<subject>/versions

Types

type Compatibility

type Compatibility string

Compatibility is the compatibility level from the schema registry. See schema registry documentation for more details

func GetDefaultCompatibility

func GetDefaultCompatibility(client HTTPClient, url string) (compatibility Compatibility, err error)

GetDefaultCompatibility returns the compatibility level set at the server level

func GetSubjectCompatibility

func GetSubjectCompatibility(client HTTPClient, url string, subject Subject) (compatibility Compatibility, err error)

GetSubjectCompatibility returns the compatibility level for a subject

func GetSubjectDerivedCompatibility

func GetSubjectDerivedCompatibility(client HTTPClient, url string, subject Subject) (compatibility Compatibility, err error)

GetSubjectDerivedCompatibility returns the compatibility level for a subject or the default if a subject specific doesnt exist

func SetSubjectCompatibility

func SetSubjectCompatibility(client HTTPClient, url string, subject Subject, compatibility Compatibility) (result Compatibility, err error)

SetSubjectCompatibility sets the compatibility level for a subject

type ConfigGetJSON

type ConfigGetJSON struct {
	Compatibility string `json:"compatibilityLevel"`
}

ConfigGetJSON is what the schema registry returns on config get endpoints

type ConfigPutJSON

type ConfigPutJSON struct {
	Compatibility string `json:"compatibility"`
}

ConfigPutJSON is what the schema registry expects on config put endpoints

type HTTPClient

type HTTPClient interface {
	Do(request *http.Request) (*http.Response, error)
}

HTTPClient is any client that can do a http request

type Schema

type Schema string

Schema is a string that represents a avro schema

func GetLatestSchema

func GetLatestSchema(client HTTPClient, url string, subject Subject) (id uint32, schema Schema, err error)

GetLatestSchema returns the latest schema and id for a subject

func GetSchema

func GetSchema(client HTTPClient, url string, id uint32) (schema Schema, err error)

GetSchema returns a schema for an id

func GetVersion

func GetVersion(client HTTPClient, url string, subject Subject, version string) (id uint32, schema Schema, err error)

GetVersion returns a schema and id for a subject and version

func TestSchema

func TestSchema(unique int64) Schema

TestSchema returns a schema with the unique part added to the name

func UniqueSchema

func UniqueSchema() Schema

UniqueSchema returns a schema with a unique name

type SchemaJSON

type SchemaJSON struct {
	Schema Schema `json:"schema"`
}

SchemaJSON is what the schema registry expects when sending it a schema

type Subject

type Subject string

Subject is *not* a topic. Subject is a schema registry abstraction, topic is a kafka one. For instance the kafka rest proxy assumes that for topic "foo" there can be 2 subjects foo-key and foo-value. foo-key will store the schema for the key field (if any) and foo-value will store the schema for the value field

func KeySubject

func KeySubject(topic string) Subject

KeySubject takes a topic name and turns it into what kafka-rest assumes is the name for value schemas

func ListSubjects

func ListSubjects(client HTTPClient, url string) (subjects []Subject, err error)

ListSubjects returns the list of subjects

func UniqueSubject

func UniqueSubject() Subject

UniqueSubject returns a subject with a unique name

func ValueSubject

func ValueSubject(topic string) Subject

ValueSubject takes a topic name and turns it into what kafka-rest assumes is the name for value schemas

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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