Skip to content

Commit

Permalink
Merge pull request #3160 from gravitl/NET-1640
Browse files Browse the repository at this point in the history
NET-1640: Include static Nodes in the nodes api
  • Loading branch information
abhishek9686 authored Oct 30, 2024
2 parents 2426b5f + 7904886 commit f63ed23
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 234 deletions.
2 changes: 1 addition & 1 deletion controllers/ext_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func validateCustomExtClient(customExtClient *models.CustomExtClient, checkID bo
//validate clientid
if customExtClient.ClientID != "" {
if err := isValid(customExtClient.ClientID, checkID); err != nil {
return fmt.Errorf("client validatation: %v", err)
return fmt.Errorf("client validation: %v", err)
}
}
//extclient.ClientID = customExtClient.ClientID
Expand Down
8 changes: 4 additions & 4 deletions controllers/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

var (
errInvalidExtClientPubKey = errors.New("incorrect ext client public key")
errInvalidExtClientID = errors.New("ext client ID must be alphanumderic and/or dashes and less that 15 chars")
errInvalidExtClientExtraIP = errors.New("ext client extra ip must be a valid cidr")
errInvalidExtClientDNS = errors.New("ext client dns must be a valid ip address")
errInvalidExtClientPubKey = errors.New("incorrect client public key")
errInvalidExtClientID = errors.New("node name must be alphanumderic and/or dashes and less that 15 chars")
errInvalidExtClientExtraIP = errors.New("client extra ip must be a valid cidr")
errInvalidExtClientDNS = errors.New("client dns must be a valid ip address")
errDuplicateExtClientName = errors.New("duplicate client name")
)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
)

require (
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e
github.com/guumaster/tablewriter v0.0.10
github.com/matryer/is v1.4.1
github.com/olekukonko/tablewriter v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e h1:XmA6L9IPRdUr28a+SK/oMchGgQy159wvzXA5tJ7l+40=
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e/go.mod h1:AFIo+02s+12CEg8Gzz9kzhCbmbq6JcKNrhHffCGA9z4=
github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE=
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
Expand Down
11 changes: 11 additions & 0 deletions logic/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"sort"
"strings"
"sync"
"time"

"github.com/c-robinson/iplib"
validator "github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic/acls/nodeacls"
Expand Down Expand Up @@ -233,6 +235,15 @@ func CreateNetwork(network models.Network) (models.Network, error) {
storeNetworkInCache(network.NetID, network)
}

_, _ = CreateEnrollmentKey(
0,
time.Time{},
[]string{network.NetID},
[]string{network.NetID},
true,
uuid.Nil,
)

return network, nil
}

Expand Down
28 changes: 28 additions & 0 deletions migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"golang.org/x/exp/slog"

"github.com/google/uuid"
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
Expand Down Expand Up @@ -123,6 +124,33 @@ func updateEnrollmentKeys() {
}

}

existingKeys, err := logic.GetAllEnrollmentKeys()
if err != nil {
return
}
// check if any tags are duplicate
existingTags := make(map[string]struct{})
for _, existingKey := range existingKeys {
for _, t := range existingKey.Tags {
existingTags[t] = struct{}{}
}
}
networks, _ := logic.GetNetworks()
for _, network := range networks {
if _, ok := existingTags[network.NetID]; ok {
continue
}
_, _ = logic.CreateEnrollmentKey(
0,
time.Time{},
[]string{network.NetID},
[]string{network.NetID},
true,
uuid.Nil,
)

}
}

func removeOldUserGrps() {
Expand Down
234 changes: 5 additions & 229 deletions models/names.go
Original file line number Diff line number Diff line change
@@ -1,242 +1,18 @@
package models

import (
"math/rand"
"time"
)

// NAMES - list of names 4-7 chars in length
var NAMES = []string{
"logic",
"warrant",
"iconic",
"threat",
"strike",
"boy",
"vital",
"unity",
"audio",
"schemer",
"depth",
"gravitl",
"mystic",
"donkey",
"atomic",
"turtle",
"monkey",
"rabbit",
"static",
"mosaic",
"elite",
"stonks",
"doggy",
"python",
"mohawk",
"arctic",
"rival",
"vibes",
"delay",
"bridge",
"weeble",
"combat",
"animal",
"wobble",
"rubble",
"bucket",
"proof",
"worker",
"beetle",
"racket",
"equal",
"panda",
"antics",
"strong",
"forum",
"koala",
"anchor",
"ornery",
"indigo",
"schism",
"dragon",
"knight",
"bishop",
"laser",
"rhino",
"clutch",
"shark",
"leader",
"young",
"robot",
"squish",
"chimp",
"rocket",
"space",
"queen",
"royalty",
"flush",
"earth",
"planet",
"heart",
"droplet",
"dillon",
"saturn",
"pluto",
"school",
"alien",
"matte",
"dingo",
"meercat",
"cookie",
"snack",
"goose",
"pepper",
"melissa",
"alex",
"elon",
"yeet",
"meh",
"walrus",
"avatar",
"chicken",
"proton",
"mohawk",
"tattoo",
"zebra",
"star",
"butter",
"tango",
"homie",
"rambo",
"cosmo",
"bubbles",
"hulk",
"pluto",
"scooby",
"thanos",
"yoda",
"draco",
"goofy",
"ditto",
"puff",
"duck",
"mouse",
"akita",
"water",
"hound",
"baby",
"spider",
"squid",
"roach",
"crab",
"cougar",
"cyborg",
"android",
"being",
"ninja",
"unicorn",
"zombie",
"warrior",
"zamboni",
"life",
"marine",
"node",
"mother",
"father",
"tesla",
}

// SMALL_NAMES - list of small (4 char or less) names
var SMALL_NAMES = []string{
"ace",
"odd",
"hot",
"ill",
"root",
"sudo",
"moon",
"beef",
"bro",
"dank",
"red",
"gold",
"big",
"old",
"og",
"best",
"blue",
"lil",
"mom",
"bot",
"evil",
"good",
"holy",
"rad",
"bad",
"sad",
"mad",
"chad",
"pre",
"post",
"foot",
"soft",
"hard",
"lite",
"dark",
"true",
"toy",
"soy",
"rude",
"nice",
"fun",
"fat",
"pro",
"sly",
"tan",
"pet",
"fine",
"main",
"last",
"wide",
"free",
"open",
"poor",
"rich",
"next",
"real",
"long",
"huge",
"wild",
"sick",
"weak",
"firm",
"pink",
"okay",
"dull",
"loud",
"lazy",
"dumb",
"tidy",
"idle",
"bony",
"cute",
"oily",
"lame",
"mega",
"limp",
"wavy",
"edgy",
"nosy",
"zany",
"base",
"cold",
}
"github.com/goombaio/namegenerator"
)

var logoString = retrieveLogo()

// GenerateNodeName - generates a random node name
func GenerateNodeName() string {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
return SMALL_NAMES[rng.Intn(len(SMALL_NAMES))] + "-" + NAMES[rng.Intn(len(NAMES))]
seed := time.Now().UTC().UnixNano()
nameGenerator := namegenerator.NewNameGenerator(seed)
return nameGenerator.Generate()
}

// RetrieveLogo - retrieves the ascii art logo for Netmaker
Expand Down

0 comments on commit f63ed23

Please sign in to comment.