UNPKG

3.64 kBJavaScriptView Raw
1"use strict";
2/*!
3 * Copyright 2015 Google Inc. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.Sink = void 0;
19const promisify_1 = require("@google-cloud/promisify");
20const extend = require("extend");
21/**
22 * A sink is an object that lets you to specify a set of log entries to export
23 * to a particular destination. Cloud Logging lets you export log entries
24 * to destinations including Cloud Storage buckets (for long term log
25 * storage), Google BigQuery datasets (for log analysis), Google Pub/Sub (for
26 * streaming to other applications).
27 *
28 * See {@link https://cloud.google.com/logging/docs/basic-concepts#sinks|Introduction to Sinks}
29 *
30 * @class
31 *
32 * @param {Logging} logging {@link Logging} instance.
33 * @param {string} name Name of the sink.
34 *
35 * @example
36 * ```
37 * const {Logging} = require('@google-cloud/logging');
38 * const logging = new Logging();
39 * const sink = logging.sink('my-sink');
40 * ```
41 */
42class Sink {
43 constructor(logging, name) {
44 this.logging = logging;
45 /**
46 * @name Sink#name
47 * @type {string}
48 */
49 this.name = name;
50 this.formattedName_ = 'projects/' + logging.projectId + '/sinks/' + name;
51 }
52 create(config) {
53 return this.logging.createSink(this.name, config);
54 }
55 async delete(gaxOptions) {
56 const projectId = await this.logging.auth.getProjectId();
57 this.formattedName_ = 'projects/' + projectId + '/sinks/' + this.name;
58 const reqOpts = {
59 sinkName: this.formattedName_,
60 };
61 return this.logging.configService.deleteSink(reqOpts, gaxOptions);
62 }
63 async getMetadata(gaxOptions) {
64 const projectId = await this.logging.auth.getProjectId();
65 this.formattedName_ = 'projects/' + projectId + '/sinks/' + this.name;
66 const reqOpts = {
67 sinkName: this.formattedName_,
68 };
69 [this.metadata] = await this.logging.configService.getSink(reqOpts, gaxOptions);
70 return [this.metadata];
71 }
72 setFilter(filter) {
73 return this.setMetadata({
74 filter,
75 });
76 }
77 async setMetadata(metadata) {
78 const [currentMetadata] = await this.getMetadata();
79 const uniqueWriterIdentity = metadata.uniqueWriterIdentity;
80 delete metadata.uniqueWriterIdentity;
81 let reqOpts = {
82 sinkName: this.formattedName_,
83 sink: extend({}, currentMetadata, metadata),
84 };
85 delete reqOpts.sink.gaxOptions;
86 // Add user specified uniqueWriterIdentity boolean, if any.
87 reqOpts = {
88 ...reqOpts,
89 ...(uniqueWriterIdentity && { uniqueWriterIdentity }),
90 };
91 [this.metadata] = await this.logging.configService.updateSink(reqOpts, metadata.gaxOptions);
92 return [this.metadata];
93 }
94}
95exports.Sink = Sink;
96/*! Developer Documentation
97 *
98 * All async methods (except for streams) will call a callbakc in the event
99 * that a callback is provided.
100 */
101promisify_1.callbackifyAll(Sink);
102//# sourceMappingURL=sink.js.map
\No newline at end of file