| 1 | package runnerproto |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "time" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 8 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 9 | ) |
| 10 | |
| 11 | const ( |
| 12 | Version = 1 // Device enrolment and credential storage. |
| 13 | DirectVersion = provider.Version |
| 14 | DeviceAudience = "equipo.device.v1" |
| 15 | RunnerAudience = "equipo.runner.v1" |
| 16 | PollIntervalSeconds = 5 |
| 17 | ) |
| 18 | |
| 19 | type BeginEnrolmentRequest struct { |
| 20 | Version int `json:"version"` |
| 21 | MachinePublicKey string `json:"machine_public_key"` |
| 22 | Label string `json:"label"` |
| 23 | // WorkerOnly: the machine can only be a worker (a Mac). The instance |
| 24 | // refuses to approve it for a person with no primary runner. |
| 25 | WorkerOnly bool `json:"worker_only,omitempty"` |
| 26 | } |
| 27 | |
| 28 | type DeviceCode struct { |
| 29 | Version int `json:"version"` |
| 30 | EnrolmentID string `json:"enrolment_id"` |
| 31 | InstanceID string `json:"instance_id"` |
| 32 | DeviceSecret string `json:"device_secret"` |
| 33 | UserCode string `json:"user_code"` |
| 34 | Challenge string `json:"challenge"` |
| 35 | VerificationURI string `json:"verification_uri"` |
| 36 | ExpiresAt time.Time `json:"expires_at"` |
| 37 | PollIntervalSeconds int `json:"poll_interval_seconds"` |
| 38 | } |
| 39 | |
| 40 | type ExchangeProof struct { |
| 41 | EnrolmentID string `json:"enrolment_id"` |
| 42 | Challenge string `json:"challenge"` |
| 43 | ExchangeNonce string `json:"exchange_nonce"` |
| 44 | Signature string `json:"signature"` |
| 45 | } |
| 46 | |
| 47 | type ExchangeEnrolmentRequest struct { |
| 48 | Version int `json:"version"` |
| 49 | DeviceSecret string `json:"device_secret"` |
| 50 | Proof ExchangeProof `json:"proof"` |
| 51 | } |
| 52 | |
| 53 | type RunnerCredential struct { |
| 54 | Version int `json:"version"` |
| 55 | Token string `json:"token"` |
| 56 | TokenType string `json:"token_type"` |
| 57 | RunnerID string `json:"runner_id"` |
| 58 | CredentialID string `json:"credential_id"` |
| 59 | Person string `json:"person"` |
| 60 | ExpiresAt time.Time `json:"expires_at"` |
| 61 | // Role is "worker" for a worker (protocol 2 instances say so at |
| 62 | // enrolment); absent means primary, as an older instance's credential |
| 63 | // is. The runner keeps it with the credential. |
| 64 | Role string `json:"role,omitempty"` |
| 65 | } |
| 66 | |
| 67 | type ErrorResponse struct { |
| 68 | Version int `json:"version"` |
| 69 | Error string `json:"error"` |
| 70 | } |
| 71 | |
| 72 | const ( |
| 73 | CleanupAudience = "cleanup" |
| 74 | LongPollSeconds = 2 |
| 75 | RenewSeconds = 15 |
| 76 | MaxActionBytes = 64 << 10 |
| 77 | MaxEventBytes = 16 << 10 |
| 78 | MaxArtifactBytes = 1 << 20 |
| 79 | ) |
| 80 | |
| 81 | type ClaimRequest struct { |
| 82 | Version int `json:"version"` |
| 83 | AssignmentID string `json:"assignment_id"` |
| 84 | Revision int64 `json:"revision"` |
| 85 | RequestID string `json:"request_id"` |
| 86 | } |
| 87 | type PollRequest struct { |
| 88 | Version int `json:"version"` |
| 89 | After string `json:"after"` |
| 90 | } |
| 91 | type RunnerRequest struct { |
| 92 | ArtifactID team.ArtifactID `json:"artifact_id,omitempty"` |
| 93 | Question *Question `json:"question,omitempty"` |
| 94 | Version int `json:"version"` |
| 95 | AssignmentID string `json:"assignment_id"` |
| 96 | Scope team.Scope `json:"scope"` |
| 97 | Handle team.Handle `json:"handle"` |
| 98 | RequestID string `json:"request_id"` |
| 99 | ActionID team.ActionID `json:"action_id,omitempty"` |
| 100 | Intent *team.IntentSpec `json:"intent,omitempty"` |
| 101 | Receipt *team.Receipt `json:"receipt,omitempty"` |
| 102 | Artifact *team.ArtifactSpec `json:"artifact,omitempty"` |
| 103 | Event json.RawMessage `json:"event,omitempty"` |
| 104 | Prepared json.RawMessage `json:"prepared,omitempty"` |
| 105 | Proof json.RawMessage `json:"proof,omitempty"` |
| 106 | Result *team.AttemptResult `json:"result,omitempty"` |
| 107 | Reason team.WaitReason `json:"reason,omitempty"` |
| 108 | } |
| 109 | type WorkResponse struct { |
| 110 | Version int `json:"version"` |
| 111 | Result any `json:"result"` |
| 112 | } |
| 113 | type HeartbeatRequest struct { |
| 114 | Repositories []string `json:"repositories,omitempty"` |
| 115 | RequestID string `json:"request_id"` |
| 116 | Version int `json:"version"` |
| 117 | Reports json.RawMessage `json:"reports,omitempty"` |
| 118 | RotationRequestID string `json:"rotation_request_id,omitempty"` |
| 119 | } |
| 120 | type Delivery struct { |
| 121 | Ticket team.AdmissionTicket `json:"ticket"` |
| 122 | ReceivedAt time.Time `json:"received_at"` |
| 123 | } |
| 124 | |
| 125 | type ConnectionRouting struct { |
| 126 | BindingID, AccountID, ObservedAccountID, CredentialHomeHash string |
| 127 | AccountPinned, NoFailover, TimelineRecovery, ProcessOwnership, DedicatedUser bool |
| 128 | } |
| 129 | |
| 130 | type ConnectionReport struct { |
| 131 | SignInCommand string `json:",omitempty"` |
| 132 | OwnerMode bool `json:",omitempty"` |
| 133 | LauncherVersion, BwrapVersion, PolicyVersion string |
| 134 | TrialReady bool |
| 135 | ProviderVersionSource string |
| 136 | LocalID, Provider, ProviderVersion, PaseoVersion, Family, Model, AccountLabel, Kind, UnavailableReason, IsolationConfigHash string |
| 137 | Available, ReadIsolation, AllowanceKnown bool |
| 138 | AllowanceRemaining int64 |
| 139 | Routing ConnectionRouting |
| 140 | } |
| 141 | |
| 142 | type Selection struct { |
| 143 | ConnectionID, RunnerID, Person, Provider, Family, Model, AccountLabel, AccountID string |
| 144 | Revision, ChoiceRevision, SpecialistRevision int64 |
| 145 | Reason string |
| 146 | MaxConcurrent int |
| 147 | AllowanceKnown bool |
| 148 | AllowanceRemaining int64 |
| 149 | Isolation team.IsolationSnapshot |
| 150 | } |
| 151 | |
| 152 | type Assignment struct { |
| 153 | ID string `json:"id"` |
| 154 | TaskID string `json:"task_id"` |
| 155 | StepKey string `json:"step_key"` |
| 156 | WorkspaceKey string `json:"workspace_key"` |
| 157 | Scope Scope `json:"scope"` |
| 158 | Selection Selection `json:"selection"` |
| 159 | Revision int64 `json:"revision"` |
| 160 | Kind string `json:"kind"` |
| 161 | } |
| 162 | |
| 163 | type StepBrief struct { |
| 164 | SpecialistName, SpecialistIcon string |
| 165 | PlanRevision int64 |
| 166 | StepKey, SpecialistKey, Action string |
| 167 | SpecialistRevision int64 |
| 168 | ArtifactHashes []string |
| 169 | } |
| 170 | type SourceSnapshot struct { |
| 171 | Ref team.SourceRef `json:"ref"` |
| 172 | Payload json.RawMessage `json:"payload"` |
| 173 | } |
| 174 | type RunnerBrief struct { |
| 175 | ProjectRevision, BudgetRevision int64 |
| 176 | Step StepBrief `json:"step"` |
| 177 | Sources []SourceSnapshot `json:"sources,omitempty"` |
| 178 | RenderRecipe *RenderRecipe `json:"render_recipe,omitempty"` |
| 179 | AttemptDeadline time.Time `json:"attempt_deadline"` |
| 180 | CheckDefinition []byte `json:"check_definition"` |
| 181 | Target team.TargetBinding `json:"target"` |
| 182 | Instructions string `json:"instructions"` |
| 183 | StandingInstructions string `json:"standing_instructions"` |
| 184 | ConfirmedPreferences []string `json:"confirmed_preferences"` |
| 185 | Selection Selection `json:"selection"` |
| 186 | Policy team.Policy `json:"policy"` |
| 187 | ArtifactHashes []string `json:"artifact_hashes"` |
| 188 | } |
| 189 | |
| 190 | type ClaimResponse struct { |
| 191 | CleanupExpired bool `json:"cleanup_expired,omitempty"` |
| 192 | NotClaimed bool `json:"not_claimed,omitempty"` |
| 193 | AttemptDeadline time.Time `json:"attempt_deadline"` |
| 194 | Scope Scope `json:"scope"` |
| 195 | Handle team.Handle `json:"handle"` |
| 196 | Brief RunnerBrief `json:"brief"` |
| 197 | LeaseDeadline time.Time `json:"lease_deadline"` |
| 198 | CleanupToken string `json:"cleanup_token"` |
| 199 | CleanupExpiresAt time.Time `json:"cleanup_expires_at"` |
| 200 | RenewSeconds int `json:"renew_seconds"` |
| 201 | } |
| 202 | |
| 203 | type CredentialRotation struct { |
| 204 | Bearer RunnerCredential `json:"bearer"` |
| 205 | CleanupTokens map[string]string `json:"cleanup_tokens"` |
| 206 | } |
| 207 | |
| 208 | type Scope = team.Scope |
| 209 | |
| 210 | type PreparedBug struct { |
| 211 | Repository, DefaultBranch, BaseCommit string |
| 212 | CheckDefinition []byte |
| 213 | CheckDefinitionHash, BaselineTestSetHash string |
| 214 | } |
| 215 | |
| 216 | type CheckCommand struct { |
| 217 | Argv []string `json:"argv"` |
| 218 | Dir string `json:"dir"` |
| 219 | Parser string `json:"parser"` |
| 220 | TimeoutSeconds int `json:"timeout_seconds"` |
| 221 | } |
| 222 | type CheckFile struct { |
| 223 | Path string `json:"path"` |
| 224 | Bytes []byte `json:"bytes"` |
| 225 | } |
| 226 | type TestBaseline struct { |
| 227 | Names []team.TestIdentity `json:"names"` |
| 228 | Hash string `json:"hash"` |
| 229 | } |
| 230 | type CheckDefinition struct { |
| 231 | Render *RenderRecipe `json:"render,omitempty"` |
| 232 | TrustedPaths []string `json:"trusted_paths"` |
| 233 | Version int `json:"version"` |
| 234 | Repository string `json:"repository"` |
| 235 | Base string `json:"base"` |
| 236 | Commands []CheckCommand `json:"commands"` |
| 237 | Reproduction CheckCommand `json:"reproduction"` |
| 238 | Baseline TestBaseline `json:"baseline"` |
| 239 | Files []CheckFile `json:"files"` |
| 240 | TestFiles []string `json:"test_files"` |
| 241 | GOOS string `json:"goos"` |
| 242 | GOARCH string `json:"goarch"` |
| 243 | } |
| 244 | type Reproduction struct { |
| 245 | ExpectedSymptom string `json:"expected_symptom"` |
| 246 | Files []CheckFile `json:"files"` |
| 247 | TestNames []team.TestIdentity `json:"test_names"` |
| 248 | } |
| 249 | type BlobRequest struct { |
| 250 | Version int `json:"version"` |
| 251 | Scope team.Scope `json:"scope"` |
| 252 | Handle team.Handle `json:"handle"` |
| 253 | Digest string `json:"digest"` |
| 254 | Bytes []byte `json:"bytes"` |
| 255 | } |
| 256 | |
| 257 | type BlobReadRequest struct { |
| 258 | Version int `json:"version"` |
| 259 | Scope team.Scope `json:"scope"` |
| 260 | Digest string `json:"digest"` |
| 261 | } |
| 262 | |
| 263 | type DispatchTicket = team.AdmissionTicket |
| 264 | type PublicationAuthorization = team.PublicationAuthorization |
| 265 | |
| 266 | type RenderRecipe struct { |
| 267 | Version int `json:"version"` |
| 268 | Command CheckCommand `json:"command"` |
| 269 | } |
| 270 | |