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][GRAFX-3332] Introduce "set-auth" CLI command #38

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 17 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# Connector Contrib
# Connector Framework

This repository is a placeholder for the soon-to-be connector repository.
Repository represents a monorepo with `connector-cli` and marketplace `connectors`

The idea is that we will host opensourced connectors in this repo and provide
all tools and cicd to automate as much as possible in the process of publishing a new connector.
## Connector-cli

## root package.json
In `src/connector-cli` we created a CLI tool that is able to run a connector in a standalone mode. This isolated runtime simplifies the development lifecycle. It offers a suite of commands to initialize projects, build and test code, and deploy your connectors with ease.

Inspect the root package.json to see how to build / setup
See the [readme](src/connector-cli/readme.md) of the package for more info.

## connector-cli
## Connectors

In `src/connector-cli` we created a cli tool that is able to run a connector in standalone mode. This isolated runtime gives us the opportunity to run tests, while mocking network requests, etc.
In `src/connectors` we collect all `marketplace` connectors that we or our partners implemented

See the readme in the connector-cli folder for more info.

### Updating / adding a connector:
## Development setup

```sh
yarn # to install dependencies
yarn run build-cli # to build local version of the CLI
```

NOTE: Inspect root package.json for more commands to run

## Updating / adding a connector:

- Open PR

Expand Down
1,963 changes: 0 additions & 1,963 deletions src/connector-cli/debugger/yarn.lock

This file was deleted.

8 changes: 6 additions & 2 deletions src/connector-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
"@types/handlebars": "^4.1.0",
"@types/node": "^20.8.6",
"@types/dot-object": "^2.1.6",
"@types/js-yaml": "^4.0.9",
"copyfiles": "2.4.1",
"js-yaml": "^4.1.0",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"rimraf": "^5.0.5"
"rimraf": "^5.0.5",
"quicktype": "23.0.0"
},
"scripts": {
"build": "rimraf ./out && yarn run tsc && yarn --cwd ./debugger build && copyfiles -Vf ./debugger/dist/assets/* ./out/",
"debugger": "yarn run ts-node src/index.ts login && yarn run ts-node src/index.ts publish ../connectors/acquia/connector.ts",
"update": "yarn build && npm version patch && yarn pack",
"demo": "yarn run ts-node src/index.ts demo '../connectors/acquia/connector.ts'"
"demo": "yarn run ts-node src/index.ts demo '../connectors/acquia/connector.ts'",
"produce-types": "quicktype -s schema ./resources/schemas/**/*.json ./resources/schemas/*.json -o src/core/types/gen-types.ts"
}
}
51 changes: 34 additions & 17 deletions src/connector-cli/readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# @chili-publish/connector-cli

`@chili-publish/connector-cli` is a command-line interface tool designed to facilitate the management of connector test and publish processes in the CHILI publisher ecosystem. It provides a suite of commands to initialize projects, build connectors, debug, test, and publish them to the marketplace.
`@chili-publish/connector-cli` is a command-line interface tool designed to facilitate the management of connector test and publish processes in the CHILI publisher ecosystem. It provides a suite of commands to initialize projects, build connectors, debug, test, deploy and publish them to the marketplace.

## Features

### Main

- **Initialize**: Scaffold a new connector with `init`.
- **Publish**: Publish your connector to the marketplace with `publish`.
- **Publish**: Deploy your connector to the specified environment with `publish`.
- **Set Auth**: Configure your connector authentication with `set-auth`.
- **Build**: Build your connector from TypeScript to JavaScript with `build`.
- **Debug**: Run a local debug server for your connector with `debug`.
- **Info**: Retrieve information about your connector with `info`.
- **Test**: Run a test suite against your connector with `test`.
- **Stress Test**: Perform stress tests on your compiled connector with `stress`.

### Informational

- **Info**: Retrieve runtime information about your connector with `info`.
- **List options**: Retrieve information about particular connector config with `list-options`.

## Installation

You can install `@chili-publish/connector-cli` globally via npm:
Expand Down Expand Up @@ -42,12 +49,24 @@ connector-cli init --name YourConnectorName
connector-cli build --outFolder ./dist
```

### Publish a connector
### Login to the system

```sh
connector-cli login
```

### Deploy a connector to environment

```sh
connector-cli publish pathToTsFile --baseUrl EnvironmentAPIBaseURL --environment YOUR_ENVIRONMENT --name YourConnectorName
```

### Configure a connector authentication

```sh
connector-cli set-auth pathToConnectorDir --baseUrl EnvironmentAPIBaseURL --environment YOUR_ENVIRONMENT --connectorId ConnectorIdFromEnv --usage browser --type staticKey --auth-data-file ./pathToAuthData
```

### Debug a connector

```sh
Expand Down Expand Up @@ -76,38 +95,36 @@ connector-cli stress --iterations 100

To build `@chili-publish/connector-cli` from source, follow these steps:

### Prerequisites

