Exemplo n.º 1
0
// Info about the configuration including global version/state and modified time
func Info(opts config.Options) config.ResponseObject {
	resp := config.ResponseObject{
		Action: "info",
	}

	if opts.CfgName != "" {
		// Just get the root key
		opts.Key = "/"

		storageResponse, err := storage.Get(opts)
		if err != nil {
			resp.Error = err.Error()
		} else {
			// Debating putting the item value on here... (allowing users to store values on the config or "root")
			// resp.Item = storageResponse
			// Set the configuration version and modified time on the response
			// Item.CfgVersion and Item.CfgModifiedNanoseconds are not included in the JSON output
			resp.CfgVersion = storageResponse.CfgVersion
			resp.CfgModified = 0
			resp.CfgModifiedNanoseconds = storageResponse.CfgModifiedNanoseconds
			// Modified in seconds
			resp.CfgModified = storageResponse.CfgModifiedNanoseconds / int64(time.Second)
			// Modified parsed
			modified := time.Unix(0, storageResponse.CfgModifiedNanoseconds)
			resp.CfgModifiedParsed = modified.Format(time.RFC3339)

			// Set information about the storage engine
			resp.CfgStorage.InterfaceName = opts.StorageInterfaceName
			resp.CfgStorage.Name = storage.Name(opts)
			resp.CfgStorage.Options = storage.Options(opts)

			// Get the status (only applicable for some storage interfaces, such as DynamoDB)
			resp.CfgState, err = storage.ConfigState(opts)
			if err != nil {
				resp.Error = err.Error()
			} else {
				var buffer bytes.Buffer
				buffer.WriteString(opts.CfgName)
				if resp.CfgState != "" {
					buffer.WriteString(" (")
					buffer.WriteString(resp.CfgState)
					buffer.WriteString(")")
				}
				buffer.WriteString(" version ")
				buffer.WriteString(strconv.FormatInt(resp.CfgVersion, 10))
				buffer.WriteString(" last modified ")
				buffer.WriteString(modified.Format(time.RFC1123))
				resp.Message = buffer.String()
				buffer.Reset()
			}
		}
	} else {
		resp.Error = NotEnoughArgsMsg
	}
	return resp
}
Exemplo n.º 2
0
// GetKey gets a key from a configuration
func GetKey(opts config.Options) config.ResponseObject {
	resp := config.ResponseObject{
		Action: "get",
	}
	key, keyErr := formatKeyName(opts.Key)
	if keyErr == nil {
		opts.Key = key
		storageResponse, err := storage.Get(opts)
		if err != nil {
			resp.Error = err.Error()
		} else {
			resp.Item = storageResponse
		}
	} else {
		resp.Error = keyErr.Error()
	}
	return resp
}