Skip to content

Commit

Permalink
Add support for registry authentication (#83)
Browse files Browse the repository at this point in the history
* Add support for registry authenticatiohn

* Update changelog

* Add link to Axios Request Config
  • Loading branch information
johnbenz13 authored and ricardohbin committed Jan 14, 2020
1 parent e3a6751 commit d62b7d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ When instantiating kafka-avro you may pass the following options:

* `kafkaBroker` **String REQUIRED** The url or comma delimited strings pointing to your kafka brokers.
* `schemaRegistry` **String REQUIRED** The url to the Schema Registry.
* `schemaRegistryAuth` **Object** Basic auth object to connect to confluent cloud registry `{username: API_KEY, password: API_SECRET}`. Same as Axios basic auth [Request Config](https://github.com/axios/axios#request-config) parameter.
* `topics` **Array of Strings** You may optionally define specific topics to be fetched by kafka-avro vs fetching schemas for all the topics which is the default behavior.
* `fetchAllVersions` **Boolean** Set to true to fetch all versions for each topic, use it when updating of schemas is often in your environment.
* `fetchRefreshRate` **Number** The pooling time (in seconds) to the schemas be fetched and updated in background. This is useful to keep with schemas changes in production. The default value is `0` seconds (disabled).
Expand Down Expand Up @@ -300,6 +301,8 @@ You can use `docker-compose up` to up all the stack before you call your integra
* `grunt release:major` for major number jump.

## Release History
- **3.0.2**, *14 Jan 2020*
- Adds support for basic authentication to schema registry, using Axios auth Request Config parameter, feature by [Bookaway](github.com/Bookaway).
- **3.0.1**, *13 Jan 2020*
- Fix a bug to custom strategies `keySubjectStrategy` and `valueSubjectStrategy` - they were not working as expected. The default behavior was not impacted.
- Little error logs improvements
Expand Down
1 change: 1 addition & 0 deletions lib/kafka-avro.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const KafkaAvro = module.exports = CeventEmitter.extend(function (opts) {

const srOpts = {
schemaRegistryUrl: opts.schemaRegistry,
auth: opts.schemaRegistryAuth || null,
selectedTopics: opts.topics || null,
fetchAllVersions: opts.fetchAllVersions || false,
fetchRefreshRate: opts.fetchRefreshRate || 0,
Expand Down
14 changes: 12 additions & 2 deletions lib/schema-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ const log = rootLog.getChild(__filename);
* @constructor
*/
const SchemaRegistry = module.exports = cip.extend(function (opts) {
if (opts.httpsAgent) {
instance = axios.create({httpsAgent: opts.httpsAgent});
if (opts.httpsAgent || opts.auth) {
const defaultOptions = {};

if (opts.httpsAgent) {
defaultOptions.httpsAgent = opts.httpsAgent;
}

if (opts.auth) {
defaultOptions.auth = opts.auth;
}

instance = axios.create(defaultOptions);
}

/** @type {Object} The SR URL object */
Expand Down

0 comments on commit d62b7d8

Please sign in to comment.