github.com/coreos/mantle@v0.13.0/cmd/ore/do/do.go (about) 1 // Copyright 2017 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package do 16 17 import ( 18 "context" 19 "fmt" 20 21 "github.com/coreos/pkg/capnslog" 22 "github.com/spf13/cobra" 23 24 "github.com/coreos/mantle/auth" 25 "github.com/coreos/mantle/cli" 26 "github.com/coreos/mantle/platform/api/do" 27 ) 28 29 var ( 30 plog = capnslog.NewPackageLogger("github.com/coreos/mantle", "ore/do") 31 32 DO = &cobra.Command{ 33 Use: "do [command]", 34 Short: "DigitalOcean machine utilities", 35 } 36 37 API *do.API 38 options do.Options 39 40 imageName string 41 imageURL string 42 ) 43 44 func init() { 45 DO.PersistentFlags().StringVar(&options.ConfigPath, "config-file", "", "config file (default \"~/"+auth.DOConfigPath+"\")") 46 DO.PersistentFlags().StringVar(&options.Profile, "profile", "", "profile (default \"default\")") 47 DO.PersistentFlags().StringVar(&options.AccessToken, "token", "", "access token (overrides config file)") 48 cli.WrapPreRun(DO, preflightCheck) 49 } 50 51 func preflightCheck(cmd *cobra.Command, args []string) error { 52 plog.Debugf("Running DigitalOcean preflight check") 53 api, err := do.New(&options) 54 if err != nil { 55 return fmt.Errorf("could not create DigitalOcean client: %v", err) 56 } 57 if err := api.PreflightCheck(context.Background()); err != nil { 58 return fmt.Errorf("could not complete DigitalOcean preflight check: %v", err) 59 } 60 61 plog.Debugf("Preflight check success; we have liftoff") 62 API = api 63 return nil 64 }