mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-02 03:33:05 +00:00
remove unnecessary checks on slices
This commit is contained in:
parent
09863b540d
commit
c52e3aafe6
4 changed files with 24 additions and 31 deletions
|
@ -108,14 +108,13 @@ var listPreAuthKeys = &cobra.Command{
|
||||||
reusable = fmt.Sprintf("%v", key.GetReusable())
|
reusable = fmt.Sprintf("%v", key.GetReusable())
|
||||||
}
|
}
|
||||||
|
|
||||||
var aclTags string
|
aclTags := ""
|
||||||
|
|
||||||
if len(key.AclTags) > 0 {
|
|
||||||
for _, tag := range key.AclTags {
|
for _, tag := range key.AclTags {
|
||||||
aclTags += "," + tag
|
aclTags += "," + tag
|
||||||
}
|
}
|
||||||
|
|
||||||
aclTags = strings.TrimLeft(aclTags, ",")
|
aclTags = strings.TrimLeft(aclTags, ",")
|
||||||
}
|
|
||||||
|
|
||||||
tableData = append(tableData, []string{
|
tableData = append(tableData, []string{
|
||||||
key.GetId(),
|
key.GetId(),
|
||||||
|
|
|
@ -106,17 +106,14 @@ func (api headscaleV1APIServer) CreatePreAuthKey(
|
||||||
expiration = request.GetExpiration().AsTime()
|
expiration = request.GetExpiration().AsTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(request.AclTags) > 0 {
|
|
||||||
for _, tag := range request.AclTags {
|
for _, tag := range request.AclTags {
|
||||||
err := validateTag(tag)
|
err := validateTag(tag)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &v1.CreatePreAuthKeyResponse{
|
return &v1.CreatePreAuthKeyResponse{
|
||||||
PreAuthKey: nil,
|
PreAuthKey: nil,
|
||||||
}, status.Error(codes.InvalidArgument, err.Error())
|
}, status.Error(codes.InvalidArgument, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
preAuthKey, err := api.h.CreatePreAuthKey(
|
preAuthKey, err := api.h.CreatePreAuthKey(
|
||||||
request.GetNamespace(),
|
request.GetNamespace(),
|
||||||
|
@ -154,7 +151,6 @@ func (api headscaleV1APIServer) ListPreAuthKeys(
|
||||||
request *v1.ListPreAuthKeysRequest,
|
request *v1.ListPreAuthKeysRequest,
|
||||||
) (*v1.ListPreAuthKeysResponse, error) {
|
) (*v1.ListPreAuthKeysResponse, error) {
|
||||||
preAuthKeys, err := api.h.ListPreAuthKeys(request.GetNamespace())
|
preAuthKeys, err := api.h.ListPreAuthKeys(request.GetNamespace())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,11 +234,9 @@ func (key *PreAuthKey) toProto() *v1.PreAuthKey {
|
||||||
protoKey.CreatedAt = timestamppb.New(*key.CreatedAt)
|
protoKey.CreatedAt = timestamppb.New(*key.CreatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(key.ACLTags) > 0 {
|
|
||||||
for idx := range key.ACLTags {
|
for idx := range key.ACLTags {
|
||||||
protoKey.AclTags[idx] = key.ACLTags[idx].Tag
|
protoKey.AclTags[idx] = key.ACLTags[idx].Tag
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return &protoKey
|
return &protoKey
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,7 +358,6 @@ func (h *Headscale) handleAuthKeyCommon(
|
||||||
if len(aclTags) > 0 {
|
if len(aclTags) > 0 {
|
||||||
// This conditional preserves the existing behaviour, although SaaS would reset the tags on auth-key login
|
// This conditional preserves the existing behaviour, although SaaS would reset the tags on auth-key login
|
||||||
err = h.SetTags(machine, aclTags)
|
err = h.SetTags(machine, aclTags)
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
|
@ -371,6 +370,7 @@ func (h *Headscale) handleAuthKeyCommon(
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue