hashicorp-copywrite[bot] 5fb9df1640
[COMPLIANCE] License changes (#18443)
* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 09:12:13 -04:00

80 lines
1.8 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Service from '@ember/service';
import { env } from 'consul-ui/env';
export default class EnvService extends Service {
// deprecated
// TODO: Remove this elsewhere in the app and use var instead
env(key) {
return this.var(key);
}
var(key) {
return env(key);
}
}
/**
* Stub class that can be used in testing when we want to test
* interactions with the EnvService. We can use `EnvStub.stubEnv` to setup
* an Env-Service that returns certain values we need to execute our tests.
*
* Example:
*
* ```js
* // some-test.js
* test('testing interaction with Env-service', async function(assert) {
* this.owner.register('service:env', class Stub extends EnvStub {
* . stubEnv = {
* CONSUL_ACLS_ENABLED: true
* }
* })
* })
* ```
*/
export class EnvStub extends EnvService {
var(key) {
const { stubEnv } = this;
const stubbed = stubEnv[key];
if (stubbed) {
return stubbed;
} else {
return super.var(...arguments);
}
}
}
/**
* Helper function to allow stubbing out data that is accessed by the application
* based on the Env-service. You will need to call this before the env-service gets
* initialized because it overrides the env-service injection on the owner.
*
* Example:
*
* ```js
* test('test something env related', async function(assert) {
* setupTestEnv(this.owner, {
* CONSUL_ACLS_ENABLED: true
* });
*
* // ...
* })
* ```
*
* @param {*} owner - the owner of the test instance (usually `this.owner`)
* @param {*} stubEnv - an object that holds the stubbed env-data
*/
export function setupTestEnv(owner, stubEnv) {
owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = stubEnv;
}
);
}