swaggerhub-cli 0.2.15 → 0.6.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/README.md +498 -64
- package/oclif.manifest.json +1 -1
- package/package.json +28 -20
- package/src/commands/api/create.js +7 -6
- package/src/commands/api/delete.js +63 -0
- package/src/commands/api/publish.js +1 -1
- package/src/commands/api/unpublish.js +5 -13
- package/src/commands/api/update.js +21 -41
- package/src/commands/domain/create.js +5 -4
- package/src/commands/domain/delete.js +63 -0
- package/src/commands/domain/publish.js +1 -1
- package/src/commands/domain/setdefault.js +30 -0
- package/src/commands/domain/unpublish.js +4 -12
- package/src/commands/domain/update.js +109 -0
- package/src/commands/integration/create.js +3 -25
- package/src/commands/integration/delete.js +40 -0
- package/src/commands/integration/execute.js +40 -0
- package/src/commands/integration/get.js +51 -0
- package/src/commands/integration/list.js +62 -0
- package/src/commands/integration/update.js +51 -0
- package/src/commands/project/api/add.js +48 -0
- package/src/commands/project/api/remove.js +69 -0
- package/src/commands/project/create.js +77 -0
- package/src/commands/project/delete.js +44 -0
- package/src/commands/project/domain/add.js +48 -0
- package/src/commands/project/domain/remove.js +69 -0
- package/src/commands/project/get.js +51 -0
- package/src/commands/project/list.js +62 -0
- package/src/commands/project/member/list.js +60 -0
- package/src/config/index.js +4 -2
- package/src/format-readme.js +38 -0
- package/src/help.js +1 -1
- package/src/requests/api.js +5 -3
- package/src/requests/domain.js +4 -4
- package/src/requests/project.js +20 -0
- package/src/requests/spec.js +12 -0
- package/src/support/command/parse-input.js +44 -0
- package/src/support/command/update-command.js +21 -3
- package/src/template-strings/errors.js +1 -1
- package/src/template-strings/info.js +38 -3
- package/src/utils/oas.js +3 -3
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { putProject } = require('../../../requests/project')
|
|
2
|
+
const {
|
|
3
|
+
getProjectIdentifierArg
|
|
4
|
+
} = require('../../../support/command/parse-input')
|
|
5
|
+
const BaseCommand = require('../../../support/command/base-command')
|
|
6
|
+
|
|
7
|
+
class ProjectDomainAddCommand extends BaseCommand {
|
|
8
|
+
|
|
9
|
+
async run() {
|
|
10
|
+
const { args } = this.parse(ProjectDomainAddCommand)
|
|
11
|
+
const projectPath = getProjectIdentifierArg(args)
|
|
12
|
+
const domainName = args['DOMAIN']
|
|
13
|
+
|
|
14
|
+
await this.addDomainToProject(projectPath, domainName)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async addDomainToProject(projectPath, domainName) {
|
|
18
|
+
|
|
19
|
+
return this.executeHttp({
|
|
20
|
+
execute: () => putProject({ pathParams: [projectPath, 'domains', domainName] }),
|
|
21
|
+
onResolve: this.logCommandSuccess({ domainName, projectPath }),
|
|
22
|
+
options: {}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
ProjectDomainAddCommand.description = 'Adds a domain to an existing project.'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
ProjectDomainAddCommand.examples = [
|
|
31
|
+
'swaggerhub project:domain:add organization/project_name my_domain'
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
ProjectDomainAddCommand.args = [
|
|
35
|
+
{
|
|
36
|
+
name: 'OWNER/PROJECT_NAME',
|
|
37
|
+
required: true,
|
|
38
|
+
description: 'The project to add the domain to'
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
{
|
|
42
|
+
name: 'DOMAIN',
|
|
43
|
+
required: true,
|
|
44
|
+
description: 'The name of the domain to add'
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
module.exports = ProjectDomainAddCommand
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const { putProject, getProject } = require('../../../requests/project')
|
|
2
|
+
const {
|
|
3
|
+
getProjectIdentifierArg,
|
|
4
|
+
splitPathParams,
|
|
5
|
+
} = require('../../../support/command/parse-input')
|
|
6
|
+
const BaseCommand = require('../../../support/command/base-command')
|
|
7
|
+
const { getResponseContent } = require('../../../support/command/handle-response')
|
|
8
|
+
const { pipeAsync } = require('../../../utils/general')
|
|
9
|
+
|
|
10
|
+
class ProjectDomainRemoveCommand extends BaseCommand {
|
|
11
|
+
|
|
12
|
+
async run() {
|
|
13
|
+
const { args } = this.parse(ProjectDomainRemoveCommand)
|
|
14
|
+
const projectPath = getProjectIdentifierArg(args)
|
|
15
|
+
const domainToRemove = args['DOMAIN']
|
|
16
|
+
|
|
17
|
+
await this.removeDomainFromProject(projectPath, domainToRemove)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getProjectDetails(owner, projectName) {
|
|
21
|
+
return this.executeHttp({
|
|
22
|
+
execute: () => getProject([owner, projectName]),
|
|
23
|
+
onResolve: pipeAsync(getResponseContent, JSON.parse),
|
|
24
|
+
options: {}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async removeDomainFromProject(projectPath, domainName) {
|
|
29
|
+
const [owner, projectName] = splitPathParams(projectPath)
|
|
30
|
+
|
|
31
|
+
const project = await this.getProjectDetails(owner, projectName)
|
|
32
|
+
if (project.domains && !project.domains.includes(domainName)) {
|
|
33
|
+
return this.log(`Domain \'${domainName}\' does not exist in project \'${projectPath}\'`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
project.domains = project.domains.filter(item => item !== domainName)
|
|
37
|
+
const updateRequest = {
|
|
38
|
+
pathParams: [owner, projectName],
|
|
39
|
+
body: JSON.stringify(project)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this.executeHttp({
|
|
43
|
+
execute: () => putProject(updateRequest),
|
|
44
|
+
onResolve: this.logCommandSuccess({ domainName, projectPath }),
|
|
45
|
+
options: {}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
ProjectDomainRemoveCommand.description = 'Removes a domain from a project in SwaggerHub.'
|
|
51
|
+
|
|
52
|
+
ProjectDomainRemoveCommand.examples = [
|
|
53
|
+
'swaggerhub project:domain:remove organization/project_name my_domain',
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
ProjectDomainRemoveCommand.args = [
|
|
57
|
+
{
|
|
58
|
+
name: 'OWNER/PROJECT_NAME',
|
|
59
|
+
required: true,
|
|
60
|
+
description: 'The project remove the domain from'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'DOMAIN',
|
|
64
|
+
required: true,
|
|
65
|
+
description: 'The domain to remove'
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
module.exports = ProjectDomainRemoveCommand
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const { getProject } = require('../../requests/project')
|
|
2
|
+
const { getProjectIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
|
|
3
|
+
const { getResponseContent } = require('../../support/command/handle-response')
|
|
4
|
+
const { prettyPrintJSON } = require('../../utils/general')
|
|
5
|
+
const BaseCommand = require('../../support/command/base-command')
|
|
6
|
+
|
|
7
|
+
class GetProjectCommand extends BaseCommand {
|
|
8
|
+
constructor(...props) {
|
|
9
|
+
super(...props)
|
|
10
|
+
this.logProject = this.logProject.bind(this)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async run() {
|
|
14
|
+
const { args } = this.parse(GetProjectCommand)
|
|
15
|
+
const projectPath = getProjectIdentifierArg(args)
|
|
16
|
+
await this.getProject(projectPath)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async logProject(response) {
|
|
20
|
+
const project = await getResponseContent(response)
|
|
21
|
+
this.log(prettyPrintJSON(project))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getProject(projectPath) {
|
|
25
|
+
const [owner, project] = splitPathParams(projectPath)
|
|
26
|
+
|
|
27
|
+
return this.executeHttp({
|
|
28
|
+
execute: () => getProject([owner, project]),
|
|
29
|
+
onResolve: this.logProject,
|
|
30
|
+
options: {}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
GetProjectCommand.description = 'Retrieves the details for a project.'
|
|
36
|
+
|
|
37
|
+
GetProjectCommand.examples = [
|
|
38
|
+
'swaggerhub project:get organization/project_name'
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
GetProjectCommand.args = [{
|
|
42
|
+
name: 'OWNER/PROJECT_NAME',
|
|
43
|
+
required: true,
|
|
44
|
+
description: 'Project to retrieve the details for'
|
|
45
|
+
}]
|
|
46
|
+
|
|
47
|
+
GetProjectCommand.flags = {
|
|
48
|
+
...BaseCommand.flags
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = GetProjectCommand
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const { cli } = require('cli-ux')
|
|
2
|
+
const { getProject } = require('../../requests/project')
|
|
3
|
+
const { getResponseContent } = require('../../support/command/handle-response')
|
|
4
|
+
const BaseCommand = require('../../support/command/base-command')
|
|
5
|
+
|
|
6
|
+
class ListProjectCommand extends BaseCommand {
|
|
7
|
+
constructor(...props) {
|
|
8
|
+
super(...props)
|
|
9
|
+
this.logProject = this.logProject.bind(this)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run() {
|
|
13
|
+
const { args } = this.parse(ListProjectCommand)
|
|
14
|
+
await this.listProjects(args['OWNER'])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async logProject(response) {
|
|
18
|
+
const responseObj = JSON.parse(await getResponseContent(response))
|
|
19
|
+
if (responseObj.projects.length === 0){
|
|
20
|
+
this.log('No projects found.')
|
|
21
|
+
} else {
|
|
22
|
+
cli.table(responseObj.projects, {
|
|
23
|
+
name: {},
|
|
24
|
+
owner: {},
|
|
25
|
+
description: {},
|
|
26
|
+
apis: {
|
|
27
|
+
header: 'APIs'
|
|
28
|
+
},
|
|
29
|
+
domains: {}
|
|
30
|
+
}, {
|
|
31
|
+
printLine: this.log
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async listProjects(args) {
|
|
37
|
+
return this.executeHttp({
|
|
38
|
+
execute: () => getProject([args]),
|
|
39
|
+
onResolve: this.logProject,
|
|
40
|
+
options: {}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ListProjectCommand.description = 'list projects'
|
|
46
|
+
|
|
47
|
+
ListProjectCommand.examples = [
|
|
48
|
+
'swaggerhub project:list',
|
|
49
|
+
'swaggerhub project:list organization'
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
ListProjectCommand.args = [{
|
|
53
|
+
name: 'OWNER',
|
|
54
|
+
required: false,
|
|
55
|
+
description: 'Organization to list projects for'
|
|
56
|
+
}]
|
|
57
|
+
|
|
58
|
+
ListProjectCommand.flags = {
|
|
59
|
+
...BaseCommand.flags
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = ListProjectCommand
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { getProject } = require('../../../requests/project')
|
|
2
|
+
const { getResponseContent } = require('../../../support/command/handle-response')
|
|
3
|
+
const BaseCommand = require('../../../support/command/base-command')
|
|
4
|
+
const { getProjectIdentifierArg } = require('../../../support/command/parse-input')
|
|
5
|
+
const { cli } = require('cli-ux')
|
|
6
|
+
|
|
7
|
+
class ListProjectMembersCommand extends BaseCommand {
|
|
8
|
+
constructor(...props) {
|
|
9
|
+
super(...props)
|
|
10
|
+
this.logProjectMembers = this.logProjectMembers.bind(this)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async run() {
|
|
14
|
+
const { args } = this.parse(ListProjectMembersCommand)
|
|
15
|
+
const projectPath = getProjectIdentifierArg(args)
|
|
16
|
+
await this.getProjectMembers(projectPath)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async logProjectMembers(response) {
|
|
20
|
+
const responseObj = JSON.parse(await getResponseContent(response))
|
|
21
|
+
if (responseObj.members.length === 0){
|
|
22
|
+
this.log('No members found.')
|
|
23
|
+
} else {
|
|
24
|
+
cli.table(responseObj.members, {
|
|
25
|
+
name: {
|
|
26
|
+
minWidth: 24
|
|
27
|
+
},
|
|
28
|
+
type: {}
|
|
29
|
+
}, {
|
|
30
|
+
printLine: this.log
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async getProjectMembers(projectPath) {
|
|
36
|
+
return this.executeHttp({
|
|
37
|
+
execute: () => getProject([projectPath,'members']),
|
|
38
|
+
onResolve: this.logProjectMembers,
|
|
39
|
+
options: {}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
ListProjectMembersCommand.description = 'list members of a project'
|
|
45
|
+
|
|
46
|
+
ListProjectMembersCommand.examples = [
|
|
47
|
+
'swaggerhub project:member:list organisation/project_name',
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
ListProjectMembersCommand.args = [{
|
|
51
|
+
name: 'OWNER/PROJECT_NAME',
|
|
52
|
+
required: true,
|
|
53
|
+
description: 'Project to list members of'
|
|
54
|
+
}]
|
|
55
|
+
|
|
56
|
+
ListProjectMembersCommand.flags = {
|
|
57
|
+
...BaseCommand.flags
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = ListProjectMembersCommand
|
package/src/config/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const fse = require('fs-extra') // We're not using {readSyncJSON, ...} expansion
|
|
|
2
2
|
const { mergeDeep } = require('../utils/general')
|
|
3
3
|
const pick = require('lodash/pick')
|
|
4
4
|
|
|
5
|
+
const swaggerhubUrlRegex = new RegExp(/^https?:\/\/api\..*swaggerhub\.com$/)
|
|
5
6
|
const environmentalKeys = ['SWAGGERHUB_URL', 'SWAGGERHUB_API_KEY']
|
|
6
7
|
|
|
7
8
|
const checkEnvOverrides = config => ({
|
|
@@ -21,8 +22,9 @@ const setConfig = update => {
|
|
|
21
22
|
|
|
22
23
|
const isURLValid = () => {
|
|
23
24
|
const { SWAGGERHUB_URL } = getConfig()
|
|
24
|
-
return
|
|
25
|
-
(!SWAGGERHUB_URL.includes('api.swaggerhub.com') && SWAGGERHUB_URL.endsWith('/v1'))
|
|
25
|
+
return swaggerhubUrlRegex.test(SWAGGERHUB_URL) ||
|
|
26
|
+
(!SWAGGERHUB_URL.includes('api.swaggerhub.com') && SWAGGERHUB_URL.endsWith('/v1')) ||
|
|
27
|
+
SWAGGERHUB_URL.includes('localhost')
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
module.exports = {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
|
|
3
|
+
const removeArgsFromHeaders = line => {
|
|
4
|
+
const words = line.split(' ')
|
|
5
|
+
if (words.length <= 3) return line
|
|
6
|
+
return `## ${words[1]} ${words[2]}\``
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const removeArgsFromLinks = line => {
|
|
10
|
+
const slug = line.substr(line.indexOf('#')+1, line.length-2)
|
|
11
|
+
const words = slug.split('-')
|
|
12
|
+
if (words.length <= 2) return line
|
|
13
|
+
return line.replace(slug, `${words[0]}-${words[1]})`)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const main = () => {
|
|
17
|
+
const outputBuffer = []
|
|
18
|
+
try {
|
|
19
|
+
const data = fs.readFileSync('README.md', 'utf8')
|
|
20
|
+
const lineBuffer = data.split('\n')
|
|
21
|
+
|
|
22
|
+
lineBuffer.forEach(line => {
|
|
23
|
+
if (line.startsWith('* [`swaggerhub')) return outputBuffer.push(removeArgsFromLinks(line))
|
|
24
|
+
if (line.startsWith('## `swaggerhub')) return outputBuffer.push(removeArgsFromHeaders(line))
|
|
25
|
+
return outputBuffer.push(line)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const output = outputBuffer.join('\n')
|
|
29
|
+
fs.writeFileSync('README.md', output)
|
|
30
|
+
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(err)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (require.main === module) {
|
|
37
|
+
main()
|
|
38
|
+
}
|
package/src/help.js
CHANGED
package/src/requests/api.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const http = require('../support/http')
|
|
3
|
-
const { getSpec, putSpec, postSpec } = require('./spec')
|
|
1
|
+
const { getSpec, putSpec, postSpec, deleteSpec } = require('./spec')
|
|
4
2
|
|
|
5
3
|
const getApi = (pathParams, queryParams, accept = 'json') =>
|
|
6
4
|
getSpec('apis', pathParams, queryParams, accept)
|
|
7
5
|
|
|
6
|
+
const deleteApi = pathParams =>
|
|
7
|
+
deleteSpec('apis', pathParams)
|
|
8
|
+
|
|
8
9
|
const putApi = ({ pathParams, body }) =>
|
|
9
10
|
putSpec('apis', pathParams, body)
|
|
10
11
|
|
|
@@ -13,6 +14,7 @@ const postApi = ({ pathParams, queryParams, body }) =>
|
|
|
13
14
|
|
|
14
15
|
module.exports = {
|
|
15
16
|
getApi,
|
|
17
|
+
deleteApi,
|
|
16
18
|
putApi,
|
|
17
19
|
postApi
|
|
18
20
|
}
|
package/src/requests/domain.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
const { getSpec,
|
|
1
|
+
const { getSpec, postSpec, deleteSpec } = require('./spec')
|
|
2
2
|
|
|
3
3
|
const getDomain = (pathParams, queryParams, accept = 'json') =>
|
|
4
4
|
getSpec('domains', pathParams, queryParams, accept)
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const deleteDomain = (pathParams, queryParams) =>
|
|
7
|
+
deleteSpec('domains', pathParams, queryParams)
|
|
8
8
|
|
|
9
9
|
const postDomain = ({ pathParams, queryParams, body }) =>
|
|
10
10
|
postSpec('domains', pathParams, queryParams, body)
|
|
11
11
|
|
|
12
12
|
module.exports = {
|
|
13
13
|
getDomain,
|
|
14
|
-
|
|
14
|
+
deleteDomain,
|
|
15
15
|
postDomain
|
|
16
16
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { getSpec, postSpec, deleteSpec, putSpec } = require('./spec')
|
|
2
|
+
|
|
3
|
+
const getProject = (pathParams, queryParams, accept = 'json') =>
|
|
4
|
+
getSpec('projects', pathParams, queryParams, accept)
|
|
5
|
+
|
|
6
|
+
const postProject = ({ pathParams, queryParams, body }) =>
|
|
7
|
+
postSpec('projects', pathParams, queryParams, body)
|
|
8
|
+
|
|
9
|
+
const putProject = ({ pathParams, body }) =>
|
|
10
|
+
putSpec('projects', pathParams, body)
|
|
11
|
+
|
|
12
|
+
const deleteProject = pathParams =>
|
|
13
|
+
deleteSpec('projects', pathParams)
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
getProject,
|
|
17
|
+
postProject,
|
|
18
|
+
putProject,
|
|
19
|
+
deleteProject
|
|
20
|
+
}
|
package/src/requests/spec.js
CHANGED
|
@@ -12,6 +12,17 @@ const getSpec = (specType, pathParams, queryParams, accept) => {
|
|
|
12
12
|
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
const deleteSpec = (specType, pathParams, queryParams) => {
|
|
16
|
+
const { SWAGGERHUB_URL, SWAGGERHUB_API_KEY } = config.getConfig()
|
|
17
|
+
return http({
|
|
18
|
+
url: [SWAGGERHUB_URL, specType, ...pathParams],
|
|
19
|
+
auth: SWAGGERHUB_API_KEY,
|
|
20
|
+
contentType: 'json',
|
|
21
|
+
method: 'DELETE',
|
|
22
|
+
query: queryParams
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
const putSpec = (specType, pathParams, body) => {
|
|
16
27
|
const { SWAGGERHUB_URL, SWAGGERHUB_API_KEY } = config.getConfig()
|
|
17
28
|
return http({
|
|
@@ -39,6 +50,7 @@ const postSpec = (specType, pathParams, queryParams, body) => {
|
|
|
39
50
|
|
|
40
51
|
module.exports = {
|
|
41
52
|
getSpec,
|
|
53
|
+
deleteSpec,
|
|
42
54
|
putSpec,
|
|
43
55
|
postSpec
|
|
44
56
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
const { existsSync, readFileSync } = require('fs-extra')
|
|
2
|
+
const { hasJsonStructure } = require('../../utils/general')
|
|
1
3
|
const { CLIError } = require('@oclif/errors')
|
|
2
4
|
const { errorMsg } = require('../../template-strings')
|
|
3
5
|
|
|
4
6
|
const optionalVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+(\/[\w\-.]+)?(\/?)$/)
|
|
5
7
|
const requiredVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
|
|
8
|
+
const integrationIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
|
|
9
|
+
const projectIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
|
|
6
10
|
|
|
7
11
|
const isValidIdentifier = (id, isVersionRequired) => isVersionRequired
|
|
8
12
|
? requiredVersionRegex.test(id)
|
|
@@ -30,8 +34,44 @@ const getDomainIdentifierArg = args => {
|
|
|
30
34
|
return getIdentifierArg(isVersionRequired, format, identifier)
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
const getIntegrationIdentifierArg = args => {
|
|
38
|
+
const format = 'OWNER/API_NAME/VERSION/INTEGRATION_ID'
|
|
39
|
+
const identifier = args[format]
|
|
40
|
+
if (!integrationIdentifierRegex.test(identifier)) {
|
|
41
|
+
throw new CLIError(errorMsg.argsMustMatchFormat({ format }))
|
|
42
|
+
}
|
|
43
|
+
return identifier
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const getProjectIdentifierArg = args => {
|
|
47
|
+
const format = 'OWNER/PROJECT_NAME'
|
|
48
|
+
const identifier = args[format]
|
|
49
|
+
if (!projectIdentifierRegex.test(identifier)) {
|
|
50
|
+
throw new CLIError(errorMsg.argsMustMatchFormat({ format }))
|
|
51
|
+
}
|
|
52
|
+
return identifier
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const readConfigFile = filename => {
|
|
56
|
+
if (!existsSync(filename)) {
|
|
57
|
+
throw new CLIError(errorMsg.fileNotFound({ filename }))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const config = readFileSync(filename)
|
|
61
|
+
if (config.length === 0) {
|
|
62
|
+
throw new CLIError(errorMsg.fileIsEmpty({ filename }))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!hasJsonStructure(config)) {
|
|
66
|
+
throw new CLIError(errorMsg.invalidConfig())
|
|
67
|
+
}
|
|
68
|
+
return config
|
|
69
|
+
}
|
|
70
|
+
|
|
33
71
|
const splitPathParams = path => path.split('/').filter(Boolean)
|
|
34
72
|
|
|
73
|
+
const splitFlagParams = flag => flag.split(',').map(param => param.trim()).filter(Boolean)
|
|
74
|
+
|
|
35
75
|
const reqType = ({ json }) => json ? 'json' : 'yaml'
|
|
36
76
|
|
|
37
77
|
const resolvedParam = ({ resolved }) => resolved ? { resolved: true } : null
|
|
@@ -39,7 +79,11 @@ const resolvedParam = ({ resolved }) => resolved ? { resolved: true } : null
|
|
|
39
79
|
module.exports = {
|
|
40
80
|
getApiIdentifierArg,
|
|
41
81
|
getDomainIdentifierArg,
|
|
82
|
+
getIntegrationIdentifierArg,
|
|
83
|
+
getProjectIdentifierArg,
|
|
84
|
+
readConfigFile,
|
|
42
85
|
splitPathParams,
|
|
86
|
+
splitFlagParams,
|
|
43
87
|
reqType,
|
|
44
88
|
resolvedParam,
|
|
45
89
|
isValidIdentifier
|
|
@@ -3,13 +3,14 @@ const { putSpec } = require('../../requests/spec')
|
|
|
3
3
|
|
|
4
4
|
class UpdateCommand extends BaseCommand {
|
|
5
5
|
|
|
6
|
-
async updatePublish(type, owner, name, version) {
|
|
6
|
+
async updatePublish(type, owner, name, version, isPublished) {
|
|
7
7
|
const pathParams = [owner, name, version, 'settings', 'lifecycle']
|
|
8
|
-
const body = JSON.stringify({ published:
|
|
8
|
+
const body = JSON.stringify({ published: isPublished })
|
|
9
|
+
const successMessage = isPublished ? 'published' : 'unpublished'
|
|
9
10
|
|
|
10
11
|
await this.executeHttp({
|
|
11
12
|
execute: () => putSpec(type, pathParams, body),
|
|
12
|
-
onResolve: this.setSuccessMessage(
|
|
13
|
+
onResolve: this.setSuccessMessage(successMessage)({
|
|
13
14
|
type: type === 'apis' ? 'API' : 'domain',
|
|
14
15
|
path: `${owner}/${name}/${version}`
|
|
15
16
|
}),
|
|
@@ -31,6 +32,23 @@ class UpdateCommand extends BaseCommand {
|
|
|
31
32
|
options: { resolveStatus: [403] }
|
|
32
33
|
})
|
|
33
34
|
}
|
|
35
|
+
|
|
36
|
+
async updateVisibility(type, owner, name, version, isPrivate) {
|
|
37
|
+
const visibility = isPrivate ? 'private' : 'public'
|
|
38
|
+
const pathParams = [owner, name, version, 'settings', 'private']
|
|
39
|
+
const body = JSON.stringify({ private: isPrivate })
|
|
40
|
+
|
|
41
|
+
await this.executeHttp({
|
|
42
|
+
execute: () => putSpec(type, pathParams, body),
|
|
43
|
+
onResolve: this.setSuccessMessage('visibilityUpdate')({
|
|
44
|
+
owner,
|
|
45
|
+
name,
|
|
46
|
+
version: version,
|
|
47
|
+
visibility
|
|
48
|
+
}),
|
|
49
|
+
options: { resolveStatus: [403] }
|
|
50
|
+
})
|
|
51
|
+
}
|
|
34
52
|
}
|
|
35
53
|
|
|
36
54
|
module.exports = UpdateCommand
|
|
@@ -9,7 +9,7 @@ const errorMsg = {
|
|
|
9
9
|
|
|
10
10
|
argsMustMatchFormat: 'Argument must match {{format}} format',
|
|
11
11
|
|
|
12
|
-
cannotParseDefinition: 'There was a problem with parsing {{filename}}.
|
|
12
|
+
cannotParseDefinition: 'There was a problem with parsing {{filename}}. \nReason: {{e}}',
|
|
13
13
|
|
|
14
14
|
cannotParseOasVersion: 'Cannot determine OAS version from file',
|
|
15
15
|
|
|
@@ -3,19 +3,33 @@ const { wrapTemplates } = require('../utils/general')
|
|
|
3
3
|
const infoMsg = {
|
|
4
4
|
ApiCreate: 'Created API \'{{owner}}/{{name}}\'',
|
|
5
5
|
|
|
6
|
+
ApiDelete: 'Deleted API \'{{owner}}/{{name}}\'',
|
|
7
|
+
|
|
6
8
|
DomainCreate: 'Created domain \'{{owner}}/{{name}}\'',
|
|
7
9
|
|
|
10
|
+
DomainDelete: 'Deleted domain \'{{owner}}/{{name}}\'',
|
|
11
|
+
|
|
8
12
|
createdApiVersion: 'Created version {{version}} of API \'{{owner}}/{{name}}\'',
|
|
9
13
|
|
|
10
14
|
createdDomainVersion: 'Created version {{version}} of domain \'{{owner}}/{{name}}\'',
|
|
11
15
|
|
|
16
|
+
deletedVersion: 'Deleted version {{version}} of {{type}} \'{{owner}}/{{name}}\'',
|
|
17
|
+
|
|
12
18
|
published: 'Published {{type}} {{path}}',
|
|
13
19
|
|
|
20
|
+
unpublished: 'Unpublished {{type}} {{path}}',
|
|
21
|
+
|
|
14
22
|
setDefault: 'Default version of {{owner}}/{{name}} set to {{version}}',
|
|
15
23
|
|
|
16
|
-
ApiUpdate: 'Updated API {{owner}}/{{name}}/{{version}}
|
|
24
|
+
ApiUpdate: 'Updated API {{owner}}/{{name}}/{{version}}',
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
DomainUpdate: 'Updated domain {{owner}}/{{name}}/{{version}}',
|
|
27
|
+
|
|
28
|
+
ApiUpdateVisibility: 'Updated API {{owner}}/{{name}}/{{version}} and visibility is set to {{visibility}}',
|
|
29
|
+
|
|
30
|
+
DomainUpdateVisibility: 'Updated domain {{owner}}/{{name}}/{{version}} and visibility is set to {{visibility}}',
|
|
31
|
+
|
|
32
|
+
visibilityUpdate: 'Updated visibility of {{owner}}/{{name}}/{{version}} to {{visibility}}',
|
|
19
33
|
|
|
20
34
|
ApiUnpublish: 'Unpublished API {{apiPath}}',
|
|
21
35
|
|
|
@@ -23,7 +37,28 @@ const infoMsg = {
|
|
|
23
37
|
|
|
24
38
|
IntegrationCreate: 'Created integration on API \'{{apiPath}}\'',
|
|
25
39
|
|
|
26
|
-
|
|
40
|
+
IntegrationDelete: 'Deleted integration \'{{integrationId}}\' from API \'{{apiPath}}\'',
|
|
41
|
+
|
|
42
|
+
IntegrationExecute: 'Executed integration \'{{integrationId}}\' on API \'{{apiPath}}\'',
|
|
43
|
+
|
|
44
|
+
IntegrationUpdate: 'Updated integration \'{{integrationId}}\' on API \'{{apiPath}}\'',
|
|
45
|
+
|
|
46
|
+
Configure: 'Saved config to {{configFilePath}}',
|
|
47
|
+
|
|
48
|
+
ProjectCreate: 'Created project \'{{owner}}/{{projectName}}\'',
|
|
49
|
+
|
|
50
|
+
ProjectUpdate: 'Updated project \'{{owner}}/{{projectName}}\'',
|
|
51
|
+
|
|
52
|
+
ProjectApiAdd: 'Added api \'{{apiName}}\' to project \'{{projectPath}}\'',
|
|
53
|
+
|
|
54
|
+
ProjectApiRemove: 'Removed api \'{{apiName}}\' from project \'{{projectPath}}\'',
|
|
55
|
+
|
|
56
|
+
ProjectDomainAdd: 'Added domain \'{{domainName}}\' to project \'{{projectPath}}\'',
|
|
57
|
+
|
|
58
|
+
ProjectDomainRemove: 'Removed domain \'{{domainName}}\' from project \'{{projectPath}}\'',
|
|
59
|
+
|
|
60
|
+
ProjectDelete: 'Deleted project \'{{projectPath}}\''
|
|
61
|
+
|
|
27
62
|
}
|
|
28
63
|
|
|
29
64
|
module.exports = wrapTemplates({
|
package/src/utils/oas.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { CLIError } = require('@oclif/errors')
|
|
2
2
|
const { hasJsonStructure } = require('./general')
|
|
3
|
-
const
|
|
3
|
+
const yaml = require('js-yaml')
|
|
4
4
|
const { existsSync, readFileSync } = require('fs-extra')
|
|
5
5
|
const { errorMsg } = require('../template-strings')
|
|
6
6
|
|
|
@@ -27,9 +27,9 @@ const parseDefinition = filename => {
|
|
|
27
27
|
throw new CLIError(errorMsg.fileIsEmpty({ filename }))
|
|
28
28
|
}
|
|
29
29
|
try {
|
|
30
|
-
return hasJsonStructure(file) ? JSON.parse(file) :
|
|
30
|
+
return hasJsonStructure(file) ? JSON.parse(file) : yaml.load(file)
|
|
31
31
|
} catch (e) {
|
|
32
|
-
throw new CLIError(errorMsg.cannotParseDefinition({ filename, e: JSON.stringify(e) }))
|
|
32
|
+
throw new CLIError(errorMsg.cannotParseDefinition({ filename, e: JSON.stringify(e.message).replace(/\\n/g, '\n') }))
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|