Ensure that you have [Yarn v1.22.19](https://classic.yarnpkg.com/lang/en/docs/install/) is installed

> yarn -v # to check existing yarn version

1. Clone the repository:

```sh
git clone https://github.com/chili-publish/studio-connector-contrib.git
git clone https://github.com/chili-publish/studio-connector-framework.git
cd connector-cli
```

2. Install dependencies:

```sh
npm install
```

Or if you are using Yarn:

```sh
yarn install
```

3. Run the build script:

```sh
npm run build
yarn run build-cli
```

Or with Yarn:
This will compile TypeScript files to JavaScript and prepare the CLI for use.

```sh
yarn build
```
## Auto generated types

This will compile TypeScript files to JavaScript and prepare the CLI for use.
The package includes types located in `src/core/gen-types.ts` file that automaticaly produced by [quicktype](https://github.com/glideapps/quicktype) library. You shouldn't manually change this typescript file. If you want to make a change you need to update a corresponding `json-schema` file under `resources/schemas/...` directory and execute `yarn workspace @chili-publish/connector-cli run produce-types` from the root level of monorepo

## Contributing

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"$defs": {
"AuthorizatoinServerMetadata": {
"type": "object",
"properties": {
"authorization_endpoint": {
"type": "string"
},
"token_endpoint": {
"type": "string"
},
"token_endpoint_auth_methods_supported": {
"type": "array",
"items": {
"type": "string",
"enum": ["client_secret_basic", "client_secret_post"]
}
}
},
"required": [
"authorization_endpoint",
"token_endpoint",
"token_endpoint_auth_methods_supported"
],
"additionalProperties": false
},
"SpecCustomization": {
"type": "object",
"properties": {
"requestContentType": {
"type": "string",
"enum": ["applicationJson", "formUrlEncoded"]
},
"codeParameterName": {
"type": "string"
}
},
"additionalProperties": false
}
},
"type": "object",
"properties": {
"name": {
"type": "string"
},
"clientId": {
"type": "string"
},
"clientSecret": {
"type": "string"
},
"scope": {
"type": "string"
},
"authorizationServerMetadata": {
"$ref": "#/$defs/AuthorizatoinServerMetadata"
},
"specCustomization": {
"$ref": "#/$defs/SpecCustomization"
}
},
"required": [
"name",
"clientId",
"clientSecret",
"authorizationServerMetadata"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"clientId": {
"type": "string"
},
"clientSecret": {
"type": "string"
},
"scope": {
"type": "string"
},
"tokenEndpoint": {
"type": "string"
}
},
"required": ["name", "clientId", "clientSecret", "tokenEndpoint"],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json-schema.org/draft-07/schema",

"type": "object",
"properties": {
"name": {
"type": "string"
},
"clientId": {
"type": "string"
},
"clientSecret": {
"type": "string"
},
"scope": {
"type": "string"
},
"tokenEndpoint": {
"type": "string"
},
"username": {
"type": "string"
},
"password": {
"type": "string"
},
"bodyFormat": {
"type": "string",
"enum": ["applicationJson", "formUrlEncoded"]
}
},
"required": [
"name",
"clientId",
"clientSecret",
"tokenEndpoint",
"username",
"password"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"key": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": ["name", "key", "value"],
"additionalProperties": false
}
34 changes: 34 additions & 0 deletions src/connector-cli/resources/schemas/connector-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["media"]
},
"iconUrl": {
"type": "string"
},
"options": {
"type": "object"
},
"supportedAuth": {
"type": "array",
"items": {
"type": "string",
"enum": [
"chili",
"staticKey",
"oAuth2ClientCredentials",
"oAuth2ResourceOwnerPassword",
"oAuth2AuthorizationCode"
]
}
},
"mappings": {
"type": "object"
}
},
"additionalProperties": false,
"required": ["type", "options"]
}
2 changes: 1 addition & 1 deletion src/connector-cli/src/authentication/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { errorNoColor, info, verbose, warn } from '../logger';
import { errorNoColor, info, verbose, warn } from '../core';
import { SessionStorage } from './session-storage';

type AuthConfig = {
Expand Down
1 change: 1 addition & 0 deletions src/connector-cli/src/authentication/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './authentication';
export * from './factories';
export { RegisteredAccessToken } from './session-storage';
4 changes: 2 additions & 2 deletions src/connector-cli/src/authentication/session-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocalStorage } from '../localstorage';
import { LocalStorage } from './localstorage';
import { AccessToken } from './authentication';

export type RegisteredAccessToken = {
Expand All @@ -14,7 +14,7 @@ export class SessionStorage {
get accessToken(): RegisteredAccessToken | null {
return JSON.parse(this.storage.getItem(this.sessionKey));
}
set accessToken(value: RegisteredAccessToken) {
set accessToken(value: RegisteredAccessToken | null) {
this.storage.setItem(this.sessionKey, JSON.stringify(value));
}
}
Loading
Loading