@atomist/sdm
Version:
Atomist Software Delivery Machine SDK
49 lines • 1.91 kB
JavaScript
;
/*
* Copyright © 2020 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.upsertRbac = void 0;
const role_1 = require("./role");
const roleBinding_1 = require("./roleBinding");
const serviceAccount_1 = require("./serviceAccount");
/**
* Create requested RBAC resources if they do not exist. If
* `req.roleSpec` is truthy, the service account, role, and binding
* are created. If `req.roleSpect` is falsey but
* `req.serviceAccountSpec` is truthy, only the service account is
* created. If any of the RBAC resources exist and their
* corresponding partial spec is provided in `req`, the resource is
* patched.
*
* @param req Kuberenetes application request
* @return Kubernetes RBAC resource specs that were created or patched, some may be undefined
*/
async function upsertRbac(req) {
if (req.roleSpec && !req.serviceAccountSpec) {
req.serviceAccountSpec = {};
}
const resources = {};
if (req.serviceAccountSpec) {
resources.serviceAccount = await serviceAccount_1.upsertServiceAccount(req);
}
if (req.roleSpec) {
resources.role = await role_1.upsertRole(req);
resources.roleBinding = await roleBinding_1.upsertRoleBinding(req);
}
return resources;
}
exports.upsertRbac = upsertRbac;
//# sourceMappingURL=rbac.js.map