MCPcopy Create free account
hub / github.com/cloudbase/garm / handleEntityCredentialsEventPayload

Method handleEntityCredentialsEventPayload

workers/entity/worker_watcher.go:77–114  ·  view source on GitHub ↗
(event dbCommon.ChangePayload)

Source from the content-addressed store, hash-verified

75}
76
77func (w *Worker) handleEntityCredentialsEventPayload(event dbCommon.ChangePayload) {
78 var creds params.ForgeCredentials
79 var ok bool
80 switch event.EntityType {
81 case dbCommon.GithubCredentialsEntityType, dbCommon.GiteaCredentialsEntityType:
82 creds, ok = event.Payload.(params.ForgeCredentials)
83 default:
84 slog.ErrorContext(w.ctx, "invalid entity type", "entity_type", event.EntityType)
85 return
86 }
87 if !ok {
88 slog.ErrorContext(w.ctx, "invalid payload for entity type", "entity_type", event.EntityType, "payload", event.Payload)
89 return
90 }
91
92 switch event.Operation {
93 case dbCommon.UpdateOperation:
94 slog.DebugContext(w.ctx, "got delete operation")
95 w.mux.Lock()
96 defer w.mux.Unlock()
97 if w.Entity.Credentials.GetID() != creds.GetID() {
98 // The channel is buffered. We may get an old update. If credentials get updated
99 // immediately after they are swapped on the entity, we may still get an update
100 // pushed to the channel before the filters are swapped. We can ignore the update.
101 return
102 }
103 w.Entity.Credentials = creds
104 ghCli, err := github.Client(w.ctx, w.Entity)
105 if err != nil {
106 slog.ErrorContext(w.ctx, "creating github client", "entity_id", w.Entity.ID, "error", err)
107 return
108 }
109 w.ghCli = ghCli
110 cache.SetGithubClient(w.Entity.ID, ghCli)
111 default:
112 slog.ErrorContext(w.ctx, "invalid operation type", "operation_type", event.Operation)
113 }
114}

Callers 1

Calls 6

GetIDMethod · 0.95
ClientFunction · 0.92
SetGithubClientFunction · 0.92
LockMethod · 0.65
UnlockMethod · 0.65
GetIDMethod · 0.65

Tested by

no test coverage detected