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

feat(cli): impl website command #854

Merged
merged 2 commits into from
Mar 6, 2023
Merged
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
2 changes: 1 addition & 1 deletion cli/src/action/storage/s3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as AWS from 'aws-sdk'
require("aws-sdk/lib/maintenance_mode_message").suppress = true;
require('aws-sdk/lib/maintenance_mode_message').suppress = true

export function getS3Client(credentials: any) {
return new AWS.S3({
Expand Down
85 changes: 85 additions & 0 deletions cli/src/action/website/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { websiteControllerBindDomain, websiteControllerCreate, websiteControllerFindAll, websiteControllerRemove } from "../../api/v1/websitehosting"
import { readApplicationConfig } from "../../config/application"
import * as Table from 'cli-table3'
import { formatDate } from "../../util/format"
import { BindCustomDomainDto, CreateWebsiteDto } from "../../api/v1/data-contracts"
import { getEmoji } from "../../util/print"


export async function list() {
const appConfig = readApplicationConfig()
const websites = await websiteControllerFindAll(appConfig.appid)
const table = new Table({
head: ['bucketName', 'domain', 'state', 'updatedAt'],
})
for (let item of websites) {
table.push([item.bucketName, item.domain, item.state, formatDate(item.updatedAt),])
}
console.log(table.toString())
}

export async function create(bucketName: string, options: any) {
const appConfig = readApplicationConfig()

if (!bucketName.startsWith(appConfig.appid + '-')) {
bucketName = appConfig.appid + '-' + bucketName
}

const createDto: CreateWebsiteDto = {
bucketName,
state: 'Active',
}
const website = await websiteControllerCreate(appConfig.appid, createDto)

if (options) { }

console.log(`${getEmoji('✅')} create website success!`)
console.log(`You can access through this domain: ${website.domain}`)
}

export async function del(bucketName: string, options: any) {
const appConfig = readApplicationConfig()
const websites = await websiteControllerFindAll(appConfig.appid)

if (options) {
}

if (!bucketName.startsWith(appConfig.appid + '-')) {
bucketName = appConfig.appid + '-' + bucketName
}

const targetId = websites.find((item) => item.bucketName === bucketName)?.id
if (!targetId) {
console.log(`${getEmoji('❌')} website ${bucketName} not found`)
return
}
await websiteControllerRemove(appConfig.appid, targetId)

console.log(`${getEmoji('✅')} delete website success!`)
}

export async function custom(bucketName: string, domain: string, options: any) {
const appConfig = readApplicationConfig()
const websites = await websiteControllerFindAll(appConfig.appid)

if (options) {
}

if (!bucketName.startsWith(appConfig.appid + '-')) {
bucketName = appConfig.appid + '-' + bucketName
}

const targetId = websites.find((item) => item.bucketName === bucketName)?.id
if (!targetId) {
console.log(`${getEmoji('❌')} website ${bucketName} not found`)
return
}

const patchDto: BindCustomDomainDto = {
domain,
}
const website = await websiteControllerBindDomain(appConfig.appid, targetId, patchDto)

console.log(`${getEmoji('✅')} bind custom success!`)
console.log(`You can access through this domain: ${website.domain}`)
}
4 changes: 2 additions & 2 deletions cli/src/api/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'
import axios, { InternalAxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'
import * as urlencode from 'urlencode'

export async function invokeFunction(
Expand Down Expand Up @@ -26,7 +26,7 @@ const request = axios.create({

// request interceptor
request.interceptors.request.use(
(config: AxiosRequestConfig) => {
(config: InternalAxiosRequestConfig) => {
let _headers: AxiosRequestHeaders | any = {
'Content-Type': 'application/json',
}
Expand Down
8 changes: 5 additions & 3 deletions cli/src/api/v1/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CreateApplicationDto,
CreateDependencyDto,
CreateEnvironmentDto,
DeleteDependencyDto,
UpdateApplicationDto,
UpdateDependencyDto,
} from './data-contracts'
Expand Down Expand Up @@ -229,17 +230,18 @@ export async function dependencyControllerGetDependencies(
* @tags Application
* @name DependencyControllerRemove
* @summary Remove a dependency
* @request DELETE:/v1/apps/{appid}/dependencies/{name}
* @request DELETE:/v1/apps/{appid}/dependencies
* @secure
*/
export async function dependencyControllerRemove(
appid: string,
name: string,
data: DeleteDependencyDto,
configParams: RequestParams = {},
): Promise<any> {
return request({
url: `/v1/apps/${appid}/dependencies/${name}`,
url: `/v1/apps/${appid}/dependencies`,
method: 'DELETE',
data: data,
...configParams,
})
}
25 changes: 12 additions & 13 deletions cli/src/api/v1/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface CreateApplicationDto {

export interface UpdateApplicationDto {
name?: string
state?: 'Running' | 'Stopped' | 'Restarting'
state?: 'Running' | 'Stopped' | 'Restarting' | 'Deleted'
}

export interface CreateEnvironmentDto {
Expand Down Expand Up @@ -91,9 +91,14 @@ export interface UpdatePolicyRuleDto {
value: string
}

export type CreateWebsiteDto = object
export interface CreateWebsiteDto {
bucketName: string
state: string
}

export type UpdateWebsiteDto = object
export interface BindCustomDomainDto {
domain: string
}

export interface Pat2TokenDto {
/**
Expand Down Expand Up @@ -142,6 +147,10 @@ export interface UpdateDependencyDto {
spec: string
}

export interface DeleteDependencyDto {
name: string
}

export interface CreateTriggerDto {
desc: string
cron: string
Expand All @@ -162,16 +171,6 @@ export type RegionControllerGetRegionsData = any

export type DatabaseControllerProxyData = any

export type WebsitesControllerCreateData = any

export type WebsitesControllerFindAllData = any

export type WebsitesControllerFindOneData = any

export type WebsitesControllerUpdateData = any

export type WebsitesControllerRemoveData = any

export interface AuthControllerCode2TokenParams {
code: string
}
Expand Down
113 changes: 0 additions & 113 deletions cli/src/api/v1/website.ts

This file was deleted.

Loading