mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
More updates on documentation
This commit is contained in:
@@ -21,10 +21,14 @@ const (
|
||||
MINIO_SECRET_ID = 40
|
||||
)
|
||||
|
||||
/// helpers
|
||||
|
||||
// Is alphanumeric?
|
||||
func isalnum(c byte) bool {
|
||||
return '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
|
||||
}
|
||||
|
||||
// validate access key for only alphanumeric characters
|
||||
func ValidateAccessKey(key []byte) bool {
|
||||
for _, char := range key {
|
||||
if isalnum(char) {
|
||||
|
||||
@@ -21,9 +21,14 @@ import (
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
// Static alphaNumeric table used for generating unique keys
|
||||
var alphaNumericTable = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
var alphaNumericTableFull = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
|
||||
|
||||
/// helpers
|
||||
|
||||
// Generate random alpha numeric value using only uppercase characters
|
||||
// takes input as size in integer
|
||||
func GetRandomAlphaNumeric(size int) ([]byte, error) {
|
||||
alpha := make([]byte, size)
|
||||
_, err := rand.Read(alpha)
|
||||
@@ -37,6 +42,8 @@ func GetRandomAlphaNumeric(size int) ([]byte, error) {
|
||||
return alpha, nil
|
||||
}
|
||||
|
||||
// Generate random alpha numeric value using all alphanumeric characters
|
||||
// takes input as size in integer
|
||||
func GetRandomAlphaNumericFull(size int) ([]byte, error) {
|
||||
alphaFull := make([]byte, size)
|
||||
_, err := rand.Read(alphaFull)
|
||||
@@ -49,6 +56,7 @@ func GetRandomAlphaNumericFull(size int) ([]byte, error) {
|
||||
return alphaFull, nil
|
||||
}
|
||||
|
||||
// Generate random base64 numeric value from a random seed.
|
||||
func GetRandomBase64(size int) ([]byte, error) {
|
||||
rb := make([]byte, size)
|
||||
_, err := rand.Read(rb)
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"github.com/minio-io/minio/pkg/utils/config"
|
||||
)
|
||||
|
||||
// Sign a given http request using HMAC style signatures
|
||||
func SignRequest(user config.User, req *http.Request) {
|
||||
if date := req.Header.Get("Date"); date == "" {
|
||||
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
|
||||
@@ -48,7 +49,7 @@ func SignRequest(user config.User, req *http.Request) {
|
||||
req.Header.Set("Authorization", authHeader.String())
|
||||
}
|
||||
|
||||
// This package implements verification side of Object API Signature request
|
||||
// Validate an API request by validating its signature using HMAC signatures
|
||||
func ValidateRequest(user config.User, req *http.Request) (bool, error) {
|
||||
// Verify if date headers are set, if not reject the request
|
||||
if req.Header.Get("x-amz-date") == "" {
|
||||
@@ -101,6 +102,7 @@ func getStringToSign(req *http.Request) string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Lower all upper case letters
|
||||
func hasPrefixCaseInsensitive(s, pfx string) bool {
|
||||
if len(pfx) > len(s) {
|
||||
return false
|
||||
@@ -113,6 +115,7 @@ func hasPrefixCaseInsensitive(s, pfx string) bool {
|
||||
return shead == pfx || shead == strings.ToLower(pfx)
|
||||
}
|
||||
|
||||
// Canonicalize amazon special headers, headers starting with 'x-amz-'
|
||||
func writeCanonicalizedAmzHeaders(buf *bytes.Buffer, req *http.Request) {
|
||||
amzHeaders := make([]string, 0)
|
||||
vals := make(map[string][]string)
|
||||
@@ -146,7 +149,7 @@ func writeCanonicalizedAmzHeaders(buf *bytes.Buffer, req *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// Must be sorted:
|
||||
// Resource list must be sorted:
|
||||
var subResList = []string{"acl", "lifecycle", "location", "logging", "notification", "partNumber", "policy", "requestPayment", "torrent", "uploadId", "uploads", "versionId", "versioning", "versions", "website"}
|
||||
|
||||
// From the Amazon docs:
|
||||
@@ -155,6 +158,7 @@ var subResList = []string{"acl", "lifecycle", "location", "logging", "notificati
|
||||
// <HTTP-Request-URI, from the protocol name up to the query string> +
|
||||
// [ sub-resource, if present. For example "?acl", "?location", "?logging", or "?torrent"];
|
||||
func writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request) {
|
||||
// Grab bucket name from hostname
|
||||
bucket := bucketFromHostname(req)
|
||||
if bucket != "" {
|
||||
buf.WriteByte('/')
|
||||
@@ -182,6 +186,7 @@ func writeCanonicalizedResource(buf *bytes.Buffer, req *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// Convert subdomain http request into bucketname if possible
|
||||
func bucketFromHostname(req *http.Request) string {
|
||||
host := req.Host
|
||||
if host == "" {
|
||||
|
||||
Reference in New Issue
Block a user