mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-28 10:51:44 +01:00 
			
		
		
		
	Apply suggestions from code review
Renamed AlreadyUsed to Used Co-authored-by: Kristoffer Dalby <kradalby@kradalby.no>
This commit is contained in:
		
							parent
							
								
									30788e1a70
								
							
						
					
					
						commit
						93517aa6f8
					
				
							
								
								
									
										2
									
								
								api.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								api.go
									
									
									
									
									
								
							| @ -395,7 +395,7 @@ func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key, | |||||||
| 	m.RegisterMethod = "authKey" | 	m.RegisterMethod = "authKey" | ||||||
| 	db.Save(&m) | 	db.Save(&m) | ||||||
| 
 | 
 | ||||||
| 	pak.AlreadyUsed = true | 	pak.Used = true | ||||||
| 	db.Save(&pak) | 	db.Save(&pak) | ||||||
| 
 | 
 | ||||||
| 	resp.MachineAuthorized = true | 	resp.MachineAuthorized = true | ||||||
|  | |||||||
| @ -57,7 +57,7 @@ var listPreAuthKeys = &cobra.Command{ | |||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		d := pterm.TableData{{"ID", "Key", "Reusable", "Ephemeral", "AlreadyUsed", "Expiration", "Created"}} | 		d := pterm.TableData{{"ID", "Key", "Reusable", "Ephemeral", "Used", "Expiration", "Created"}} | ||||||
| 		for _, k := range *keys { | 		for _, k := range *keys { | ||||||
| 			expiration := "-" | 			expiration := "-" | ||||||
| 			if k.Expiration != nil { | 			if k.Expiration != nil { | ||||||
| @ -76,7 +76,7 @@ var listPreAuthKeys = &cobra.Command{ | |||||||
| 				k.Key, | 				k.Key, | ||||||
| 				reusable, | 				reusable, | ||||||
| 				strconv.FormatBool(k.Ephemeral), | 				strconv.FormatBool(k.Ephemeral), | ||||||
| 				fmt.Sprintf("%v", k.AlreadyUsed), | 				fmt.Sprintf("%v", k.Used), | ||||||
| 				expiration, | 				expiration, | ||||||
| 				k.CreatedAt.Format("2006-01-02 15:04:05"), | 				k.CreatedAt.Format("2006-01-02 15:04:05"), | ||||||
| 			}) | 			}) | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ type PreAuthKey struct { | |||||||
| 	Namespace   Namespace | 	Namespace   Namespace | ||||||
| 	Reusable    bool | 	Reusable    bool | ||||||
| 	Ephemeral   bool `gorm:"default:false"` | 	Ephemeral   bool `gorm:"default:false"` | ||||||
| 	AlreadyUsed bool `gorm:"default:false"` | 	Used bool `gorm:"default:false"` | ||||||
| 
 | 
 | ||||||
| 	CreatedAt  *time.Time | 	CreatedAt  *time.Time | ||||||
| 	Expiration *time.Time | 	Expiration *time.Time | ||||||
| @ -111,7 +111,7 @@ func (h *Headscale) checkKeyValidity(k string) (*PreAuthKey, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if len(machines) != 0 || pak.AlreadyUsed { | 	if len(machines) != 0 || pak.Used { | ||||||
| 		return nil, errorAuthKeyNotReusableAlreadyUsed | 		return nil, errorAuthKeyNotReusableAlreadyUsed | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -181,13 +181,13 @@ func (*Suite) TestExpirePreauthKey(c *check.C) { | |||||||
| 	c.Assert(p, check.IsNil) | 	c.Assert(p, check.IsNil) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (*Suite) TestNotReusableMarkedAsAlreadyUsed(c *check.C) { | func (*Suite) TestNotReusableMarkedAsUsed(c *check.C) { | ||||||
| 	n, err := h.CreateNamespace("test6") | 	n, err := h.CreateNamespace("test6") | ||||||
| 	c.Assert(err, check.IsNil) | 	c.Assert(err, check.IsNil) | ||||||
| 
 | 
 | ||||||
| 	pak, err := h.CreatePreAuthKey(n.Name, false, false, nil) | 	pak, err := h.CreatePreAuthKey(n.Name, false, false, nil) | ||||||
| 	c.Assert(err, check.IsNil) | 	c.Assert(err, check.IsNil) | ||||||
| 	pak.AlreadyUsed = true | 	pak.Used = true | ||||||
| 	h.db.Save(&pak) | 	h.db.Save(&pak) | ||||||
| 
 | 
 | ||||||
| 	_, err = h.checkKeyValidity(pak.Key) | 	_, err = h.checkKeyValidity(pak.Key) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user