Skip to content

Commit

Permalink
env updates
Browse files Browse the repository at this point in the history
  • Loading branch information
shadrach-tayo committed Nov 25, 2024
1 parent 8f6cf1a commit e4ca21e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions desci-repo/kubernetes/deployment_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spec:
export DATABASE_URL={{ .Data.DATABASE_URL }}
export IPFS_RESOLVER_OVERRIDE={{ .Data.IPFS_RESOLVER_OVERRIDE }}
export DESCI_SERVER_URL={{ .Data.DESCI_SERVER_URL }}
export PARTY_SERVER_URL={{ .Data.PARTY_SERVER_URL }}
export PARTY_SERVER_TOKEN={{ .Data.PARTY_SERVER_TOKEN }}
export PINO_LOG_LEVEL=info
{{- end -}}
labels:
Expand Down
2 changes: 2 additions & 0 deletions desci-repo/kubernetes/deployment_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
export DATABASE_URL={{ .Data.DATABASE_URL }}
export IPFS_RESOLVER_OVERRIDE={{ .Data.IPFS_RESOLVER_OVERRIDE }}
export DESCI_SERVER_URL={{ .Data.DESCI_SERVER_URL }}
export PARTY_SERVER_URL={{ .Data.PARTY_SERVER_URL }}
export PARTY_SERVER_TOKEN={{ .Data.PARTY_SERVER_TOKEN }}
export PINO_LOG_LEVEL=info
{{- end -}}
labels:
Expand Down
2 changes: 2 additions & 0 deletions desci-repo/kubernetes/deployment_staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
export DATABASE_URL={{ .Data.DATABASE_URL }}
export IPFS_RESOLVER_OVERRIDE={{ .Data.IPFS_RESOLVER_OVERRIDE }}
export DESCI_SERVER_URL={{ .Data.DESCI_SERVER_URL }}
export PARTY_SERVER_URL={{ .Data.PARTY_SERVER_URL }}
export PARTY_SERVER_TOKEN={{ .Data.PARTY_SERVER_TOKEN }}
export PINO_LOG_LEVEL=info
{{- end -}}
labels:
Expand Down
2 changes: 1 addition & 1 deletion desci-repo/src/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const isDev = process.env.NODE_ENV == 'dev';
const isTest = process.env.NODE_ENV == 'test';

if (!(partyServerToken && partyServerHost)) {
throw new Error('Missing ENVIRONMENT variables: AUTOMERGE_PARTY_URL or AUTOMERGE_PARTY_TOKEN');
throw new Error('Missing ENVIRONMENT variables: PARTY_SERVER_URL or PARTY_SERVER_TOKEN');
}

const logger = parentLogger.child({ module: 'repo.ts' });
Expand Down
11 changes: 5 additions & 6 deletions sync-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AutomergeServer extends PartyServer {
// };

repo: Repo;
private AUTH_SECRET: string;
private API_TOKEN: string;
private DATABASE_URL: string;
private environment: string;

Expand All @@ -33,7 +33,7 @@ export class AutomergeServer extends PartyServer {
const localDbUrl =
this.env.DATABASE_URL ?? process.env.WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_NODES_DB ?? '<DATABASE_URL>';
this.DATABASE_URL = this.environment === 'dev' ? localDbUrl : this.env.NODES_DB.connectionString;
this.AUTH_SECRET = env.API_TOKEN || 'auth-token';
this.API_TOKEN = env.API_TOKEN || 'auth-token';
}

async onStart(): Promise<void> {
Expand All @@ -60,7 +60,7 @@ export class AutomergeServer extends PartyServer {
const auth = params.get('auth');
let isAuthorised = false;

if (auth === this.AUTH_SECRET) {
if (auth === this.API_TOKEN) {
isAuthorised = true;
} else {
// Add default for missing NODES_API in workered container runtime
Expand All @@ -74,25 +74,24 @@ export class AutomergeServer extends PartyServer {
if (response.ok) isAuthorised = true;
}

console.log('onConnect', { isAuthorised, id: connection.id, server: connection.server });
if (isAuthorised) {
this.repo.networkSubsystem.addNetworkAdapter(new PartyKitWSServerAdapter(connection));
} else {
console.log('Auth declined', { id: connection.id, server: connection.server });
connection.close();
}
}

onMessage(connection: Connection, message: WSMessage): void | Promise<void> {
this.broadcast(message, [connection.id]);
// console.log('[peers]:', this.repo.peers);
}

onError(connection: Connection, error: unknown): void | Promise<void> {
console.log('[Error]:', { id: connection.id, error: serialiseErr(error as Error) });
}

onClose(connection: Connection, code: number, reason: string, wasClean: boolean): void | Promise<void> {
console.log('[close]:', { id: connection.id, url: connection.url, documentId: connection.server });
console.info('[close]:', { id: connection.id, url: connection.url, documentId: connection.server });
try {
connection.close();
} catch (err) {
Expand Down

0 comments on commit e4ca21e

Please sign in to comment.