MCPcopy Create free account
hub / github.com/coder/coder / workspaceQuotaDetails

Function workspaceQuotaDetails

coderd/x/chatd/chattool/quotaerror.go:94–147  ·  view source on GitHub ↗
(
	ctx context.Context,
	logger slog.Logger,
	db database.Store,
	ownerID uuid.UUID,
	organizationID uuid.UUID,
)

Source from the content-addressed store, hash-verified

92}
93
94func workspaceQuotaDetails(
95 ctx context.Context,
96 logger slog.Logger,
97 db database.Store,
98 ownerID uuid.UUID,
99 organizationID uuid.UUID,
100) *quotaErrorDetails {
101 if db == nil || ownerID == uuid.Nil || organizationID == uuid.Nil {
102 return nil
103 }
104
105 quotaCtx := ctx
106 if actor, ok := dbauthz.ActorFromContext(ctx); !ok || actor.ID != ownerID.String() {
107 ownerCtx, err := asOwner(ctx, db, ownerID)
108 if err != nil {
109 logger.Debug(ctx, "failed to load owner authorization for quota lookup",
110 slog.F("owner_id", ownerID),
111 slog.F("organization_id", organizationID),
112 slog.Error(err),
113 )
114 return nil
115 }
116 quotaCtx = ownerCtx
117 }
118
119 consumed, err := db.GetQuotaConsumedForUser(quotaCtx, database.GetQuotaConsumedForUserParams{
120 OwnerID: ownerID,
121 OrganizationID: organizationID,
122 })
123 if err != nil {
124 logger.Debug(ctx, "failed to load consumed workspace quota",
125 slog.F("owner_id", ownerID),
126 slog.F("organization_id", organizationID),
127 slog.Error(err),
128 )
129 return nil
130 }
131 budget, err := db.GetQuotaAllowanceForUser(quotaCtx, database.GetQuotaAllowanceForUserParams{
132 UserID: ownerID,
133 OrganizationID: organizationID,
134 })
135 if err != nil {
136 logger.Debug(ctx, "failed to load workspace quota allowance",
137 slog.F("owner_id", ownerID),
138 slog.F("organization_id", organizationID),
139 slog.Error(err),
140 )
141 return nil
142 }
143 return &quotaErrorDetails{
144 CreditsConsumed: consumed,
145 Budget: budget,
146 }
147}
148
149func quotaErrorToolResponse(
150 ctx context.Context,

Callers 1

quotaErrorToolResponseFunction · 0.85

Calls 6

ActorFromContextFunction · 0.92
asOwnerFunction · 0.85
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected