Skip to content

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed May 1, 2021
1 parent 6ae823a commit b38c8aa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mods/ctl/src/commands/domains/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {CLIError} from "@oclif/errors";
import {Command} from "@oclif/command";
import {cli} from "cli-ux";
import {render} from "prettyjson";
import moment from "moment";
const moment = require("moment");

export default class GetCommand extends Command {
static description = "get information about an existing domain";
Expand Down
4 changes: 3 additions & 1 deletion mods/ctl/src/commands/domains/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {Command, flags as oclifFlags} from "@oclif/command";
import inquirer from "inquirer";
import {CommonPB} from "@fonos/domains";
import {Domain} from "@fonos/domains/src/types";
import Table from "easy-table";

// Using import will cause: Error: easy_table_1.default is not a constructor
const Table = require("easy-table");

export default class ListCommand extends Command {
static description = `list registered domains
Expand Down
2 changes: 1 addition & 1 deletion mods/ctl/src/commands/domains/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Domains from "@fonos/domains";
import {CLIError} from "@oclif/errors";
import {Command} from "@oclif/command";
import {cli} from "cli-ux";
import inquirer from "inquirer";
const inquirer = require("inquirer");

export default class UpdateCommand extends Command {
static args = [{name: "ref"}];
Expand Down
40 changes: 30 additions & 10 deletions mods/domains/src/service/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ import {
ResourceServer,
getAccessKeyId,
Kind,
ResourceBuilder
ResourceBuilder,
updateResource
} from "@fonos/core";
import unmarshalDomain from "./decoder";
import decoder from "./decoder";

class DomainsServer extends ResourceServer implements IDomainsServer {
async listDomains(
call: grpc.ServerUnaryCall<ListDomainsRequest>,
callback: grpc.sendUnaryData<ListDomainsResponse>
) {
// const response = super.listResources(Kind.DOMAIN, call);
// const
// callback(null, await unmarshalDomain(response))
const result = await super.listResources(Kind.DOMAIN, call);
const response = new ListDomainsResponse();
if (result.resources) {
const domains = result.resources.map((resource) => decoder(resource));
response.setNextPageToken(result.nextPageToken + "");
response.setDomainsList(domains);
}
callback(null, response);
}

async createDomain(
Expand Down Expand Up @@ -79,10 +86,13 @@ class DomainsServer extends ResourceServer implements IDomainsServer {
.withEgressPolicy(domain.getEgressRule(), domain.getEgressNumberRef())
.withACL(domain.getAccessAllowList(), domain.getAccessDenyList())
.build();
/* callback(
null,
//await updateResource(getAccessKeyId(call), resource, unmarshalDomain)
);*/

const result = await updateResource({
resource,
accessKeyId: getAccessKeyId(call)
});

callback(null, decoder(result));
} catch (e) {
callback(e, null);
}
Expand All @@ -92,14 +102,24 @@ class DomainsServer extends ResourceServer implements IDomainsServer {
call: grpc.ServerUnaryCall<GetDomainRequest>,
callback: grpc.sendUnaryData<Domain>
) {
super.getResource(Kind.DOMAIN, call);
try {
const result = await super.getResource(Kind.DOMAIN, call);
callback(null, decoder(result));
} catch (e) {
callback(e, null);
}
}

async deleteDomain(
call: grpc.ServerUnaryCall<DeleteDomainRequest>,
callback: grpc.sendUnaryData<Empty>
) {
super.deleteResource(Kind.DOMAIN, call);
try {
await super.deleteResource(Kind.DOMAIN, call);
callback(null, new Empty());
} catch (e) {
callback(e, null);
}
}
}

Expand Down

0 comments on commit b38c8aa

Please sign in to comment.