@@ -31,6 +31,7 @@ import * as CliState from "../cloud/CliState.ts";
3131import * as CliTokenManager from "../cloud/CliTokenManager.ts" ;
3232import { filterRelayResponse } from "../cloud/relayResponse.ts" ;
3333import {
34+ CLOUD_LINK_REVOKED ,
3435 CLOUD_LINKED_USER_ID ,
3536 isAgentActivityPublishingEnabledValue ,
3637 PUBLISH_AGENT_ACTIVITY_SECRET ,
@@ -140,6 +141,8 @@ interface CloudCliStatus {
140141 readonly desired : boolean ;
141142 readonly authenticated : boolean ;
142143 readonly linked : boolean ;
144+ // The relay rejected the stored link, usually after a Deregister.
145+ readonly revoked : boolean ;
143146 readonly cloudUserId : string | null ;
144147 readonly relayUrl : string | null ;
145148 readonly publishAgentActivity : boolean ;
@@ -176,18 +179,22 @@ function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: b
176179 return JSON . stringify ( status , null , 2 ) ;
177180 }
178181
179- const provisioned = status . linked
180- ? "provisioned"
181- : status . desired && status . authenticated
182- ? "pending server startup"
183- : "not provisioned" ;
182+ const provisioned = status . revoked
183+ ? "removed from T3 Connect"
184+ : status . linked
185+ ? "provisioned"
186+ : status . desired && status . authenticated
187+ ? "pending server startup"
188+ : "not provisioned" ;
184189 const nextStep = ! status . authenticated
185190 ? "Run `t3 connect link` to authorize and enable T3 Connect."
186- : ! status . desired
187- ? "Run `t3 connect link` to enable T3 Connect."
188- : ! status . linked
189- ? "Start T3 to provision the environment link and launch its managed tunnel."
190- : undefined ;
191+ : status . revoked
192+ ? "Run `t3 connect link` to link this environment again."
193+ : ! status . desired
194+ ? "Run `t3 connect link` to enable T3 Connect."
195+ : ! status . linked
196+ ? "Start T3 to provision the environment link and launch its managed tunnel."
197+ : undefined ;
191198
192199 return [
193200 "T3 Connect" ,
@@ -477,6 +484,11 @@ const linkEnvironmentForConnect = Effect.fn("cloud.cli.link_environment")(functi
477484
478485 const identity = yield * authorizeCli ( options ) ;
479486 yield * CliState . setCliDesiredCloudLink ( true , publishOnly ? "publish_only" : "managed" ) ;
487+ if ( yield * CliState . dropRevokedCloudLink ) {
488+ yield * Console . log (
489+ "Removed the link T3 Connect no longer accepts. The next start links this environment again." ,
490+ ) ;
491+ }
480492 if ( publishOnly ) {
481493 const secrets = yield * ServerSecretStore . ServerSecretStore ;
482494 yield * secrets . set ( PUBLISH_AGENT_ACTIVITY_SECRET , stringToBytes ( "true" ) ) ;
@@ -543,22 +555,31 @@ const connectStatusCommand = Command.make("status", {
543555 const secrets = yield * ServerSecretStore . ServerSecretStore ;
544556 const relayClient = yield * RelayClient . RelayClient ;
545557 const tokens = yield * CliTokenManager . CloudCliTokenManager ;
546- const [ desired , authenticated , cloudUserId , relayUrl , publishAgentActivity , executable ] =
547- yield * Effect . all (
548- [
549- CliState . readCliDesiredCloudLink ,
550- tokens . hasCredential ,
551- secrets . get ( CLOUD_LINKED_USER_ID ) ,
552- secrets . get ( RELAY_URL_SECRET ) ,
553- secrets . get ( PUBLISH_AGENT_ACTIVITY_SECRET ) ,
554- relayClient . resolve ,
555- ] ,
556- { concurrency : "unbounded" } ,
557- ) ;
558+ const [
559+ desired ,
560+ authenticated ,
561+ cloudUserId ,
562+ relayUrl ,
563+ publishAgentActivity ,
564+ revoked ,
565+ executable ,
566+ ] = yield * Effect . all (
567+ [
568+ CliState . readCliDesiredCloudLink ,
569+ tokens . hasCredential ,
570+ secrets . get ( CLOUD_LINKED_USER_ID ) ,
571+ secrets . get ( RELAY_URL_SECRET ) ,
572+ secrets . get ( PUBLISH_AGENT_ACTIVITY_SECRET ) ,
573+ secrets . get ( CLOUD_LINK_REVOKED ) ,
574+ relayClient . resolve ,
575+ ] ,
576+ { concurrency : "unbounded" } ,
577+ ) ;
558578 const status : CloudCliStatus = {
559579 desired,
560580 authenticated,
561581 linked : Option . isSome ( cloudUserId ) ,
582+ revoked : Option . isSome ( cloudUserId ) && Option . isSome ( revoked ) ,
562583 cloudUserId : Option . isSome ( cloudUserId ) ? bytesToString ( cloudUserId . value ) : null ,
563584 relayUrl : Option . isSome ( relayUrl ) ? bytesToString ( relayUrl . value ) : null ,
564585 publishAgentActivity : isAgentActivityPublishingEnabledValue (
0 commit comments