Socket
Socket
Sign inDemoInstall

oci-common

Package Overview
Dependencies
Maintainers
4
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oci-common - npm Package Compare versions

Comparing version 2.57.0 to 2.58.1

9

lib/endpoint-builder.d.ts

@@ -7,7 +7,12 @@ /**

export declare class EndpointBuilder {
static createEndpointFromRegion(template: string, region: Region, endpointServiceName?: string): string;
static createEndpointFromRegionId(template: string, regionId: string, endpointServiceName?: string): string;
static createEndpointFromRegion(template: string, region: Region, endpointServiceName?: string, serviceEndpointTemplatePerRealm?: any, useRealmSpecificEndpointTemplate?: boolean): string;
private static checkAndGetEndpointTemplateToUse;
private static getEndpointTemplateToUse;
static createEndpointFromRegionId(template: string, regionId: string, endpointServiceName?: string, serviceEndpointTemplatePerRealm?: any, useRealmSpecificEndpointTemplate?: boolean): string;
static createEndpointFromRegionIdAndSecondLevelDomain(template: string, regionId: string, secondLevelDomain: string): string;
static createEndpointForDottedRegion(template: string, // https://identity.{region}.oci.{secondLevelDomain}
regionId: string, endpointServiceName?: string): string;
static populateServiceParamsInEndpoint(endpoint: string, pathParams: any, queryParams: any, requiredParams: Set<string>): string;
private static getParameterValueFromPathAndQueryParams;
private static isRealmSpecificEndpointTemplateEnabledViaEnv;
}

@@ -11,15 +11,37 @@ "use strict";

class EndpointBuilder {
static createEndpointFromRegion(template, region, endpointServiceName) {
static createEndpointFromRegion(template, region, endpointServiceName, serviceEndpointTemplatePerRealm, useRealmSpecificEndpointTemplate) {
const regionId = region.regionId;
const secondLevelDomain = region.realm.secondLevelDomain;
const templateToUse = EndpointBuilder.checkAndGetEndpointTemplateToUse(region.realm, template, serviceEndpointTemplatePerRealm, useRealmSpecificEndpointTemplate);
// If regionId is a dotted region, call createEndpointForDottedRegion
if (regionId.includes(".")) {
return EndpointBuilder.createEndpointForDottedRegion(template, regionId, endpointServiceName);
return EndpointBuilder.createEndpointForDottedRegion(templateToUse, regionId, endpointServiceName);
}
else {
// Default to using regionId and secondLevelDomain
return EndpointBuilder.createEndpointFromRegionIdAndSecondLevelDomain(template, regionId, secondLevelDomain);
return EndpointBuilder.createEndpointFromRegionIdAndSecondLevelDomain(templateToUse, regionId, secondLevelDomain);
}
}
static createEndpointFromRegionId(template, regionId, endpointServiceName) {
static checkAndGetEndpointTemplateToUse(realm, defaultTemplate, serviceEndpointTemplatePerRealm, useRealmSpecificEndpointTemplate) {
let templateToUse = defaultTemplate;
if (useRealmSpecificEndpointTemplate) {
templateToUse = EndpointBuilder.getEndpointTemplateToUse(realm, defaultTemplate, serviceEndpointTemplatePerRealm);
}
else if (EndpointBuilder.isRealmSpecificEndpointTemplateEnabledViaEnv()) {
templateToUse = EndpointBuilder.getEndpointTemplateToUse(realm, defaultTemplate, serviceEndpointTemplatePerRealm);
}
return templateToUse;
}
static getEndpointTemplateToUse(realm, defaultTemplate, serviceEndpointTemplatePerRealm) {
const realmId = realm.realmId.toLowerCase();
if (serviceEndpointTemplatePerRealm) {
if (serviceEndpointTemplatePerRealm[realmId]) {
console.log(`Using ${serviceEndpointTemplatePerRealm[realmId]} as the realm specific endpoint template`);
return serviceEndpointTemplatePerRealm[realmId];
}
}
console.log(`Realm specific endpoint template for realm ${realmId} does not exist. Falling back to endpoint template : ${defaultTemplate}`);
return defaultTemplate;
}
static createEndpointFromRegionId(template, regionId, endpointServiceName, serviceEndpointTemplatePerRealm, useRealmSpecificEndpointTemplate) {
// If regionId is a dotted region, call createEndpointForDottedRegion

@@ -29,7 +51,13 @@ if (regionId.includes("."))

const region = region_1.Region.fromRegionId(regionId);
if (region)
return EndpointBuilder.createEndpointFromRegion(template, region, endpointServiceName);
if (region) {
const templateToUse = EndpointBuilder.checkAndGetEndpointTemplateToUse(region.realm, template, serviceEndpointTemplatePerRealm, useRealmSpecificEndpointTemplate);
return EndpointBuilder.createEndpointFromRegion(templateToUse, region, endpointServiceName);
}
// If regionId does not return a known region, check to see if there is a fallback second level domain from env.OCI_DEFAULT_REALM
// If no fallback for second level domain, default it to OC1's second level domain.
const fallbackSecondLevelDomain = process.env["OCI_DEFAULT_REALM"];
let templateToUse = template;
if (!fallbackSecondLevelDomain) {
templateToUse = EndpointBuilder.checkAndGetEndpointTemplateToUse(realm_1.Realm.OC1, template, serviceEndpointTemplatePerRealm, useRealmSpecificEndpointTemplate);
}
let secondLevelDomain = fallbackSecondLevelDomain

@@ -39,3 +67,3 @@ ? fallbackSecondLevelDomain

console.log(`Unknown regionId [${regionId}], falling back to using ${secondLevelDomain} as the second level domain.`);
return EndpointBuilder.createEndpointFromRegionIdAndSecondLevelDomain(template, regionId, secondLevelDomain);
return EndpointBuilder.createEndpointFromRegionIdAndSecondLevelDomain(templateToUse, regionId, secondLevelDomain);
}

@@ -61,4 +89,46 @@ static createEndpointFromRegionIdAndSecondLevelDomain(template, regionId, secondLevelDomain) {

}
static populateServiceParamsInEndpoint(endpoint, pathParams, queryParams, requiredParams) {
if (!/\{.*\}/.test(endpoint))
return endpoint;
const regexForParameters = /\{([^}]+)\}/g;
let paramFromEndpoint;
let populatedEndpoint = endpoint;
while ((paramFromEndpoint = regexForParameters.exec(endpoint))) {
let appendDotInEndpointTemplate = false;
let paramName = paramFromEndpoint[1];
if (paramName.indexOf("+Dot") !== -1 || paramName.indexOf(".") !== -1) {
appendDotInEndpointTemplate = true;
paramName = paramFromEndpoint[1].replace("+Dot", "").replace(".", "");
}
let value = "";
if (requiredParams.has(paramName)) {
value = EndpointBuilder.getParameterValueFromPathAndQueryParams(paramName, pathParams, queryParams);
}
if (value) {
if (appendDotInEndpointTemplate)
value += ".";
populatedEndpoint = populatedEndpoint.replace(paramFromEndpoint[0], value);
}
else {
populatedEndpoint = populatedEndpoint.replace(paramFromEndpoint[0], "");
}
}
return populatedEndpoint;
}
static getParameterValueFromPathAndQueryParams(parameterName, pathParams, queryParams) {
let paramNameForPath = `{${parameterName}}`;
if (pathParams[paramNameForPath] && typeof pathParams[paramNameForPath] === "string")
return pathParams[paramNameForPath];
if (queryParams[parameterName] && typeof queryParams[parameterName] === "string")
return queryParams[parameterName];
return "";
}
static isRealmSpecificEndpointTemplateEnabledViaEnv() {
if (process.env.OCI_REALM_SPECIFIC_SERVICE_ENDPOINT_TEMPLATE_ENABLED === "true") {
return true;
}
return false;
}
}
exports.EndpointBuilder = EndpointBuilder;
//# sourceMappingURL=endpoint-builder.js.map

@@ -35,2 +35,4 @@ /**

private static CONTENT_TYPE_HEADER_VALUE;
static REGION_ID_STRING: string;
static REGION_STRING: string;
private constructor();

@@ -37,0 +39,0 @@ static AP_CHUNCHEON_1: Region;

@@ -236,2 +236,4 @@ "use strict";

Region.CONTENT_TYPE_HEADER_VALUE = "application/json";
Region.REGION_ID_STRING = "regionId";
Region.REGION_STRING = "region";
// OC1

@@ -238,0 +240,0 @@ Region.AP_CHUNCHEON_1 = Region.register("ap-chuncheon-1", realm_1.Realm.OC1, "yny");

{
"name": "oci-common",
"version": "2.57.0",
"version": "2.58.1",
"description": "OCI Common module for NodeJS",

@@ -5,0 +5,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc