@ohos-ports/sap-cf-tools 3.3.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/src/cli.js ADDED
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cli = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const comment_json_1 = require("comment-json");
6
+ const _ = require("lodash");
7
+ const types_1 = require("./types");
8
+ class Cli {
9
+ static execute(args, options, token) {
10
+ token = token || {
11
+ isCancellationRequested: false,
12
+ onCancellationRequested: () => {
13
+ return;
14
+ },
15
+ };
16
+ Cli.updateSpawnOptions(options);
17
+ return new Promise((resolve) => {
18
+ let stderr = "";
19
+ let stdout = "";
20
+ if (token.isCancellationRequested) {
21
+ Cli.cliResultOnExit(stdout, resolve, stderr, types_1.CF_CMD_EXIT_CODE.CANCEL_REQ);
22
+ return;
23
+ }
24
+ const childProcess = (0, child_process_1.spawn)(Cli.CF_CMD, args, options);
25
+ childProcess.stdin.end();
26
+ childProcess.stdout.on("data", (data) => {
27
+ stdout = stdout.concat(data);
28
+ });
29
+ childProcess.stderr.on("data", (data) => {
30
+ stderr = stderr.concat(data);
31
+ });
32
+ childProcess.on("exit", (code) => {
33
+ Cli.cliResultOnExit(stdout, resolve, stderr, code);
34
+ });
35
+ childProcess.on("error", (err) => {
36
+ const message = (_.get(err, "code") === "ENOENT" ? `${Cli.CF_CMD}: command not found` : _.get(err, "message"));
37
+ resolve({ stdout: stdout, stderr: stderr, error: message, exitCode: types_1.CF_CMD_EXIT_CODE.ERROR });
38
+ });
39
+ token.onCancellationRequested(() => {
40
+ childProcess.kill();
41
+ Cli.cliResultOnExit("", resolve, "", types_1.CF_CMD_EXIT_CODE.CANCELED);
42
+ });
43
+ });
44
+ }
45
+ static cliResultOnExit(stdout, resolve, stderr, code) {
46
+ if (stdout) {
47
+ if (stdout.indexOf("error_code") > 0) {
48
+ try {
49
+ const cfErr = (0, comment_json_1.parse)(stdout);
50
+ const message = (_.get(cfErr, "code") === 10002 ? Cli.CF_LOGIN_ERROR : _.get(cfErr, "description", "Internal error occured"));
51
+ resolve({ stdout: stdout, stderr: stderr, exitCode: types_1.CF_CMD_EXIT_CODE.ERROR, error: message });
52
+ return;
53
+ }
54
+ catch (e) {
55
+ }
56
+ }
57
+ else if (stdout.startsWith("FAILED") && stdout.indexOf("Error creating request") > 0) {
58
+ resolve({ stdout: stdout, stderr: stderr, error: Cli.CF_LOGIN_ERROR, exitCode: types_1.CF_CMD_EXIT_CODE.ERROR });
59
+ return;
60
+ }
61
+ else if (/failed.*\bError\b:/g.test(stdout)) {
62
+ try {
63
+ (0, comment_json_1.parse)(stdout);
64
+ }
65
+ catch (e) {
66
+ resolve({ stdout: stdout, stderr: stderr, error: stdout, exitCode: types_1.CF_CMD_EXIT_CODE.ERROR });
67
+ return;
68
+ }
69
+ }
70
+ else if (stdout.startsWith("FAILED") && stdout.indexOf("No API endpoint set") > 0) {
71
+ resolve({ stdout: stdout, stderr: stderr, error: stdout, exitCode: types_1.CF_CMD_EXIT_CODE.ERROR });
72
+ return;
73
+ }
74
+ }
75
+ resolve({ stdout: stdout, stderr: stderr, exitCode: code });
76
+ }
77
+ static updateSpawnOptions(options) {
78
+ if (options) {
79
+ options.env = Object.assign(Object.assign(Object.assign({}, process.env), { NODE_VERSION: process.versions.node }), options.env);
80
+ _.defaults(options, { cwd: _.get(options, "cmd", __dirname) });
81
+ }
82
+ }
83
+ }
84
+ exports.Cli = Cli;
85
+ Cli.CF_LOGIN_ERROR = "Not logged in. Use 'cf login' to log in.";
86
+ Cli.CF_CMD = "cf";
87
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1,10 @@
1
+ export * from "./types";
2
+ export * from "./cli";
3
+ export * from "./cf-local";
4
+ export * from "./messages";
5
+ export * from "./utils";
6
+ import { ServiceInstanceInfo } from "./types";
7
+ export declare function apiGetServicesInstancesFilteredByType(serviceTypes: string[]): Promise<ServiceInstanceInfo[]>;
8
+ export declare function apiGetInstanceCredentials(instanceName: string): Promise<any>;
9
+ export declare function apiCreateServiceInstance(serviceType: string, servicePlan: string, instanceName: string, config?: any): Promise<any>;
10
+ export declare function apiGetInstanceMetadata(instanceName: string): Promise<any>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.apiGetInstanceMetadata = exports.apiCreateServiceInstance = exports.apiGetInstanceCredentials = exports.apiGetServicesInstancesFilteredByType = void 0;
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./cli"), exports);
20
+ __exportStar(require("./cf-local"), exports);
21
+ __exportStar(require("./messages"), exports);
22
+ __exportStar(require("./utils"), exports);
23
+ const serviceUtils = require("./cfServicesUtil");
24
+ async function apiGetServicesInstancesFilteredByType(serviceTypes) {
25
+ return serviceUtils.getServicesInstancesFilteredByType(serviceTypes);
26
+ }
27
+ exports.apiGetServicesInstancesFilteredByType = apiGetServicesInstancesFilteredByType;
28
+ async function apiGetInstanceCredentials(instanceName) {
29
+ return serviceUtils.getInstanceCredentials(instanceName);
30
+ }
31
+ exports.apiGetInstanceCredentials = apiGetInstanceCredentials;
32
+ async function apiCreateServiceInstance(serviceType, servicePlan, instanceName, config) {
33
+ return serviceUtils.createServiceInstance(serviceType, servicePlan, instanceName, config);
34
+ }
35
+ exports.apiCreateServiceInstance = apiCreateServiceInstance;
36
+ async function apiGetInstanceMetadata(instanceName) {
37
+ return serviceUtils.getInstanceMetadata(instanceName);
38
+ }
39
+ exports.apiGetInstanceMetadata = apiGetInstanceMetadata;
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ export declare const messages: {
2
+ space_not_set: string;
3
+ service_creation_started: string;
4
+ create_service_canceled_by_requester: string;
5
+ cf_setting_not_set: string;
6
+ no_valid_filters: string;
7
+ failed_creating_entity: (description: string, name: string) => string;
8
+ exceed_number_of_attempts: (name: string) => string;
9
+ service_not_found: (instanceName: string) => string;
10
+ service_creation_failed: (error: string) => string;
11
+ not_allowed_filter: (param: string, query: string) => string;
12
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.messages = void 0;
4
+ exports.messages = {
5
+ space_not_set: `The selected action failed because there is no Cloud Foundry space assigned.`,
6
+ service_creation_started: `Service instance creation started, waiting for 'Ready' state...`,
7
+ create_service_canceled_by_requester: `The service instance creation was cancelled by the requester. The service may have been partially created, consider deleting it using the 'cf delete-service' command.`,
8
+ cf_setting_not_set: `Could not find the Cloud Foundry settings. Make sure you have assigned an org and space in Cloud Foundry.`,
9
+ no_valid_filters: `Could not find any valid filters.`,
10
+ failed_creating_entity: (description, name) => `Could not create the entity since ${description}, consider deleting it using the 'cf delete-service ${name} command'.`,
11
+ exceed_number_of_attempts: (name) => `Could not verify the service instance creation. Check its status using the 'cf service ${name}' command.`,
12
+ service_not_found: (instanceName) => `Could not find the '${instanceName}' service instance.`,
13
+ service_creation_failed: (error) => `Service instance creation failed: ${error}`,
14
+ not_allowed_filter: (param, query) => `The '${param}' parameter is not allowed in the '${query}' query.`,
15
+ };
16
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ export declare function saveTaskConfiguration(wsFolderPath: string, configuration: any): Promise<void>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.saveTaskConfiguration = void 0;
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const _ = require("lodash");
7
+ const comment_json_1 = require("comment-json");
8
+ const DEFAULT_TASKS_JSON_CONTENT = { version: "2.0.0", tasks: [] };
9
+ async function getTaskJsonContentAsJsonObject(taskJsonFilePath) {
10
+ try {
11
+ const tasksJsonString = await fs.promises.readFile(taskJsonFilePath, { encoding: "utf8" });
12
+ const tasksJson = (0, comment_json_1.parse)(tasksJsonString);
13
+ return _.assign(DEFAULT_TASKS_JSON_CONTENT, tasksJson);
14
+ }
15
+ catch (e) {
16
+ return DEFAULT_TASKS_JSON_CONTENT;
17
+ }
18
+ }
19
+ async function saveTaskConfiguration(wsFolderPath, configuration) {
20
+ const taskJsonFilePath = path.join(wsFolderPath, ".vscode", "tasks.json");
21
+ const tasksJson = await getTaskJsonContentAsJsonObject(taskJsonFilePath);
22
+ const existingTaskindex = tasksJson.tasks.findIndex((task) => task.label === configuration.label);
23
+ if (existingTaskindex >= 0) {
24
+ tasksJson.tasks[existingTaskindex] = configuration;
25
+ }
26
+ else {
27
+ tasksJson.tasks.push(configuration);
28
+ }
29
+ await fs.promises.writeFile(taskJsonFilePath, (0, comment_json_1.stringify)(tasksJson, undefined, " "));
30
+ }
31
+ exports.saveTaskConfiguration = saveTaskConfiguration;
32
+ //# sourceMappingURL=task.js.map
@@ -0,0 +1,214 @@
1
+ export declare const OK = "OK";
2
+ export declare const NEW_LINE = "\n";
3
+ export declare const CF_PAGE_SIZE: number;
4
+ export declare const DEFAULT_TARGET = "Default (no targets)";
5
+ export interface CliResult {
6
+ stdout: string;
7
+ stderr: string;
8
+ error?: string;
9
+ exitCode: number;
10
+ }
11
+ export declare enum CF_CMD_EXIT_CODE {
12
+ OK = 0,
13
+ ERROR = -1,
14
+ CANCEL_REQ = -2,
15
+ CANCELED = -3
16
+ }
17
+ export interface CancellationToken {
18
+ isCancellationRequested: boolean;
19
+ onCancellationRequested: any;
20
+ }
21
+ interface Progress<T> {
22
+ report(value: T): void;
23
+ }
24
+ export interface ProgressHandler {
25
+ progress: Progress<{
26
+ message?: string;
27
+ increment?: number;
28
+ }>;
29
+ cancelToken: CancellationToken;
30
+ }
31
+ export interface CFTarget {
32
+ label: string;
33
+ isCurrent: boolean;
34
+ isDirty: boolean;
35
+ }
36
+ export interface ServiceInstanceInfo {
37
+ label: string;
38
+ serviceName: string;
39
+ guid?: string;
40
+ tags?: string[];
41
+ alwaysShow?: boolean;
42
+ plan_guid?: string;
43
+ plan?: string;
44
+ credentials?: any;
45
+ }
46
+ export interface ServiceInfo {
47
+ label: string;
48
+ guid: string;
49
+ service_plans_url: string;
50
+ description: string;
51
+ }
52
+ export interface PlanInfo {
53
+ label: string;
54
+ guid: string;
55
+ description: string;
56
+ service_offering?: {
57
+ guid: string;
58
+ name: string;
59
+ description: string;
60
+ };
61
+ }
62
+ export interface CFResource {
63
+ guid: string;
64
+ name: string;
65
+ description: string;
66
+ schemas: any;
67
+ relationships: any;
68
+ metadata: any;
69
+ links: any;
70
+ }
71
+ export interface ServiceTypeInfo {
72
+ name: string;
73
+ plan: string;
74
+ tag: string;
75
+ prompt: string;
76
+ plans?: PlanInfo[];
77
+ serviceKeyName?: string;
78
+ serviceKeyParam?: any;
79
+ ups?: {
80
+ tag?: string;
81
+ isShow?: boolean;
82
+ };
83
+ allowCreate?: {
84
+ serviceName?: string;
85
+ plan?: string;
86
+ tag?: string;
87
+ name?: string;
88
+ namePrompt?: string;
89
+ getParams?: () => Promise<any>;
90
+ };
91
+ }
92
+ export declare enum eFilters {
93
+ type = "type",
94
+ names = "names",
95
+ guids = "guids",
96
+ app_guids = "app_guids",
97
+ app_names = "app_names",
98
+ space_guids = "space_guids",
99
+ available = "available",
100
+ broker_catalog_ids = "broker_catalog_ids",
101
+ service_broker_guids = "service_broker_guids",
102
+ service_broker_names = "service_broker_names",
103
+ service_plan_guids = "service_plan_guids",
104
+ organization_guids = "organization_guids",
105
+ service_plan_names = "service_plan_names",
106
+ service_plan = "service_plan",
107
+ service_instance_guids = "service_instance_guids",
108
+ service_instance_names = "service_instance_names",
109
+ service_offering_guids = "service_offering_guids",
110
+ service_offering_names = "service_offering_names",
111
+ label_selector = "label_selector",
112
+ page = "page",
113
+ per_page = "per_page",
114
+ oder_by = "order_by",
115
+ created_ats = "created_ats",
116
+ updated_ats = "updated_ats",
117
+ status = "status",
118
+ include = "include"
119
+ }
120
+ export declare enum eOperation {
121
+ gte = "gte",
122
+ lte = "lte",
123
+ lt = "lt",
124
+ gt = "gt",
125
+ not = "not",
126
+ fields = "fields"
127
+ }
128
+ export interface IServiceFilters {
129
+ key: eFilters;
130
+ value: string;
131
+ op?: eOperation;
132
+ }
133
+ export declare enum eOrderDirection {
134
+ asc = 0,
135
+ desc = 1
136
+ }
137
+ export declare enum eServiceTypes {
138
+ managed = "managed",
139
+ user_provided = "user-provided"
140
+ }
141
+ export interface IServiceQuery {
142
+ filters?: IServiceFilters[];
143
+ per_page?: number;
144
+ page?: number;
145
+ order_by?: eOrderDirection;
146
+ }
147
+ export interface ServiceBinding {
148
+ env: string;
149
+ id: string;
150
+ type: string;
151
+ version: string;
152
+ }
153
+ export interface UAAInfo {
154
+ apiurl: string;
155
+ clientid: string;
156
+ clientsecret: string;
157
+ identityzone: string;
158
+ identityzoneid: string;
159
+ sburl: string;
160
+ tenantid: string;
161
+ tenantmode: string;
162
+ uaadomain: string;
163
+ url: string;
164
+ verificationkey: string;
165
+ xsappname: string;
166
+ }
167
+ export interface ServiceKey {
168
+ binding: ServiceBinding;
169
+ catalogs: any;
170
+ endpoints: any;
171
+ preserve_host_header: boolean;
172
+ "sap.cloud.service": string;
173
+ systemid: string;
174
+ uaa: UAAInfo;
175
+ url: string;
176
+ }
177
+ export interface Api {
178
+ "api endpoint": string;
179
+ "api version": string;
180
+ }
181
+ export interface ITarget extends Api {
182
+ user: string;
183
+ org?: string;
184
+ space?: string;
185
+ }
186
+ export interface UpsTypeInfo {
187
+ instanceName: string;
188
+ space_guid?: string;
189
+ syslog_drain_url?: string;
190
+ credentials?: unknown;
191
+ route_service_url?: string;
192
+ tags?: string[];
193
+ }
194
+ interface LoginOptions {
195
+ endpoint: string;
196
+ origin?: string;
197
+ }
198
+ export interface SSOLoginOptions extends LoginOptions {
199
+ ssoPasscode: string;
200
+ }
201
+ export interface CredentialsLoginOptions extends LoginOptions {
202
+ user: string;
203
+ password: string;
204
+ }
205
+ export interface Organization {
206
+ label: string;
207
+ guid: string;
208
+ }
209
+ export interface Space {
210
+ label: string;
211
+ guid: string;
212
+ orgGUID: string;
213
+ }
214
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eServiceTypes = exports.eOrderDirection = exports.eOperation = exports.eFilters = exports.CF_CMD_EXIT_CODE = exports.DEFAULT_TARGET = exports.CF_PAGE_SIZE = exports.NEW_LINE = exports.OK = void 0;
4
+ exports.OK = "OK";
5
+ exports.NEW_LINE = "\n";
6
+ exports.CF_PAGE_SIZE = 99 * 3;
7
+ exports.DEFAULT_TARGET = "Default (no targets)";
8
+ var CF_CMD_EXIT_CODE;
9
+ (function (CF_CMD_EXIT_CODE) {
10
+ CF_CMD_EXIT_CODE[CF_CMD_EXIT_CODE["OK"] = 0] = "OK";
11
+ CF_CMD_EXIT_CODE[CF_CMD_EXIT_CODE["ERROR"] = -1] = "ERROR";
12
+ CF_CMD_EXIT_CODE[CF_CMD_EXIT_CODE["CANCEL_REQ"] = -2] = "CANCEL_REQ";
13
+ CF_CMD_EXIT_CODE[CF_CMD_EXIT_CODE["CANCELED"] = -3] = "CANCELED";
14
+ })(CF_CMD_EXIT_CODE = exports.CF_CMD_EXIT_CODE || (exports.CF_CMD_EXIT_CODE = {}));
15
+ var eFilters;
16
+ (function (eFilters) {
17
+ eFilters["type"] = "type";
18
+ eFilters["names"] = "names";
19
+ eFilters["guids"] = "guids";
20
+ eFilters["app_guids"] = "app_guids";
21
+ eFilters["app_names"] = "app_names";
22
+ eFilters["space_guids"] = "space_guids";
23
+ eFilters["available"] = "available";
24
+ eFilters["broker_catalog_ids"] = "broker_catalog_ids";
25
+ eFilters["service_broker_guids"] = "service_broker_guids";
26
+ eFilters["service_broker_names"] = "service_broker_names";
27
+ eFilters["service_plan_guids"] = "service_plan_guids";
28
+ eFilters["organization_guids"] = "organization_guids";
29
+ eFilters["service_plan_names"] = "service_plan_names";
30
+ eFilters["service_plan"] = "service_plan";
31
+ eFilters["service_instance_guids"] = "service_instance_guids";
32
+ eFilters["service_instance_names"] = "service_instance_names";
33
+ eFilters["service_offering_guids"] = "service_offering_guids";
34
+ eFilters["service_offering_names"] = "service_offering_names";
35
+ eFilters["label_selector"] = "label_selector";
36
+ eFilters["page"] = "page";
37
+ eFilters["per_page"] = "per_page";
38
+ eFilters["oder_by"] = "order_by";
39
+ eFilters["created_ats"] = "created_ats";
40
+ eFilters["updated_ats"] = "updated_ats";
41
+ eFilters["status"] = "status";
42
+ eFilters["include"] = "include";
43
+ })(eFilters = exports.eFilters || (exports.eFilters = {}));
44
+ var eOperation;
45
+ (function (eOperation) {
46
+ eOperation["gte"] = "gte";
47
+ eOperation["lte"] = "lte";
48
+ eOperation["lt"] = "lt";
49
+ eOperation["gt"] = "gt";
50
+ eOperation["not"] = "not";
51
+ eOperation["fields"] = "fields";
52
+ })(eOperation = exports.eOperation || (exports.eOperation = {}));
53
+ var eOrderDirection;
54
+ (function (eOrderDirection) {
55
+ eOrderDirection[eOrderDirection["asc"] = 0] = "asc";
56
+ eOrderDirection[eOrderDirection["desc"] = 1] = "desc";
57
+ })(eOrderDirection = exports.eOrderDirection || (exports.eOrderDirection = {}));
58
+ var eServiceTypes;
59
+ (function (eServiceTypes) {
60
+ eServiceTypes["managed"] = "managed";
61
+ eServiceTypes["user_provided"] = "user-provided";
62
+ })(eServiceTypes = exports.eServiceTypes || (exports.eServiceTypes = {}));
63
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,18 @@
1
+ import { IServiceQuery, IServiceFilters } from "./types";
2
+ export declare function dataContentAsObject(filePath: string): Promise<any>;
3
+ export declare function ensureQuery(query?: IServiceQuery): IServiceQuery;
4
+ export declare function padQuery(query: IServiceQuery, otherFilters: IServiceFilters[]): IServiceQuery;
5
+ export declare function getGuid(resource: any): string;
6
+ export declare function getName(resource: any): string;
7
+ export declare function getLabel(resource: any): string;
8
+ export declare function getDescription(resource: any): string;
9
+ export declare function getSpaceFieldGUID(spaceField: any): string;
10
+ export declare function getOrgGUID(resource: any): string;
11
+ export declare function getTags(resource: any): string[];
12
+ export declare function cfGetConfigFilePath(target?: string): string;
13
+ export declare function isUpsType(resource: any): boolean;
14
+ export declare function cfGetConfigFileJson(target?: string): Promise<unknown>;
15
+ export declare function cfGetConfigFileField(field: string, target?: string): Promise<any>;
16
+ export declare function getSpaceGuidThrowIfUndefined(): Promise<string>;
17
+ export declare function padQuerySpace(query: IServiceQuery, otherFilters?: IServiceFilters[]): Promise<IServiceQuery>;
18
+ export declare function parseRawDictData(data: string): unknown;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRawDictData = exports.padQuerySpace = exports.getSpaceGuidThrowIfUndefined = exports.cfGetConfigFileField = exports.cfGetConfigFileJson = exports.isUpsType = exports.cfGetConfigFilePath = exports.getTags = exports.getOrgGUID = exports.getSpaceFieldGUID = exports.getDescription = exports.getLabel = exports.getName = exports.getGuid = exports.padQuery = exports.ensureQuery = exports.dataContentAsObject = void 0;
4
+ const _ = require("lodash");
5
+ const os = require("os");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const comment_json_1 = require("comment-json");
9
+ const messages_1 = require("./messages");
10
+ const types_1 = require("./types");
11
+ async function dataContentAsObject(filePath) {
12
+ try {
13
+ return _.reduce(_.split(await fs.promises.readFile(filePath, { encoding: "utf8" }), os.EOL), (data, line) => {
14
+ const parts = _.split(line, "=");
15
+ if (_.size(parts) > 1) {
16
+ data[_.trim(parts[0])] = _.trim(parts[1]);
17
+ }
18
+ return data;
19
+ }, {});
20
+ }
21
+ catch (error) {
22
+ return {};
23
+ }
24
+ }
25
+ exports.dataContentAsObject = dataContentAsObject;
26
+ function ensureQuery(query) {
27
+ query = query || {};
28
+ _.defaults(query, { filters: [] });
29
+ _.defaults(query, { per_page: types_1.CF_PAGE_SIZE });
30
+ return query;
31
+ }
32
+ exports.ensureQuery = ensureQuery;
33
+ function padQuery(query, otherFilters) {
34
+ query = ensureQuery(query);
35
+ _.each(otherFilters, (other) => {
36
+ const filter = _.find(query.filters, ["key", other.key]);
37
+ if (!_.size(filter === null || filter === void 0 ? void 0 : filter.value)) {
38
+ query.filters = _.concat(query.filters, [other]);
39
+ }
40
+ });
41
+ return query;
42
+ }
43
+ exports.padQuery = padQuery;
44
+ function getGuid(resource) {
45
+ return _.get(resource, "guid", "");
46
+ }
47
+ exports.getGuid = getGuid;
48
+ function getName(resource) {
49
+ return _.get(resource, "name", "");
50
+ }
51
+ exports.getName = getName;
52
+ function getLabel(resource) {
53
+ return _.get(resource, "label", "");
54
+ }
55
+ exports.getLabel = getLabel;
56
+ function getDescription(resource) {
57
+ return _.get(resource, "description", "");
58
+ }
59
+ exports.getDescription = getDescription;
60
+ function getSpaceFieldGUID(spaceField) {
61
+ return _.get(spaceField, "GUID", "");
62
+ }
63
+ exports.getSpaceFieldGUID = getSpaceFieldGUID;
64
+ function getOrgGUID(resource) {
65
+ return _.get(resource, ["relationships", "organization", "data", "guid"], "");
66
+ }
67
+ exports.getOrgGUID = getOrgGUID;
68
+ function getTags(resource) {
69
+ return _.get(resource, "tags", []);
70
+ }
71
+ exports.getTags = getTags;
72
+ function cfGetConfigFilePath(target) {
73
+ const relatives = target ? ["targets", `${target}.config.json`] : [`config.json`];
74
+ return path.join(_.get(process, "env.CF_HOME", os.homedir()), ".cf", ...relatives);
75
+ }
76
+ exports.cfGetConfigFilePath = cfGetConfigFilePath;
77
+ function isUpsType(resource) {
78
+ return _.get(resource, "type", types_1.eServiceTypes.managed) === types_1.eServiceTypes.user_provided;
79
+ }
80
+ exports.isUpsType = isUpsType;
81
+ async function cfGetConfigFileJson(target) {
82
+ try {
83
+ return (0, comment_json_1.parse)(await fs.promises.readFile(cfGetConfigFilePath(target), { encoding: "utf8" }));
84
+ }
85
+ catch (error) {
86
+ }
87
+ }
88
+ exports.cfGetConfigFileJson = cfGetConfigFileJson;
89
+ async function cfGetConfigFileField(field, target) {
90
+ return _.get(await cfGetConfigFileJson(target), `${field}`);
91
+ }
92
+ exports.cfGetConfigFileField = cfGetConfigFileField;
93
+ async function getSpaceGuidThrowIfUndefined() {
94
+ const space = getSpaceFieldGUID(await cfGetConfigFileField("SpaceFields"));
95
+ if (!space) {
96
+ throw new Error(messages_1.messages.cf_setting_not_set);
97
+ }
98
+ return space;
99
+ }
100
+ exports.getSpaceGuidThrowIfUndefined = getSpaceGuidThrowIfUndefined;
101
+ async function padQuerySpace(query, otherFilters) {
102
+ query = padQuery(query, otherFilters);
103
+ const filter = _.find(query.filters, ["key", types_1.eFilters.space_guids]);
104
+ if (!_.size(filter === null || filter === void 0 ? void 0 : filter.value)) {
105
+ query.filters = _.concat(query.filters, [
106
+ { key: types_1.eFilters.space_guids, value: await getSpaceGuidThrowIfUndefined() },
107
+ ]);
108
+ }
109
+ return query;
110
+ }
111
+ exports.padQuerySpace = padQuerySpace;
112
+ function parseRawDictData(data) {
113
+ const result = {};
114
+ _.each(_.compact(_.split(data, "\n")), (item) => {
115
+ item = _.replace(_.trim(item), /^['"]|['"]$/g, "");
116
+ const sep = _.indexOf(item, ":");
117
+ if (sep > -1) {
118
+ const key = _.toLower(_.trim(_.join(_.slice(item, 0, sep), "")));
119
+ const value = _.trim(_.join(_.slice(item, sep + 1), ""));
120
+ result[`${key}`] = value;
121
+ }
122
+ });
123
+ return result;
124
+ }
125
+ exports.parseRawDictData = parseRawDictData;
126
+ //# sourceMappingURL=utils.js.map