Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | 2x 2x 11x 2x 1x 10x 9x 9x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 15x | // @flow import { prune } from '../../utils/objects'; import { into as intoUser, type AdminUser } from './users'; import { type Caller } from '.'; /** * A description of a project. */ export type AdminProject = { account: { id: number, username: string, uuid: ?string, }, accounts: Array<string>, created: Date, enabled: boolean, id: number, department: { id: number, uuid: ?string, }, description: string, displayName: ?string, name: string, type?: string, subscriptionNumber?: string, productCode?: string, }; /** * Project API keys. */ export type AdminProjectKeys = { apiKey: string, secretKey: string, }; /** * Values for updating a project. */ export type AdminProjectUpdateValues = { description?: string, displayName?: string, }; /** * Values for updating a project. */ export type AdminProjectCreateValues = { ...AdminProjectUpdateValues, name: string, department: number, type?: string, subscriptionNumber?: string, productCode?: string, }; /** * Manage projects. */ export interface AdminProjectsAPI { list(id?: number): Promise<AdminProject | Array<AdminProject>>; keys(id: number): Promise<AdminProjectKeys>; create(values: AdminProjectCreateValues): Promise<AdminProject>; update(id: number, values: AdminProjectUpdateValues): Promise<AdminProject>; enable(id: number): Promise<AdminProject>; disable(id: number): Promise<AdminProject>; listUsers(id: number): Promise<Array<AdminUser>>; addUser(id: number, username: string): Promise<AdminProject>; removeUser(id: number, username: string): Promise<AdminProject>; delete(id: number): Promise<number>; } function into(project: any): AdminProject { return { account: { id: project.account.id, username: project.account.username, uuid: project.account.uuid || null, }, accounts: project.accounts || [], created: new Date(project.date_created), department: { id: project.reseller.id, uuid: project.reseller.cs_domain_id || null, }, description: project.description, displayName: project.display_name || null, enabled: project.enabled, id: project.id, name: project.group_name, type: project.source, subscriptionNumber: project.subscription_number, productCode: project.product_code, }; } function intoCreateValues({ name, department, description = '', displayName = name, subscriptionNumber, productCode, type, }: AdminProjectCreateValues): mixed { return { group_name: name, display_name: displayName, description, reseller_id: department, subscription_number: subscriptionNumber, product_code: productCode, source: type, }; } function intoUpdateValues({ displayName, description, }: AdminProjectUpdateValues): mixed { return prune({ description, display_name: displayName, }); } export default function projects(call: Caller): AdminProjectsAPI { async function list(id) { if (id) { const project = await call('GET', `projects/${id}`); return into(project); } const { objects } = await call('GET', 'projects'); return objects.map(into); } async function keys(id) { const { account: { username }, } = await list(id); const result = await call('GET', 'account-keys/get_user_keys', { params: { username }, }); return { apiKey: result.api_public_key, secretKey: result.api_private_key }; } async function create(values) { const data = intoCreateValues(values); const { id } = await call('POST', 'projects', { data }); return list(id); } async function update(id, values) { const data = intoUpdateValues(values); await call('PUT', `projects/${id}`, { data }); return list(id); } async function enable(id) { await call('POST', `projects/${id}/enable`); return list(id); } async function disable(id) { await call('POST', `projects/${id}/disable`); return list(id); } async function listUsers(id) { const users = await call('GET', `projects/${id}/users`); return users.map(intoUser); } async function addUser(id, username) { await call('POST', `projects/${id}/add_user`, { data: { username } }); return list(id); } async function removeUser(id, username) { await call('POST', `projects/${id}/remove_user`, { data: { username } }); return list(id); } async function remove(id) { await call('GET', `projects/${id}/delete`); return id; } return { list, keys, create, update, enable, disable, listUsers, addUser, removeUser, delete: remove, }; } |