コード例 #1
0
ファイル: nexter.go プロジェクト: modcloth/amqp-tools
func (up *UUIDProvider) Next() (string, error) {
	uuid, err := uuid.NewV4()

	if err != nil {
		return "", err
	}

	return uuid.String(), nil
}
コード例 #2
0
func (client *Client) newRequest(method string, urlStr string, body interface{}) *http.Request {
	jsonBody, _ := json.Marshal(body)
	req, _ := http.NewRequest(method, urlStr, bytes.NewReader(jsonBody))
	req.Header.Set("User-Agent", fmt.Sprintf("jarias/stormpath-sdk-go/%s (%s; %s)", version, runtime.GOOS, runtime.GOARCH))
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-Type", "application/json")

	uuid, _ := uuid.NewV4()
	nonce := uuid.String()

	Authenticate(req, jsonBody, time.Now().In(time.UTC), client.Credentials, nonce)
	return req
}
コード例 #3
0
func (client *Client) newRequest(method string, urlStr string, body interface{}, contentType string) *http.Request {
	var encodedBody []byte
	if contentType == ApplicationJson {
		encodedBody, _ = json.Marshal(body)
	} else {
		//If content type is not application/json then it is application/x-www-form-urlencoded in which case the body should the encoded params as a []byte
		encodedBody = body.([]byte)
	}
	req, _ := http.NewRequest(method, urlStr, bytes.NewReader(encodedBody))
	req.Header.Set("User-Agent", fmt.Sprintf("jarias/stormpath-sdk-go/%s (%s; %s)", version, runtime.GOOS, runtime.GOARCH))
	req.Header.Set("Accept", ApplicationJson)
	req.Header.Set("Content-Type", contentType)

	uuid, _ := uuid.NewV4()
	nonce := uuid.String()

	Authenticate(req, encodedBody, time.Now().In(time.UTC), client.Credentials, nonce)
	return req
}
コード例 #4
0
ファイル: component.go プロジェクト: nagyistge/hm9000
func NewComponent(logger *gosteno.Logger, componentType string, index uint, heathMonitor HealthMonitor, statusPort uint16, statusCreds []string, instrumentables []instrumentation.Instrumentable) (Component, error) {
	ip, err := localip.LocalIP()
	if err != nil {
		return Component{}, err
	}

	if statusPort == 0 {
		statusPort, err = localip.LocalPort()
		if err != nil {
			return Component{}, err
		}
	}

	uuid, err := uuid.NewV4()
	if err != nil {
		return Component{}, err
	}

	if len(statusCreds) == 0 || statusCreds[username] == "" || statusCreds[password] == "" {
		randUser := make([]byte, 42)
		randPass := make([]byte, 42)
		rand.Read(randUser)
		rand.Read(randPass)
		en := base64.URLEncoding
		user := en.EncodeToString(randUser)
		pass := en.EncodeToString(randPass)

		statusCreds = []string{user, pass}
	}

	return Component{
		Logger:            logger,
		IpAddress:         ip,
		Type:              componentType,
		Index:             index,
		UUID:              uuid.String(),
		HealthMonitor:     heathMonitor,
		StatusPort:        statusPort,
		StatusCredentials: statusCreds,
		Instrumentables:   instrumentables,
	}, nil
}
コード例 #5
0
func checkRedirect(req *http.Request, via []*http.Request) error {
	//Go client defautl behavior is to bail after 10 redirects
	if len(via) > 10 {
		return errors.New("stopped after 10 redirects")
	}
	//No redirect do nothing
	if len(via) == 0 {
		// No redirects
		return nil
	}
	// Re-Authenticate the redirect request
	uuid, _ := uuid.NewV4()
	nonce := uuid.String()

	//We can use an empty payload cause the only redirect is for the current tenant
	//this could change in the future
	Authenticate(req, emptyPayload(), time.Now().In(time.UTC), client.Credentials, nonce)

	return nil
}
コード例 #6
0
ファイル: stormpath.go プロジェクト: jarias/stormpath-sdk-go
func checkRedirect(req *http.Request, via []*http.Request) error {
	//Go client defautl behavior is to bail after 10 redirects
	if len(via) > 10 {
		return errors.New("stopped after 10 redirects")
	}
	//No redirect do nothing
	if len(via) == 0 {
		// No redirects
		return nil
	}
	// Re-Authenticate the redirect request
	uuid, _ := uuid.NewV4()
	nonce := uuid.String()

	//In Go 1.8 the authorization header remains in the redirect request causing auth errors
	req.Header.Del(AuthorizationHeader)

	//We can use an empty payload cause the only redirect is for the current tenant
	//this could change in the future
	Authenticate(req, emptyPayload(), time.Now().In(time.UTC), client.ClientConfiguration.APIKeyID, client.ClientConfiguration.APIKeySecret, nonce)

	return nil
}
コード例 #7
0
func (client *Client) newRequest(method string, urlStr string, body interface{}, contentType string) *http.Request {
	var encodedBody []byte

	if contentType != ApplicationJSON || method == http.MethodGet || method == http.MethodDelete {
		//If content type is not application/json then it is application/x-www-form-urlencoded in which case the body should the encoded params as a []byte
		//Fixes issue #23 if the method is GET then body should also be just the bytes instead of doing a JSON marshaling
		encodedBody = body.([]byte)
	} else {
		if _, ok := body.([]byte); !ok {
			encodedBody, _ = json.Marshal(body)
		}
	}
	req, _ := http.NewRequest(method, urlStr, bytes.NewReader(encodedBody))

	req.Header.Set(UserAgentHeader, strings.TrimSpace(fmt.Sprintf("stormpath-sdk-go/%s %s", version, client.WebSDKToken)))
	req.Header.Set(AcceptHeader, ApplicationJSON)
	req.Header.Set(ContentTypeHeader, contentType)

	uuid, _ := uuid.NewV4()
	nonce := uuid.String()

	Authenticate(req, encodedBody, time.Now().In(time.UTC), client.ClientConfiguration.APIKeyID, client.ClientConfiguration.APIKeySecret, nonce)
	return req
}
コード例 #8
0
func randomName() string {
	uuid, _ := uuid.NewV4()
	return uuid.String()
}