Beispiel #1
0
func main() {
	// If not set for some reason, use us-east-1 by default.
	if discfgDBRegion == "" {
		discfgDBRegion = "us-east-1"
	}

	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		var m message

		if err := json.Unmarshal(event, &m); err != nil {
			return nil, err
		}

		options.Storage.AWS.Region = discfgDBRegion
		// Each discfg API can be configured with a default table name.
		options.CfgName = discfgDBTable
		// Overwritten by the message passed to the Lambda.
		if m.Name != "" {
			options.CfgName = m.Name
		}
		options.Key = m.Key

		resp := commands.DeleteKey(options)

		return commands.FormatJSONValue(resp), nil
	})
}
Beispiel #2
0
func main() {
	// If not set for some reason, use us-east-1 by default.
	if discfgDBRegion == "" {
		discfgDBRegion = "us-east-1"
	}

	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		var m message

		if err := json.Unmarshal(event, &m); err != nil {
			return nil, err
		}

		options.Storage.AWS.Region = discfgDBRegion

		if m.Name != "" {
			options.CfgName = m.Name
		}

		var settings map[string]interface{}
		err := json.Unmarshal([]byte(m.Settings), &settings)
		if err != nil {
			return nil, err
		}

		resp := commands.CreateCfg(options, settings)

		return commands.FormatJSONValue(resp), nil
	})
}
Beispiel #3
0
func main() {
	// If not set for some reason, use us-east-1 by default.
	if discfgDBRegion == "" {
		discfgDBRegion = "us-east-1"
	}

	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		var m message

		if err := json.Unmarshal(event, &m); err != nil {
			return nil, err
		}

		options.Storage.AWS.Region = discfgDBRegion
		// The following are set automatically.
		// options.Storage.AWS.AccessKeyID = os.Getenv("AWS_ACCESS_KEY_ID")
		// options.Storage.AWS.SecretAccessKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
		// options.Storage.AWS.SessionToken = os.Getenv("AWS_SESSION_TOKEN")

		// Each discfg API can be configured with a default table name.
		options.CfgName = discfgDBTable
		// Overwritten by the message passed to the Lambda.
		if m.Name != "" {
			options.CfgName = m.Name
		}
		// Comes from a path param from API Gateway.
		options.Key = m.Key
		// Comes from a querystring value from API Gateway, ie. ?ttl=300
		// Note: 0 is unlimited, no TTL.
		if m.TTL != "" {
			if ttl, err := strconv.ParseInt(m.TTL, 10, 64); err == nil {
				options.TTL = ttl
			}
		}
		// Ends up being the POST body from API Gateway.
		options.Value = []byte(m.Value)

		resp := commands.SetKey(options)

		// Format the expiration time (if applicable). This prevents output like "0001-01-01T00:00:00Z" when empty
		// and allows for the time.RFC3339Nano format to be used whereas time.Time normally marshals to a different format.
		if resp.Item.TTL > 0 {
			resp.Item.OutputExpiration = resp.Item.Expiration.Format(time.RFC3339Nano)
		}

		return commands.FormatJSONValue(resp), nil
	})
}
Beispiel #4
0
func main() {
	// If not set for some reason, use us-east-1 by default.
	if discfgDBRegion == "" {
		discfgDBRegion = "us-east-1"
	}

	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		var m message

		if err := json.Unmarshal(event, &m); err != nil {
			return nil, err
		}

		options.Storage.AWS.Region = discfgDBRegion
		// Each discfg API can be configured with a default table name.
		options.CfgName = discfgDBTable
		// Overwritten by the message passed to the Lambda.
		if m.Name != "" {
			options.CfgName = m.Name
		}
		options.Key = m.Key

		resp := commands.GetKey(options)

		// Format the expiration time (if applicable). This prevents output like "0001-01-01T00:00:00Z" when empty
		// and allows for the time.RFC3339Nano format to be used whereas time.Time normally marshals to a different format.
		if resp.Item.TTL > 0 {
			resp.Item.OutputExpiration = resp.Item.Expiration.Format(time.RFC3339Nano)
		}

		// Just return the raw value for the given key if raw was passed as true
		// if m.Raw == "true" {
		// 	return resp.Item.Value, nil
		// }

		r := commands.FormatJSONValue(resp)
		return r, nil
	})
}