func newSession(conf *Config, k *kite.Kite) (*session.Session, error) { c := credentials.NewStaticCredentials(conf.AWSAccessKeyId, conf.AWSSecretAccessKey, "") kontrolPrivateKey, kontrolPublicKey := kontrolKeys(conf) klientFolder := "development/latest" if conf.ProdMode { k.Log.Info("Prod mode enabled") klientFolder = "production/latest" } k.Log.Info("Klient distribution channel is: %s", klientFolder) // Credential belongs to the `koding-kloud` user in AWS IAM's sess := &session.Session{ DB: modelhelper.Mongo, Kite: k, Userdata: &userdata.Userdata{ Keycreator: &keycreator.Key{ KontrolURL: getKontrolURL(conf.KontrolURL), KontrolPrivateKey: kontrolPrivateKey, KontrolPublicKey: kontrolPublicKey, }, KlientURL: conf.KlientURL, TunnelURL: conf.TunnelURL, Bucket: userdata.NewBucket("koding-klient", klientFolder, c), }, Terraformer: &terraformer.Options{ Endpoint: "http://127.0.0.1:2300/kite", SecretKey: conf.TerraformerSecretKey, Kite: k, }, Log: logging.NewCustom("kloud", conf.DebugMode), } sess.DNSStorage = dnsstorage.NewMongodbStorage(sess.DB) return sess, nil }
func providers() (*awsprovider.Provider, *softlayer.Provider) { c := credentials.NewStaticCredentials(os.Getenv("KLOUD_ACCESSKEY"), os.Getenv("KLOUD_SECRETKEY"), "") mongoURL := os.Getenv("KLOUD_MONGODB_URL") if mongoURL == "" { panic("KLOUD_MONGODB_URL is not set") } modelhelper.Initialize(mongoURL) db := modelhelper.Mongo dnsOpts := &dnsclient.Options{ Creds: c, HostedZone: "dev.koding.io", Log: logging.NewCustom("dns", true), } dnsInstance, err := dnsclient.NewRoute53Client(dnsOpts) if err != nil { panic(err) } dnsStorage := dnsstorage.NewMongodbStorage(db) usd := &userdata.Userdata{ Keycreator: &keycreator.Key{ KontrolURL: conf.KontrolURL, KontrolPrivateKey: testkeys.Private, KontrolPublicKey: testkeys.Public, }, Bucket: userdata.NewBucket("koding-klient", "development/latest", c), } opts := &amazon.ClientOptions{ Credentials: c, Regions: amazon.ProductionRegions, Log: logging.NewCustom("koding", true), } ec2clients, err := amazon.NewClients(opts) if err != nil { panic(err) } slclient := sl.NewSoftlayer( os.Getenv("KLOUD_TESTACCOUNT_SLUSERNAME"), os.Getenv("KLOUD_TESTACCOUNT_SLAPIKEY"), ) awsp := &awsprovider.Provider{ DB: db, Log: logging.NewCustom("kloud-aws", true), DNSClient: dnsInstance, DNSStorage: dnsStorage, Kite: kloudKite, Userdata: usd, } slp := &softlayer.Provider{ DB: db, Log: logging.NewCustom("kloud-softlayer", true), DNSClient: dnsInstance, DNSStorage: dnsStorage, SLClient: slclient, Kite: kloudKite, Userdata: usd, } return kdp, awsp, slp }
func NewCleaner(conf *Config) *Cleaner { creds := credentials.NewStaticCredentials( conf.Aws.AccessKey, conf.Aws.SecretKey, "", ) opts := &amazon.ClientOptions{ Credentials: creds, Regions: amazon.ProductionRegions, Log: logging.NewCustom("cleaner", conf.Debug), MaxResults: int64(conf.MaxResults), Debug: conf.Debug, } m := lookup.NewMongoDB(conf.MongoURL) l, err := lookup.NewAWS(opts) if err != nil { panic(err) } dnsOpts := &dnsclient.Options{ Creds: creds, HostedZone: conf.HostedZone, Log: logging.NewCustom("dns", conf.Debug), } dns, err := dnsclient.NewRoute53Client(dnsOpts) if err != nil { panic(err) } dnsdevOpts := &dnsclient.Options{ Creds: creds, HostedZone: "dev.koding.io", Log: logging.NewCustom("dnsdev", conf.Debug), } dnsdev, err := dnsclient.NewRoute53Client(dnsdevOpts) if err != nil { panic(err) } domains := dnsstorage.NewMongodbStorage(m.DB) p := lookup.NewPostgres(&lookup.PostgresConfig{ Host: conf.Postgres.Host, Port: conf.Postgres.Port, Username: conf.Postgres.Username, Password: conf.Postgres.Password, DBName: conf.Postgres.DBName, }) // TODO: change once the code is moved to koding/monitoring hook := Hook{ URL: conf.Slack.URL, Channel: "#reports", Username: "******", } return &Cleaner{ AWS: l, MongoDB: m, SandboxMongoDB: lookup.NewMongoDB(conf.SandboxMongoURL), Postgres: p, DNS: dns, DNSDev: dnsdev, Domains: domains, Hook: hook, Log: logging.NewCustom("cleaner", conf.Debug), Config: conf, } }