Exemple #1
0
// Auth does the authentication
func (carina *Command) Auth(pc *kingpin.ParseContext) (err error) {

	// Check for the latest release.
	if err = carina.informLatest(pc); err != nil {
		// Do nothing if the latest version couldn't be checked
	}

	if carina.Username == "" || carina.APIKey == "" {
		// Backwards compatibility for prior releases, to be deprecated
		// Check on RACKSPACE_USERNAME
		if os.Getenv(rackspaceUserNameEnvVar) != "" && os.Getenv(rackspaceAPIKeyEnvVar) != "" {
			fmt.Fprintf(os.Stderr, "Warning: use of %s and %s environment variables is deprecated.\n", rackspaceUserNameEnvVar, rackspaceAPIKeyEnvVar)
			fmt.Fprintf(os.Stderr, "Please use %s and %s instead.\n", UserNameEnvVar, APIKeyEnvVar)
			carina.Username = os.Getenv(rackspaceUserNameEnvVar)
			carina.APIKey = os.Getenv(rackspaceAPIKeyEnvVar)
		}
	}

	// Short circuit if the cache is not enabled
	if !carina.CacheEnabled {
		carina.ClusterClient, err = libcarina.NewClusterClient(carina.Endpoint, carina.Username, carina.APIKey)
		if err != nil {
			carina.ClusterClient.Client.Timeout = httpTimeout
		}
		return err
	}

	token, ok := carina.Cache.Tokens[carina.Username]

	if ok {
		carina.ClusterClient = &libcarina.ClusterClient{
			Client:   &http.Client{Timeout: httpTimeout},
			Username: carina.Username,
			Token:    token,
			Endpoint: carina.Endpoint,
		}

		if dummyRequest(carina.ClusterClient) == nil {
			return nil
		}
		// Otherwise we fall through and authenticate again
	}

	carina.ClusterClient, err = libcarina.NewClusterClient(carina.Endpoint, carina.Username, carina.APIKey)
	if err != nil {
		return err
	}
	err = carina.Cache.SetToken(carina.Username, carina.ClusterClient.Token)
	return err
}
Exemple #2
0
// Auth does the authentication
func (carina *Command) Auth(pc *kingpin.ParseContext) (err error) {

	if carina.Username == "" || carina.APIKey == "" {
		// Backwards compatibility for prior releases, to be deprecated
		// Check on RACKSPACE_USERNAME
		if os.Getenv(rackspaceUserNameEnvVar) != "" && os.Getenv(rackspaceAPIKeyEnvVar) != "" {
			fmt.Fprintf(os.Stderr, "Warning: use of %s and %s environment variables is deprecated.\n", rackspaceUserNameEnvVar, rackspaceAPIKeyEnvVar)
			fmt.Fprintf(os.Stderr, "Please use %s and %s instead.\n", UserNameEnvVar, APIKeyEnvVar)
			carina.Username = os.Getenv(rackspaceUserNameEnvVar)
			carina.APIKey = os.Getenv(rackspaceAPIKeyEnvVar)
		}
	}

	carina.ClusterClient, err = libcarina.NewClusterClient(carina.Endpoint, carina.Username, carina.APIKey)
	return err
}
Exemple #3
0
func cmdStart(c *cli.Context) {
	username := c.GlobalString("username")
	apiKey := c.GlobalString("api-key")
	clusterName := c.GlobalString("clustername")
	endpoint := c.GlobalString("endpoint")

	if clusterName == "" {
		log.Fatalf("cluster name must not be empty")
	}

	config := &interlock.Config{}

	client, err := libcarina.NewClusterClient(endpoint, username, apiKey)

	if err != nil {
		log.Fatalf("error getting access to the cluster: %s", err)
	}

	swarmURL, tlsConfig, err := client.GetDockerConfig(clusterName)
	if err != nil {
		log.Fatalf("error retrieving tls config and swarm URL: %s", err)
	}

	config.SwarmUrl = swarmURL
	config.EnabledPlugins = c.GlobalStringSlice("plugin")

	m := NewManager(config, tlsConfig)

	log.Infof("interlock running version=%s", version.FullVersion())
	if err := m.Run(); err != nil {
		log.Fatal(err)
	}

	waitForInterrupt()

	log.Infof("shutting down")
	if err := m.Stop(); err != nil {
		log.Fatal(err)
	}
}