Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new config format and parser #485

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 10 additions & 129 deletions docs/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ This function must return an object with the following shape:
export default async function () {
return {
glee: {},
kafka: {},
websocket: {},
mqtt: {},
cluster: {},
http: {}
docs: {},
server: {},
cluster: {}
}
}
Comment on lines 18 to 25
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the old format for glee-config and it was done to configure WebSocket servers for socket-io or pass in a custom server object. So building on that I am trying to add a new object named server where we would pass in the custom server config. The parser would take a server name from the spec and see if any config exists in the config file and then load that accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, the only thing that worries me a little about this approach is writing an interface for it. I mean we want type suggestion/safety on the file right? with server name as a key I am not sure how we can write protocol specific interfaces. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can still achieve that, I am not sure but I used notion API which had something like this kind of type

interface T {
  server: {
    [name:string]: {
      httpAdapter: any,
      adapter: string,
      port: number
    }
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KhudaDad414 can I move ahead with this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, If type can be checked then let's do this. 👍


Expand All @@ -41,53 +39,18 @@ export default async function () {
enabled: true, // Enable/Disable documentation generation
folder: 'docs', // Folder where you want the output of your docs to reside.
template: '@asyncapi/markdown-template' // Type of template you want to use.
}
ws: {
server: {
},
server: {
'websocket': { // name of the server
httpServer: customServer, // A custom HTTP server of your own.
adapter: "native", // Default. Can also be 'socket.io' or a reference to a custom adapter.
adapter: 'native', // Default. Can also be 'socket.io' or a reference to a custom adapter.
port: process.env.PORT,
},
client: {
auth: {
token: process.env.TOKEN
}
}
},
cluster: {
adapter: "redis",
name: "cluster", // Default. Name of your cluster.
url: "redis://localhost:6379", // Server URL used by adapter for clustering
},
mqtt: {
auth: ({serverName, parsedAsyncAPI}) => {
if (serverName === 'mqtt') {
return {
cert: async () => fs.readFileSync('./cert')
clientId: '123',
username: 'user1'
password: 'pass12'
}
}
}
},
http: {
server: {
httpServer: customServer, // A custom HTTP server of your own.
adapter: 'native',
port: process.env.PORT,
},
client: {
auth: {
token: process.env.TOKEN
},
query: {
foo: 'bar'
},
body: {
foo: 'bar'
}
}
adapter: 'redis',
name: 'cluster', // Default. Name of your cluster.
url: 'redis://localhost:6379', // Server URL used by adapter for clustering
}
};
}
Expand All @@ -113,85 +76,3 @@ These configurations apply to Glee itself, rather than any specific protocol.
|docs.enabled|This flag enables/disables the docs generation functionality.
|docs.folder|The dedicated folder you want your generated docs to reside.
|docs.template|The AsyncAPI template you wanna use for generating your documentation.

### Websocket Server

|Field|Description|
|--|--|
|ws.server|Websocket server-specific configurations|
|ws.client|Websocket client-specific configurations|
|ws.server.adapter| The Glee adapter to use for the WebSocket server. Defaults to a "native" WebSocket implementation. Other allowed values are `socket.io` (to use the [Socket.IO](https://socket.io/) Glee adapter) or a reference to a custom adapter.|
|ws.server.httpServer| A custom HTTP server of your own. E.g., an [Express](https://expressjs.com/en/4x/api.html) server or any object that implements the [http.Server](https://nodejs.org/api/http.html#http_class_http_server) interface. |
|ws.server.port| The port to use when binding the WebSocket server. This is useful when your server is behind a proxy and the port exposed for consumption is not the same as the port your application should be bound to. Defaults to the port specified in the selected AsyncAPI server.|
|ws.client.auth| Authentication variables for client|
|ws.client.auth.token| HTTP Authentication header|

### Cluster

|Field|Description|
|--|--|
|cluster.adapter| The Glee cluster adapter to use for communication between instances. Defaults to Redis Pub/Sub ("redis"). Can be a reference to a custom adapter.|
|cluster.name|The name of the cluster. Defaults to "cluster".|
|cluster.url|The url of the server to be used by the adapter. In case of "redis" adapter, it's the url of the Redis server.|

### MQTT

|Field|Description|
|---|---|
|mqtt.auth| MQTT authentication configuration|
|mqtt.auth.cert| Client certificate
|mqtt.auth.clientId| MQTT client Id for authentication
|mqtt.auth.username| username parameter
|mqtt.auth.password| password parameter

### Kafka

|Field|Description|
|---|---|
|kafka.auth| Kafka authentication configuration|
|kafka.auth.key | Kafka Broker Key
|kafka.auth.cert| Client certificate
|kafka.auth.clientId| Kafka client Id for authentication
|kafka.auth.rejectUnauthorized | Boolean flag for accepting the valid SSL certificates
|kafka.auth.username| The username to use during authentication.
|kafka.auth.password| The password to use during authentication.

### HTTP Server

|Field|Description|
|--|--|
|http.server|HTTP server-specific configurations|
|http.client|HTTP client-specific configurations|
|http.server.adapter| The Glee adapter to use for the HTTP server. Defaults to a "native" HTTP implementation.|
|websocket.server.port| The port to use when binding the HTTP server. This is useful when your server is behind a proxy and the port exposed for consumption is not the same as the port your application should be bound to. Defaults to the port specified in the selected AsyncAPI server.|
|http.client.auth| Authentication/Authorization configuration for the client|
|http.client.auth.token| HTTP Authentication header|
|http.client.query| Query object for the client to send|
|http.client.body| Body object for the client to send


### Auth Config

Most clients like `ws`,`kafka`, and `mqtt` have auth fields that are used for passing auth parameters. All these configurations can be an object or a function that returns the specific object defined by each protocol.


```js
export default async function() {
ws: {
client: {
auth: {
token: process.env.TOKEN
}
}
},
mqtt: {
auth: ({serverName, parsedAsyncAPI}) => {
if (serverName === 'mqtt') {
return {
cert: fs.readFileSync('./cert', 'utf-8')
}
}
}
}
}
```
Loading