@@ -1178,21 +1178,8 @@ func (h *TfeHandler) DownloadStateVersion(c echo.Context) error {
11781178
11791179// UploadStateVersion handles PUT /tfe/api/v2/state-versions/:id/upload
11801180func (h * TfeHandler ) UploadStateVersion (c echo.Context ) error {
1181- fmt .Printf ("UploadStateVersion: START - Method=%s, URI=%s\n " , c .Request ().Method , c .Request ().RequestURI )
1182-
1183- // Debug: Check if Authorization header is present
1184- authHeader := c .Request ().Header .Get ("Authorization" )
1185- fmt .Printf ("UploadStateVersion: Authorization header present: %t\n " , authHeader != "" )
1186- if authHeader != "" {
1187- // Don't log the full token for security, just whether it looks like a Bearer token
1188- fmt .Printf ("UploadStateVersion: Authorization header format: %s\n " ,
1189- strings .SplitN (authHeader , " " , 2 )[0 ])
1190- }
1191-
11921181 stateVersionID := c .Param ("id" )
1193- fmt .Printf ("UploadStateVersion: stateVersionID=%s\n " , stateVersionID )
11941182 if stateVersionID == "" {
1195- fmt .Printf ("UploadStateVersion: ERROR - state_version_id required\n " )
11961183 return c .JSON (400 , map [string ]string {"error" : "state_version_id required" })
11971184 }
11981185
@@ -1209,47 +1196,37 @@ func (h *TfeHandler) UploadStateVersion(c echo.Context) error {
12091196 if err := h .checkWorkspacePermission (c , "unit.write" , workspaceID ); err != nil {
12101197 // Only enforce RBAC if we have a real auth error, not just missing headers
12111198 if ! strings .Contains (err .Error (), "no authorization header" ) {
1212- fmt .Printf ("UploadStateVersion: RBAC permission denied: %v\n " , err )
12131199 return c .JSON (http .StatusForbidden , map [string ]string {
12141200 "error" : "insufficient permissions to upload state" ,
12151201 "hint" : "contact your administrator to grant unit.write permission" ,
12161202 })
12171203 }
1218- // If no auth header, allow but log for security monitoring
1219- fmt .Printf ("UploadStateVersion: No auth header - allowing upload based on lock validation\n " )
12201204 }
12211205
12221206 // Read the state data from request body
12231207 stateData , err := io .ReadAll (c .Request ().Body )
1224- fmt .Printf ("UploadStateVersion: Read %d bytes from body, err=%v\n " , len (stateData ), err )
12251208 if err != nil {
1226- fmt .Printf ("UploadStateVersion: ERROR - Failed to read state data: %v\n " , err )
12271209 return c .JSON (400 , map [string ]string {"error" : "Failed to read state data" })
12281210 }
1229- if len (stateData ) > 0 {
1230- fmt .Printf ("UploadStateVersion: Body preview: %s\n " , string (stateData ))
1231- }
12321211
12331212 // Extract unit UUID from state ID - repository expects just the UUID
12341213 unitUUID := extractUnitUUID (stateID )
1235- fmt .Printf ("UploadStateVersion: Extracted unitUUID=%s from stateID=%s\n " , unitUUID , stateID )
12361214
1215+ // Use directStateStore for signed URL operations (pre-authorized, no RBAC checks)
12371216 // Check if state exists (no auto-creation)
1238- _ , err = h .stateStore .Get (c .Request ().Context (), unitUUID )
1217+ _ , err = h .directStateStore .Get (c .Request ().Context (), unitUUID )
12391218 if err == storage .ErrNotFound {
1240- fmt .Printf ("UploadStateVersion: Unit not found - no auto-creation\n " )
12411219 return c .JSON (404 , map [string ]string {
12421220 "error" : "Unit not found. Please create the unit first using 'taco unit create " + unitUUID + "' or the opentaco_unit Terraform resource." ,
12431221 })
12441222 } else if err != nil {
1245- fmt .Printf ("UploadStateVersion: ERROR - Failed to check state existence: %v\n " , err )
12461223 return c .JSON (500 , map [string ]string {
12471224 "error" : "Failed to check state existence" ,
12481225 })
12491226 }
12501227
12511228 // Get the current lock to extract lock ID for state upload
1252- currentLock , lockErr := h .stateStore .GetLock (c .Request ().Context (), unitUUID )
1229+ currentLock , lockErr := h .directStateStore .GetLock (c .Request ().Context (), unitUUID )
12531230 if lockErr != nil && lockErr != storage .ErrNotFound {
12541231 return c .JSON (500 , map [string ]string {"error" : "Failed to get lock status" })
12551232 }
@@ -1261,23 +1238,18 @@ func (h *TfeHandler) UploadStateVersion(c echo.Context) error {
12611238 }
12621239
12631240 // Upload the state with proper lock ID
1264- fmt .Printf ("UploadStateVersion: Uploading to storage with lockID=%s\n " , lockID )
1265- err = h .stateStore .Upload (c .Request ().Context (), unitUUID , stateData , lockID )
1266- fmt .Printf ("UploadStateVersion: Upload result, err=%v\n " , err )
1241+ err = h .directStateStore .Upload (c .Request ().Context (), unitUUID , stateData , lockID )
12671242 if err != nil {
12681243 if err == storage .ErrLockConflict {
1269- fmt .Printf ("UploadStateVersion: ERROR - Workspace is locked\n " )
12701244 return c .JSON (423 , map [string ]string {
12711245 "error" : "Workspace is locked" ,
12721246 })
12731247 }
1274- fmt .Printf ("UploadStateVersion: ERROR - Failed to upload state: %v\n " , err )
12751248 return c .JSON (500 , map [string ]string {
12761249 "error" : "Failed to upload state" ,
12771250 })
12781251 }
12791252
1280- fmt .Printf ("UploadStateVersion: SUCCESS - State uploaded successfully\n " )
12811253 // Return 204 No Content as expected by Terraform
12821254 return c .NoContent (204 )
12831255}
0 commit comments