github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/orbiter/kinds/providers/cs/context.go (about) 1 package cs 2 3 import ( 4 ctxpkg "context" 5 "hash/fnv" 6 "net/http" 7 "time" 8 9 "github.com/cloudscale-ch/cloudscale-go-sdk" 10 11 "github.com/caos/orbos/mntr" 12 ) 13 14 type context struct { 15 monitor mntr.Monitor 16 networkName string 17 orbID string 18 providerID string 19 desired *Spec 20 client *cloudscale.Client 21 machinesService *machinesService 22 ctx ctxpkg.Context 23 } 24 25 func buildContext(monitor mntr.Monitor, desired *Spec, orbID, providerID string, oneoff bool) *context { 26 27 ctx := ctxpkg.Background() 28 29 client := cloudscale.NewClient(&http.Client{ 30 Timeout: 30 * time.Second, 31 }) 32 33 client.AuthToken = desired.APIToken.Value 34 35 h := fnv.New32() 36 h.Write([]byte(orbID)) 37 newContext := &context{ 38 monitor: monitor, 39 orbID: orbID, 40 providerID: providerID, 41 desired: desired, 42 client: client, 43 ctx: ctx, 44 } 45 h.Reset() 46 47 newContext.machinesService = newMachinesService(newContext, oneoff) 48 49 return newContext 50 }