mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-04 04:28:08 +00:00 
			
		
		
		
	* Use Colored UI if stdout is a tty * Add format options to operator unseal * Add format test on operator unseal * Add -no-color output flag, and use BasicUi if no-color flag is provided * Move seal status formatting logic to OutputSealStatus * Apply no-color to warnings from DeprecatedCommands as well * Add OutputWithFormat to support arbitrary data, add format option to auth list * Add ability to output arbitrary list data on TableFormatter * Clear up switch logic on format * Add format option for list-related commands * Add format option to rest of commands that returns a client API response * Remove initOutputYAML and initOutputJSON, and use OutputWithFormat instead * Remove outputAsYAML and outputAsJSON, and use OutputWithFormat instead * Remove -no-color flag, use env var exclusively to toggle colored output * Fix compile * Remove -no-color flag in main.go * Add missing FlagSetOutputFormat * Fix generate-root/decode test * Migrate init functions to main.go * Add no-color flag back as hidden * Handle non-supported data types for TableFormatter.OutputList * Pull formatting much further up to remove the need to use c.flagFormat (#3950) * Pull formatting much further up to remove the need to use c.flagFormat Also remove OutputWithFormat as the logic can cause issues. * Use const for env var * Minor updates * Remove unnecessary check * Fix SSH output and some tests * Fix tests * Make race detector not run on generate root since it kills Travis these days * Update docs * Update docs * Address review feedback * Handle --format as well as -format
		
			
				
	
	
		
			111 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package api
 | 
						|
 | 
						|
func (c *Sys) GenerateRootStatus() (*GenerateRootStatusResponse, error) {
 | 
						|
	return c.generateRootStatusCommon("/v1/sys/generate-root/attempt")
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) GenerateDROperationTokenStatus() (*GenerateRootStatusResponse, error) {
 | 
						|
	return c.generateRootStatusCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt")
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) generateRootStatusCommon(path string) (*GenerateRootStatusResponse, error) {
 | 
						|
	r := c.c.NewRequest("GET", path)
 | 
						|
	resp, err := c.c.RawRequest(r)
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	defer resp.Body.Close()
 | 
						|
 | 
						|
	var result GenerateRootStatusResponse
 | 
						|
	err = resp.DecodeJSON(&result)
 | 
						|
	return &result, err
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) GenerateRootInit(otp, pgpKey string) (*GenerateRootStatusResponse, error) {
 | 
						|
	return c.generateRootInitCommon("/v1/sys/generate-root/attempt", otp, pgpKey)
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) GenerateDROperationTokenInit(otp, pgpKey string) (*GenerateRootStatusResponse, error) {
 | 
						|
	return c.generateRootInitCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt", otp, pgpKey)
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) generateRootInitCommon(path, otp, pgpKey string) (*GenerateRootStatusResponse, error) {
 | 
						|
	body := map[string]interface{}{
 | 
						|
		"otp":     otp,
 | 
						|
		"pgp_key": pgpKey,
 | 
						|
	}
 | 
						|
 | 
						|
	r := c.c.NewRequest("PUT", path)
 | 
						|
	if err := r.SetJSONBody(body); err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
 | 
						|
	resp, err := c.c.RawRequest(r)
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	defer resp.Body.Close()
 | 
						|
 | 
						|
	var result GenerateRootStatusResponse
 | 
						|
	err = resp.DecodeJSON(&result)
 | 
						|
	return &result, err
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) GenerateRootCancel() error {
 | 
						|
	return c.generateRootCancelCommon("/v1/sys/generate-root/attempt")
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) GenerateDROperationTokenCancel() error {
 | 
						|
	return c.generateRootCancelCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt")
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) generateRootCancelCommon(path string) error {
 | 
						|
	r := c.c.NewRequest("DELETE", path)
 | 
						|
	resp, err := c.c.RawRequest(r)
 | 
						|
	if err == nil {
 | 
						|
		defer resp.Body.Close()
 | 
						|
	}
 | 
						|
	return err
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) GenerateRootUpdate(shard, nonce string) (*GenerateRootStatusResponse, error) {
 | 
						|
	return c.generateRootUpdateCommon("/v1/sys/generate-root/update", shard, nonce)
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) GenerateDROperationTokenUpdate(shard, nonce string) (*GenerateRootStatusResponse, error) {
 | 
						|
	return c.generateRootUpdateCommon("/v1/sys/replication/dr/secondary/generate-operation-token/update", shard, nonce)
 | 
						|
}
 | 
						|
 | 
						|
func (c *Sys) generateRootUpdateCommon(path, shard, nonce string) (*GenerateRootStatusResponse, error) {
 | 
						|
	body := map[string]interface{}{
 | 
						|
		"key":   shard,
 | 
						|
		"nonce": nonce,
 | 
						|
	}
 | 
						|
 | 
						|
	r := c.c.NewRequest("PUT", path)
 | 
						|
	if err := r.SetJSONBody(body); err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
 | 
						|
	resp, err := c.c.RawRequest(r)
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	defer resp.Body.Close()
 | 
						|
 | 
						|
	var result GenerateRootStatusResponse
 | 
						|
	err = resp.DecodeJSON(&result)
 | 
						|
	return &result, err
 | 
						|
}
 | 
						|
 | 
						|
type GenerateRootStatusResponse struct {
 | 
						|
	Nonce            string `json:"nonce"`
 | 
						|
	Started          bool   `json:"started"`
 | 
						|
	Progress         int    `json:"progress"`
 | 
						|
	Required         int    `json:"required"`
 | 
						|
	Complete         bool   `json:"complete"`
 | 
						|
	EncodedToken     string `json:"encoded_token"`
 | 
						|
	EncodedRootToken string `json:"encoded_root_token"`
 | 
						|
	PGPFingerprint   string `json:"pgp_fingerprint"`
 | 
						|
}
 |