Skip to content

Commit

Permalink
feat(sandbox): user tenant example
Browse files Browse the repository at this point in the history
  • Loading branch information
yeshamavani committed Mar 6, 2024
1 parent aec62bb commit 0bd58f8
Show file tree
Hide file tree
Showing 4 changed files with 4,785 additions and 31 deletions.
48 changes: 24 additions & 24 deletions sandbox/user-tenant-example/src/application.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig} from '@loopback/core';
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {
RestExplorerBindings,
RestExplorerComponent,
} from '@loopback/rest-explorer';
import * as dotenv from 'dotenv';
import * as dotenvExt from 'dotenv-extended';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';
import {ServiceMixin} from '@loopback/service-proxy';
import {
ServiceSequence,
SFCoreBindings,
BearerVerifierBindings,
BearerVerifierComponent,
BearerVerifierConfig,
BearerVerifierType,
SECURITY_SCHEME_SPEC,
SFCoreBindings,
ServiceSequence,
} from '@sourceloop/core';
import {UserTenantServiceComponent} from '@sourceloop/user-tenant-service'
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {ServiceMixin} from '@loopback/service-proxy';
import {UserTenantServiceComponent} from '@sourceloop/user-tenant-service';
import * as dotenv from 'dotenv';
import * as dotenvExt from 'dotenv-extended';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';
import path from 'path';
import * as openapi from './openapi.json';

Expand Down Expand Up @@ -58,25 +58,26 @@ export class UserTenantExampleApplication extends BootMixin(
// To check if monitoring is enabled from env or not
const enableObf = !!+(process.env.ENABLE_OBF ?? 0);
// To check if authorization is enabled for swagger stats or not
// sonarignore:start
const authentication =
process.env.SWAGGER_USER && process.env.SWAGGER_PASSWORD ? true : false;
const obj={
enableObf,
obfPath: process.env.OBF_PATH ?? '/obf',
openapiSpec: openapi,
authentication: authentication,
swaggerUsername: process.env.SWAGGER_USER,
swaggerPassword: process.env.SWAGGER_PASSWORD,
}
// sonarignore:end
const obj = {
enableObf,
obfPath: process.env.OBF_PATH ?? '/obf',
openapiSpec: openapi,
authentication: authentication,
swaggerUsername: process.env.SWAGGER_USER,
swaggerPassword: process.env.SWAGGER_PASSWORD,
};
this.bind(SFCoreBindings.config).to(obj);

// Set up the custom sequence
this.sequence(ServiceSequence);

// Add authentication component
this.component(AuthenticationComponent);
this.component(UserTenantServiceComponent);
this.component(UserTenantServiceComponent);

// Add bearer verifier component
this.bind(BearerVerifierBindings.Config).to({
Expand All @@ -99,7 +100,6 @@ export class UserTenantExampleApplication extends BootMixin(

this.component(RestExplorerComponent);


this.projectRoot = __dirname;
// Customize @loopback/boot Booter Conventions here
this.bootOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class UserDataSource
extends juggler.DataSource
implements LifeCycleObserver
{
static dataSourceName = 'user';
static readonly dataSourceName = 'user';

static readonly defaultConfig = config;

Expand Down
10 changes: 5 additions & 5 deletions sandbox/user-tenant-example/src/openapi-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import {ApplicationConfig} from '@loopback/core';
import {UserTenantExampleApplication} from './application';

const ARGV_INDEX = 2;
const DEFAULT_PORT = 3000;
/**
* Export the OpenAPI spec from the application
*/
async function exportOpenApiSpec(): Promise<void> {
const config: ApplicationConfig = {
rest: {
port: +(process.env.PORT ?? 3000),
port: +(process.env.PORT ?? DEFAULT_PORT),
host: process.env.HOST ?? 'localhost',
},
};
Expand All @@ -23,9 +24,8 @@ exportOpenApiSpec()
process.exit(0);
})
.catch(err => {
console.error(
'Fail to export OpenAPI spec from the application.',
err,
);
// sonarignore:start
console.error('Fail to export OpenAPI spec from the application.', err);
// sonarignore:end
process.exit(1);
});
Loading

0 comments on commit 0bd58f8

Please sign in to comment.