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

Function getForgeEntityFromInstance

auth/instance_middleware.go:117–152  ·  view source on GitHub ↗
(ctx context.Context, store dbCommon.Store, instance params.Instance)

Source from the content-addressed store, hash-verified

115}
116
117func getForgeEntityFromInstance(ctx context.Context, store dbCommon.Store, instance params.Instance) (params.ForgeEntity, error) {
118 var entityGetter params.EntityGetter
119 var err error
120 switch {
121 case instance.PoolID != "":
122 entityGetter, err = store.GetPoolByID(ctx, instance.PoolID)
123 case instance.ScaleSetID != 0:
124 entityGetter, err = store.GetScaleSetByID(ctx, instance.ScaleSetID)
125 default:
126 return params.ForgeEntity{}, errors.New("instance not associated with a pool or scale set")
127 }
128
129 if err != nil {
130 slog.With(slog.Any("error", err)).ErrorContext(
131 ctx, "failed to get entity getter",
132 "instance", instance.Name)
133 return params.ForgeEntity{}, fmt.Errorf("error fetching entity getter: %w", err)
134 }
135
136 poolEntity, err := entityGetter.GetEntity()
137 if err != nil {
138 slog.With(slog.Any("error", err)).ErrorContext(
139 ctx, "failed to get entity",
140 "instance", instance.Name)
141 return params.ForgeEntity{}, fmt.Errorf("error fetching entity: %w", err)
142 }
143
144 entity, err := store.GetForgeEntity(ctx, poolEntity.EntityType, poolEntity.ID)
145 if err != nil {
146 slog.With(slog.Any("error", err)).ErrorContext(
147 ctx, "failed to get entity",
148 "instance", instance.Name)
149 return params.ForgeEntity{}, fmt.Errorf("error fetching entity: %w", err)
150 }
151 return entity, nil
152}
153
154func (amw *instanceMiddleware) claimsToContext(ctx context.Context, claims *InstanceJWTClaims) (context.Context, error) {
155 if claims == nil {

Callers 2

claimsToContextMethod · 0.85
claimsToContextMethod · 0.85

Calls 4

GetEntityMethod · 0.95
GetPoolByIDMethod · 0.65
GetScaleSetByIDMethod · 0.65
GetForgeEntityMethod · 0.65

Tested by

no test coverage detected