] * : A note shown beside the key in the panel. * * ## EXAMPLES * * TOKEN="$(wp csdt edge pair --label=qa)" */ public function pair( $args, $assoc_args ): void { $r = CSDT_Edge_Gateway::pair( (string) ( $assoc_args['label'] ?? '' ) ); if ( ! $r['ok'] ) { WP_CLI::error( $r['error'] ); return; } WP_CLI::line( $r['token'] ); } /** * Unpair gateway keys. Their tokens stop working at once. * * ## OPTIONS * * [...] * : Key ids to unpair. * * [--all] * : Unpair every key. * * ## EXAMPLES * * wp csdt edge unpair --all * wp csdt edge unpair gw3f9a1c0b7e */ public function unpair( $args, $assoc_args ): void { if ( ! empty( $assoc_args['all'] ) ) { $ids = CSDT_Edge_Gateway::unpair_all(); WP_CLI::success( array() === $ids ? 'No gateway was paired.' : 'Unpaired ' . implode( ', ', $ids ) . '.' ); return; } if ( array() === $args ) { WP_CLI::error( 'Name the key id(s) to unpair, or pass --all.' ); return; } $missing = array(); foreach ( $args as $id ) { if ( ! CSDT_Edge_Gateway::unpair( (string) $id ) ) { $missing[] = (string) $id; } } if ( array() !== $missing ) { WP_CLI::error( 'Not paired: ' . implode( ', ', $missing ) . '.' ); return; } WP_CLI::success( 'Unpaired ' . implode( ', ', $args ) . '.' ); } /** * Show the paired key ids, the modes and the last heartbeat. * * ## OPTIONS * * [--format=] * : Render format. * --- * default: table * options: * - table * - json * --- * * ## EXAMPLES * * wp csdt edge status * wp csdt edge status --format=json */ public function status( $args, $assoc_args ): void { $st = CSDT_Edge_Gateway::status_summary(); if ( 'json' === ( $assoc_args['format'] ?? 'table' ) ) { WP_CLI::line( (string) wp_json_encode( $st ) ); return; } $when = static fn( int $t ): string => $t > 0 ? gmdate( 'Y-m-d H:i:s', $t ) . ' UTC' : 'never'; if ( array() === $st['keys'] ) { WP_CLI::line( 'Paired: none (the edge routes answer not_paired).' ); } else { $rows = array(); foreach ( $st['keys'] as $k ) { $rows[] = array( 'key_id' => $k['key_id'], 'label' => $k['label'], 'paired' => $when( (int) $k['paired'] ), 'last_state' => $when( (int) $k['last_state'] ), 'last_events' => $when( (int) $k['last_events'] ), 'secret' => $k['readable'] ? 'readable' : 'UNREADABLE on this copy, re-pair', ); } WP_CLI\Utils\format_items( 'table', $rows, array( 'key_id', 'label', 'paired', 'last_state', 'last_events', 'secret' ) ); } $modes = array(); foreach ( $st['modes'] as $f => $m ) { $modes[] = $f . '=' . $m; } WP_CLI::line( 'Modes: ' . implode( ' ', $modes ) . ( $st['uploads_confirmed'] ? '' : ' (upload paths not confirmed, so shape cannot block)' ) ); WP_CLI::line( 'Last heartbeat: ' . $when( (int) $st['last_heartbeat'] ) ); } }