|
1 | 1 | const Promise = require('bluebird');
|
2 | 2 | const _ = require('lodash');
|
3 | 3 | const CFError = require('cf-errors'); // eslint-disable-line
|
4 |
| -const { |
5 |
| - sendHttpRequest, |
6 |
| -} = require('./helper'); |
7 |
| -const { |
8 |
| - getContextByName, |
9 |
| -} = require('./context'); |
| 4 | +const { sendHttpRequest, } = require('./helper'); |
| 5 | +const { getContextByName, } = require('./context'); |
| 6 | +const HelmRepo = require('../entities/HelmRepo'); |
10 | 7 |
|
11 | 8 | const SUPPORTED_TYPES = [
|
12 | 9 | 'yaml',
|
13 | 10 | 'secret-yaml',
|
14 | 11 | ];
|
15 | 12 |
|
16 |
| - |
17 | 13 | const _normalizeValues = async (values = []) => {
|
18 | 14 | const normalizedValues = await Promise.reduce(values, async (normalized, name) => {
|
19 | 15 | let context;
|
@@ -139,8 +135,74 @@ const deleteRelease = async ({
|
139 | 135 | return res.id;
|
140 | 136 | };
|
141 | 137 |
|
| 138 | + |
| 139 | +const _extractFieldsForHelmRepoEntity = helmRepo => _.pick(helmRepo, 'Name', 'CreatedAt', 'Public', 'UpdatedAt'); |
| 140 | + |
| 141 | +const getAllRepos = async (options = {}) => { |
| 142 | + const qs = options.query || {}; |
| 143 | + |
| 144 | + const RequestOptions = { |
| 145 | + url: '/api/helm/repos', |
| 146 | + method: 'GET', |
| 147 | + qs, |
| 148 | + }; |
| 149 | + |
| 150 | + const result = await sendHttpRequest(RequestOptions); |
| 151 | + const helmRepos = []; |
| 152 | + _.forEach(result, (helmRepo) => { |
| 153 | + const data = _extractFieldsForHelmRepoEntity(helmRepo); |
| 154 | + helmRepos.push(new HelmRepo(data)); |
| 155 | + }); |
| 156 | + |
| 157 | + return helmRepos; |
| 158 | +}; |
| 159 | + |
| 160 | +const getRepoByName = async (name) => { |
| 161 | + const RequestOptions = { |
| 162 | + url: `/api/helm/repos/${name}`, |
| 163 | + method: 'GET', |
| 164 | + }; |
| 165 | + |
| 166 | + const result = await sendHttpRequest(RequestOptions); |
| 167 | + return new HelmRepo(result); |
| 168 | +}; |
| 169 | + |
| 170 | +const createRepo = async (data) => { |
| 171 | + const RequestOptions = { |
| 172 | + url: '/api/helm/repos', |
| 173 | + method: 'POST', |
| 174 | + body: data, |
| 175 | + }; |
| 176 | + |
| 177 | + return sendHttpRequest(RequestOptions); |
| 178 | +}; |
| 179 | + |
| 180 | +const updateRepo = async (name, data) => { |
| 181 | + const RequestOptions = { |
| 182 | + url: `/api/helm/repos/${name}`, |
| 183 | + method: 'PUT', |
| 184 | + body: data, |
| 185 | + }; |
| 186 | + |
| 187 | + return sendHttpRequest(RequestOptions); |
| 188 | +}; |
| 189 | + |
| 190 | +const deleteRepo = async (name) => { |
| 191 | + const RequestOptions = { |
| 192 | + url: `/api/helm/repos/${name}`, |
| 193 | + method: 'DELETE', |
| 194 | + }; |
| 195 | + |
| 196 | + return sendHttpRequest(RequestOptions); |
| 197 | +}; |
| 198 | + |
142 | 199 | module.exports = {
|
143 | 200 | installChart,
|
144 | 201 | testRelease,
|
145 | 202 | deleteRelease,
|
| 203 | + getAllRepos, |
| 204 | + createRepo, |
| 205 | + deleteRepo, |
| 206 | + getRepoByName, |
| 207 | + updateRepo, |
146 | 208 | };
|
0 commit comments