Esempio n. 1
0
// Execute runs the encode command
func (c *EncodeCommand) Execute(args []string) error {
	if opts.HmacKey == "" {
		return errors.New("Empty HMAC")
	}

	if len(args) == 0 {
		return errors.New("No url argument provided")
	}

	oURL := args[0]
	if oURL == "" {
		return errors.New("No url argument provided")
	}

	hmacKeyBytes := []byte(opts.HmacKey)
	var outURL string
	switch c.Base {
	case "base64":
		outURL = encoding.B64EncodeURL(hmacKeyBytes, oURL)
	case "hex":
		outURL = encoding.HexEncodeURL(hmacKeyBytes, oURL)
	default:
		return errors.New("Invalid base provided")
	}
	fmt.Println(c.Prefix + outURL)
	return nil
}
Esempio n. 2
0
func makeReq(testURL string) (*http.Request, error) {
	k := []byte(camoConfig.HMACKey)
	hexURL := encoding.B64EncodeURL(k, testURL)
	out := "http://example.com" + hexURL
	req, err := http.NewRequest("GET", out, nil)
	if err != nil {
		return nil, fmt.Errorf("Error building req url '%s': %s", testURL, err.Error())
	}
	return req, nil
}