Skip to content

Commit b0cdbd0

Browse files
committed
impr: don't store file content in state
1 parent 36a3758 commit b0cdbd0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

provider/file_resource.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (r *fileResource) Schema(ctx context.Context, req resource.SchemaRequest, r
9494
Sensitive: true, // define as sensitive, because content could be + avoid printing it
9595
PlanModifiers: []planmodifier.String{
9696
stringplanmodifier.RequiresReplace(),
97+
stringplanmodifier.UseStateForUnknown(),
9798
},
9899
},
99100
},
@@ -162,6 +163,9 @@ func (r *fileResource) Create(ctx context.Context, req resource.CreateRequest, r
162163
data.SHA1Sum = types.StringValue(res[0].SHA1sum)
163164
data.Location = types.StringValue(res[0].Location)
164165

166+
// Nullify content so it doesn’t go into state
167+
data.ContentB64 = types.StringNull()
168+
165169
if resp.Diagnostics.HasError() {
166170
return
167171
}
@@ -192,18 +196,18 @@ func (r *fileResource) Read(ctx context.Context, req resource.ReadRequest, resp
192196
return
193197
}
194198

195-
content, err := r.client.GetFileContent(&api.File{
196-
Location: res.Location,
197-
}, api.WithContext(ctx))
198-
if err != nil {
199-
resp.Diagnostics.AddError(
200-
"CTFd Error",
201-
fmt.Sprintf("Unable to read file at location %s, got error: %s", res.Location, err),
202-
)
203-
return
204-
}
199+
// content, err := r.client.GetFileContent(&api.File{
200+
// Location: res.Location,
201+
// }, api.WithContext(ctx))
202+
// if err != nil {
203+
// resp.Diagnostics.AddError(
204+
// "CTFd Error",
205+
// fmt.Sprintf("Unable to read file at location %s, got error: %s", res.Location, err),
206+
// )
207+
// return
208+
// }
205209

206-
data.ContentB64 = types.StringValue(base64.StdEncoding.EncodeToString(content))
210+
// data.ContentB64 = types.StringValue(base64.StdEncoding.EncodeToString(content))
207211

208212
if resp.Diagnostics.HasError() {
209213
return

0 commit comments

Comments
 (0)