Skip to content
Merged
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
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,43 @@ Main features:
2. Add .env-cmdrc file into the project directory (use '.env-cmdrc-template')
3. Replace values such as secret keys and URLs

### Auth Providers

Switcher API supports multiple auth providers such as email/password-based authentication or GitHub, Bitbucket OAuth.

Follow the steps below to set up your OAuth App in GitHub and Bitbucket.

#### GitHub OAuth App setup

1. Open your GitHub account or organization settings
2. Go to Developer settings > OAuth Apps
3. Click on "New OAuth App"
4. Fill in the application details:
- Application name: Switcher API
- Homepage URL: https://switcher-management-url (or your deployed URL)
- Authorization callback URL: https://switcher-management-url/login?platform=github
5. Click on "Register application"
6. Copy the Client ID and Client Secret
7. Update your .env-cmdrc file or ConfigMap/Secret in Kubernetes with the following variables:
- GIT_OAUTH_CLIENT_ID=your_client_id
- GIT_OAUTH_CLIENT_SECRET=your_client_secret
8. Update Switcher Management GITHUB_CLIENTID environment variable with your_client_id

#### Bitbucket OAuth App setup

1. Open your Bitbucket account or workspace settings
2. Go to Apps and features > OAuth consumers
3. Fill in the application details:
- Name: Switcher API
- Callback URL: https://switcher-management-url/login?platform=bitbucket
4. Add permissions -> Account: Read
5. Click on "Save"
6. Copy the Key and Secret
7. Update your .env-cmdrc file or ConfigMap/Secret in Kubernetes with the following variables:
- BIT_OAUTH_CLIENT_ID=your_client_id
- BIT_OAUTH_CLIENT_SECRET=your_client_secret
8. Update Switcher Management BITBUCKET_CLIENTID environment variable with your_client_id

### Running Switcher API from Docker Composer manifest file

This option leverages Switcher API and Switcher Management with minimum settings required.
Expand Down Expand Up @@ -85,8 +122,8 @@ It is equivalent to an organization that can manage multiple projects, users, an
- **New domain** - Domain: /domain/create [POST]

### Component
Components are applications that are using Switcher API.<br>
Each component has its own access token and needs to be linked to Switchers.
Components are applications that will use Switcher API.<br>
Each component has its own access API key to interact with Switcher API.

- **Create a component** - Component: /component/create [POST]
- **Generating a new API Key** - Component: /component/generateApiKey [GET]
Expand All @@ -97,11 +134,11 @@ Groups are used to organize Switchers that share the same feature scope.
- **New Group** - GroupConfig: /groupconfig/create [POST]

### Switcher
Switchers are the main entities to control features.
Switchers are the entry point to control features in your application.<br>

- **New Switcher** - Config: /config/create [POST]

### Strategy
Customize the behavior of the Switcher by including strategy rules to your Switchers.
Customize the Switcher behavior by including strategy rules to your Switchers.

- **New Strategy** - ConfigStrategy: /configstrategy/create [POST]
81 changes: 46 additions & 35 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"license": "MIT",
"dependencies": {
"axios": "^1.11.0",
"axios": "^1.12.1",
"bcryptjs": "^3.0.2",
"cors": "^2.8.5",
"express": "^5.1.0",
Expand All @@ -51,7 +51,7 @@
"moment": "^2.30.1",
"mongodb": "^6.19.0",
"mongoose": "^8.18.1",
"pino": "^9.9.4",
"pino": "^9.9.5",
"pino-pretty": "^13.1.1",
"swagger-ui-express": "^5.0.1",
"switcher-client": "^4.4.1",
Expand Down
5 changes: 5 additions & 0 deletions src/api-docs/schemas/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export const admin = {
type: 'boolean',
description: 'Whether the admin is active or not'
},
auth_provider: {
type: 'string',
enum: ['email', 'github', 'bitbucket'],
description: 'Authentication provider used'
},
teams: {
type: 'array',
items: {
Expand Down
6 changes: 6 additions & 0 deletions src/models/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const adminSchema = new mongoose.Schema({
code: {
type: String
},
auth_provider: {
type: String,
enum: ['email', 'github', 'bitbucket'],
default: 'email'
},
_gitid: {
type: String
},
Expand Down Expand Up @@ -176,6 +181,7 @@ adminSchema.statics.createThirdPartyAccount = async (
admin = new Admin({
name: userInfo.name,
email: userInfo.email,
auth_provider: platform,
[`${attributeIdName}`]: userInfo.id,
_avatar: userInfo.avatar,
password: hash
Expand Down
3 changes: 3 additions & 0 deletions tests/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('Testing Admin insertion', () => {
// DB validation - document created
const admin = await Admin.findById(response.body.admin._id).lean().exec();
expect(admin).not.toBeNull();
expect(admin.auth_provider).toBe('email');

//used at: ADMIN_SUITE - Should confirm access to a new Admin
signedupUser = response.body.admin._id;
Expand Down Expand Up @@ -282,6 +283,7 @@ describe('Testing Admin insertion', () => {
const admin = await Admin.findById(response.body.admin._id).lean().exec();
expect(admin).not.toBeNull();
expect(admin._gitid).toEqual('123456789');
expect(admin.auth_provider).toBe('github');

// restore
axiosPostStub.restore();
Expand Down Expand Up @@ -320,6 +322,7 @@ describe('Testing Admin insertion', () => {
const admin = await Admin.findById(response.body.admin._id).lean().exec();
expect(admin).not.toBeNull();
expect(admin._bitbucketid).toEqual('123456789');
expect(admin.auth_provider).toBe('bitbucket');

// restore
axiosPostStub.restore();
Expand Down