Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish registry-cli version 1.6.7 #239

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions tools/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
{
"name": "registry-cli",
"version": "1.6.6",
"version": "1.6.7",
"description": "A CLI to setup and manage Sunbird RC registry instances",
"author": "Vedant K <https://github.com/gamemaker1>",
"keywords": ["registry-cli", "sbrc", "sb-rc", "sunbird-rc", "verifiable-credentials", "registry"],
"author": "Sunbird-RC <https://github.com/Sunbird-RC>",
"keywords": [
"registry-cli",
"sbrc",
"sb-rc",
"sunbird-rc",
"verifiable-credentials",
"registry"
],
"contributors": [
{
"name": "Tejash JL",
"url": "https://github.com/tejash-jl"
},
{
"name": "Prasanna Raghu",
"url": "https://github.com/srprasanna"
}
],
"license": "MIT",
Expand All @@ -30,12 +41,12 @@
"scripts": {
"clean": "del out",
"copy-templates": "cp -r src/templates out/src",
"compile": "pnpm clean && tsc -p .",
"compile": "npm run clean && tsc -p .",
"watch": "tsc -w -p .",
"build": "pnpm compile && pnpm copy-templates",
"build": "npm run compile && npm run copy-templates",
"lint": "prettier -w . --ignore-path .gitignore",
"test": "prettier -c . --ignore-path .gitignore",
"prepare": "pnpm build"
"prepare": "npm run build"
},
"dependencies": {
"@types/node": "16.11.21",
Expand Down
116 changes: 59 additions & 57 deletions tools/cli/src/commands/down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,65 @@

import path from 'path'

import {RegistryTearDownOptions, Toolbox} from '../types'
import { RegistryTearDownOptions, Toolbox } from '../types'

export default {
name: 'down',
run: async (toolbox: Toolbox) => {
const {
environment,
events,
filesystem,
print,
prompt,
registry,
strings,
handleEvent
} = toolbox


events.on('environment.check', handleEvent)
events.on('registry.down', handleEvent)

// Print the title
print.info('')
print.info(print.colors.green.bold('Registry Teardown'))
print.info('')

// Check that all tools are installed
await environment.check()


// Check if a registry already exists in the current directory
if (
!await filesystem.existsAsync(path.resolve(process.cwd(), 'registry.yaml'))
) {
events.emit('registry.create', {
status: 'error',
operation: 'checking-env',
message: `A registry has not been setup in the current directory.`,
})
}

// Get necessary information
print.info('')
const options: RegistryTearDownOptions = await prompt.ask([
{
type: 'input',
message: print.colors.reset('Do you really want to stop and remove the containers?'),
name: 'stopConfirmation',
initial: "Y/N",
required: true
}
])
print.info(options.stopConfirmation)
if (options.stopConfirmation === "Y" || options.stopConfirmation === "y") {
await registry.down()
} else {
print.error("Invalid option")
}
print.info('')
},
name: 'down',
run: async (toolbox: Toolbox) => {
const {
environment,
events,
filesystem,
print,
prompt,
registry,
strings,
handleEvent,
} = toolbox

events.on('environment.check', handleEvent)
events.on('registry.down', handleEvent)

// Print the title
print.info('')
print.info(print.colors.green.bold('Registry Teardown'))
print.info('')

// Check that all tools are installed
await environment.check()

// Check if a registry already exists in the current directory
if (
!(await filesystem.existsAsync(
path.resolve(process.cwd(), 'registry.yaml')
))
) {
events.emit('registry.create', {
status: 'error',
operation: 'checking-env',
message: `A registry has not been setup in the current directory.`,
})
}

// Get necessary information
print.info('')
const options: RegistryTearDownOptions = await prompt.ask([
{
type: 'input',
message: print.colors.reset(
'Do you really want to stop and remove the containers?'
),
name: 'stopConfirmation',
initial: 'Y/N',
required: true,
},
])
print.info(options.stopConfirmation)
if (options.stopConfirmation === 'Y' || options.stopConfirmation === 'y') {
await registry.down()
} else {
print.error('Invalid option')
}
print.info('')
},
}
70 changes: 35 additions & 35 deletions tools/cli/src/commands/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@
// `registry health` command
// Shows the health of all containers of the registry instance

import {RegistryHealth, Toolbox} from '../types'
import { RegistryHealth, Toolbox } from '../types'

export default {
name: 'health',
run: async (toolbox: Toolbox) => {
const {environment, events, print, registry, handleEvent} = toolbox
events.on('environment.check', handleEvent)
events.on('registry.health', handleEvent)
// Check that all tools are installed
await environment.check(process.cwd())
// Get the registry health
const containers = await registry.health()
// Print the name of the registry
print.info('')
print.info(print.colors.green.bold((await registry.config()).name))
print.info('')
// Print the container details as a table
print.table(
[
['Name', 'Health', "Error"],
...containers.map((container: RegistryHealth) => [
print.colors.green(container.name),
print.colors.cyan(container.status),
print.colors.cyan(container.err)
]),
],
{
format: 'markdown',
}
)
print.info('')
},
name: 'health',
run: async (toolbox: Toolbox) => {
const { environment, events, print, registry, handleEvent } = toolbox

events.on('environment.check', handleEvent)
events.on('registry.health', handleEvent)

// Check that all tools are installed
await environment.check(process.cwd())
// Get the registry health
const containers = await registry.health()

// Print the name of the registry
print.info('')
print.info(print.colors.green.bold((await registry.config()).name))
print.info('')

// Print the container details as a table
print.table(
[
['Name', 'Health', 'Error'],
...containers.map((container: RegistryHealth) => [
print.colors.green(container.name),
print.colors.cyan(container.status),
print.colors.cyan(container.err),
]),
],
{
format: 'markdown',
}
)

print.info('')
},
}
8 changes: 5 additions & 3 deletions tools/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default {
prompt,
registry,
strings,
handleEvent
handleEvent,
} = toolbox

events.on('environment.check', handleEvent)
events.on('registry.create', handleEvent)

Expand Down Expand Up @@ -116,6 +116,8 @@ export default {
await registry.create(options as unknown as RegistrySetupOptions)

print.info('')
print.highlight('Sunbird-RC is configured with test/default keys for signing. It is required to be updated `imports/config.json` before going live/production')
print.highlight(
'Sunbird-RC is configured with test/default keys for signing. It is required to be updated `imports/config.json` before going live/production'
)
},
}
3 changes: 2 additions & 1 deletion tools/cli/src/commands/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { CLIEvent, Toolbox } from '../types'
export default {
name: 'restart',
run: async (toolbox: Toolbox) => {
const { environment, events, parameters, print, registry, handleEvent } = toolbox
const { environment, events, parameters, print, registry, handleEvent } =
toolbox

// Listen to events and show progress

Expand Down
19 changes: 12 additions & 7 deletions tools/cli/src/extensions/cli-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import restart from '../toolbox/registry/restart'
import down from '../toolbox/registry/down'
import health from '../toolbox/registry/health'

import {CLIEvent, RegistryConfiguration, RegistrySetupOptions, Toolbox} from '../types'
import {
CLIEvent,
RegistryConfiguration,
RegistrySetupOptions,
Toolbox,
} from '../types'

export default (toolbox: Toolbox) => {
// Event emmitter
Expand Down Expand Up @@ -52,7 +57,7 @@ export default (toolbox: Toolbox) => {
down: () => down(toolbox),
health: () => health(toolbox),
}
const {print} = toolbox;
const { print } = toolbox
const spinner = print.spin('Loading...').stop()
toolbox.handleEvent = (event: CLIEvent) => {
// Print and exit on error
Expand All @@ -65,11 +70,11 @@ export default (toolbox: Toolbox) => {
// Else just print the message
print.error(print.colors.error(`${print.xmark} ${event.message}`))
}

print.error('')
process.exit(1)
}

// Print and continue on success
if (event.status === 'success') {
// Stop the spinner if it is running...
Expand All @@ -83,19 +88,19 @@ export default (toolbox: Toolbox) => {
)
}
}

// If it is a progress event, show a spinner
if (event.status === 'progress') {
spinner.start(print.colors.highlight(`${event.message}...`))
}
}

toolbox.until = async (conditionFunction: () => Promise<boolean>) => {
const poll = async (resolve: (value: unknown) => void) => {
if (await conditionFunction()) resolve(true)
else setTimeout((_) => poll(resolve), 400)
}

return new Promise(poll)
}

Expand Down
2 changes: 1 addition & 1 deletion tools/cli/src/templates/config/keycloak/realm-export.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
"requiredActions": [],
"realmRoles": ["default-roles-<%= props.realmName %>"],
"clientRoles": {
"realm-management": ["manage-users","manage-realm"]
"realm-management": ["manage-users", "manage-realm"]
},
"notBefore": 0,
"groups": []
Expand Down
Loading