Exemplo n.º 1
0
// serverLogin initialized a VaultServices and tries to perform a server login.
func serverLogin() (*service.AuthenticatedVaultClient, error) {
	// Check arguments
	if extractFlags.JobID == "" {
		return nil, maskAny(fmt.Errorf("--job-id missing"))
	}
	if extractFlags.ClusterIDPath == "" {
		return nil, maskAny(fmt.Errorf("--cluster-id-path missing"))
	}
	if extractFlags.MachineIDPath == "" {
		return nil, maskAny(fmt.Errorf("--machine-id-path missing"))
	}

	// Create service
	vs, err := service.NewVaultService(log, globalFlags.VaultServiceConfig)
	if err != nil {
		return nil, maskAny(err)
	}

	// Perform server login
	c, err := vs.ServerLogin(extractFlags.ServerLoginData)
	if err != nil {
		return nil, maskAny(err)
	}
	return c, nil
}
Exemplo n.º 2
0
func cmdSealStatusRun(cmd *cobra.Command, args []string) {
	vs, err := service.NewVaultService(log, globalFlags.VaultServiceConfig)
	if err != nil {
		Exitf("Failed to create vault service: %#v", err)
	}
	if err := vs.SealStatus(); err != nil {
		Exitf("Failed to show seal-status of vault: %#v", err)
	}
}
Exemplo n.º 3
0
func cmdUnsealRun(cmd *cobra.Command, args []string) {
	if len(args) == 0 {
		Exitf("Pass command to query for unseal keys.")
	}
	// Create service
	vs, err := service.NewVaultService(log, globalFlags.VaultServiceConfig)
	if err != nil {
		Exitf("Failed to create vault service: %#v", err)
	}
	if err := vs.Unseal(args); err != nil {
		Exitf("Failed to unseal vault: %#v", err)
	}
}
Exemplo n.º 4
0
// adminLogin initialized a VaultServices and tries to perform a administrator login (if needed).
func adminLogin() (*service.VaultService, *service.AuthenticatedVaultClient, error) {
	githubToken := globalFlags.GithubToken()
	assertArgIsSet(githubToken, "-G")
	// Create service
	vs, err := service.NewVaultService(log, globalFlags.VaultServiceConfig)
	if err != nil {
		return nil, nil, maskAny(err)
	}

	// Login with github (if available)
	c, err := vs.GithubLogin(service.GithubLoginData{
		GithubToken: githubToken,
	})
	if err != nil {
		return nil, nil, maskAny(err)
	}

	return vs, c, nil
}