@@ -1540,6 +1540,51 @@ func (h APIHandler) updateResource(c *gin.Context) error {
1540
1540
return nil
1541
1541
}
1542
1542
1543
+ // manualTokenPatch is used to re-submit a new token secret to the vcluster. Resources can generally
1544
+ // use a refresh token, but this can be useful if the refresh token has been invalidated.
1545
+ func (h APIHandler ) manualTokenPatch (c * gin.Context ) {
1546
+ name := c .Param ("name" )
1547
+ namespace := c .Param ("namespace" )
1548
+ clusterName := c .Param ("cluster_name" )
1549
+
1550
+ var tfoResourceSpec models.TFOResourceSpec
1551
+
1552
+ result := h .DB .Raw (`
1553
+ SELECT
1554
+ tfo_resource_specs.*
1555
+ FROM
1556
+ tfo_resource_specs
1557
+ JOIN
1558
+ tfo_resources
1559
+ ON tfo_resources.uuid = tfo_resource_specs.tfo_resource_uuid
1560
+ JOIN
1561
+ clusters
1562
+ ON clusters.id = tfo_resources.cluster_id
1563
+ WHERE clusters.name = ?
1564
+ AND tfo_resources.namespace = ?
1565
+ AND tfo_resources.name = ?
1566
+ AND tfo_resource_specs.generation = tfo_resources.current_generation
1567
+ ` , clusterName , namespace , name ).Scan (& tfoResourceSpec )
1568
+ if result .Error != nil {
1569
+ c .JSON (http .StatusUnprocessableEntity , response (http .StatusUnprocessableEntity , fmt .Sprintf ("error getting TFOResourceSpec: %v" , result .Error ), nil ))
1570
+ return
1571
+ }
1572
+ if tfoResourceSpec .ID == 0 {
1573
+ c .JSON (http .StatusNotFound , response (http .StatusNotFound , "TFOResourceSpec not found" , nil ))
1574
+ return
1575
+ }
1576
+
1577
+ apiURL := GetApiURL (c , h .serviceIP )
1578
+ _ , err := NewTaskToken (h .DB , tfoResourceSpec , h .tenant , clusterName , apiURL , h .clientset )
1579
+ if err != nil {
1580
+
1581
+ c .JSON (http .StatusUnprocessableEntity , response (http .StatusUnprocessableEntity , err .Error (), nil ))
1582
+ return
1583
+ }
1584
+
1585
+ c .JSON (http .StatusNoContent , response (http .StatusNoContent , "" , nil ))
1586
+ }
1587
+
1543
1588
// Soft deletes tfo_resources from the database except the latest one via created_at timestamp
1544
1589
func deleteTFOResourcesExceptNewest (db * gorm.DB , tfoResource * models.TFOResource ) error {
1545
1590
// A tfo resource has a namespace and a name, which are used to identify it uniquely within the cluster.
0 commit comments