Skip to content

Commit

Permalink
release 0.0.2-beta source code
Browse files Browse the repository at this point in the history
  • Loading branch information
fecloud-sdk committed Sep 11, 2023
1 parent fab2f85 commit faff3f8
Show file tree
Hide file tree
Showing 1,974 changed files with 103,831 additions and 368 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# 0.0.6-beta 2023-05-12
# 0.0.1-beta 2023-06-30
Empty file modified LICENSE
100755 → 100644
Empty file.
Empty file modified README.md
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.2-beta
Empty file modified core/auth/basic/basic_icredential.go
100755 → 100644
Empty file.
Empty file modified core/auth/basic/basic_icredential_test.go
100755 → 100644
Empty file.
Empty file modified core/auth/cache/auth_cache.go
100755 → 100644
Empty file.
Empty file modified core/auth/derived_icredential.go
100755 → 100644
Empty file.
Empty file modified core/auth/global/global_icredential.go
100755 → 100644
Empty file.
Empty file modified core/auth/global/global_icredential_test.go
100755 → 100644
Empty file.
Empty file modified core/auth/icredential.go
100755 → 100644
Empty file.
8 changes: 4 additions & 4 deletions core/auth/internal/iam_service.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/fecloud-sdk/fecloud-sdk-go/core/request"
"github.com/fecloud-sdk/fecloud-sdk-go/core/response"
"github.com/fecloud-sdk/fecloud-sdk-go/core/sdkerr"
jsoniter "github.com/json-iterator/go"
"github.com/fecloud-sdk/fecloud-sdk-go/core/utils"
"io/ioutil"
"os"
"reflect"
Expand Down Expand Up @@ -82,7 +82,7 @@ func KeystoneListProjects(client *impl.DefaultHttpClient, req *request.DefaultHt
}

keystoneListProjectResponse := new(KeystoneListProjectsResponse)
err = jsoniter.Unmarshal(data, keystoneListProjectResponse)
err = utils.Unmarshal(data, keystoneListProjectResponse)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func KeystoneListAuthDomains(client *impl.DefaultHttpClient, req *request.Defaul
}

keystoneListAuthDomainsResponse := new(KeystoneListAuthDomainsResponse)
err = jsoniter.Unmarshal(data, keystoneListAuthDomainsResponse)
err = utils.Unmarshal(data, keystoneListAuthDomainsResponse)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -318,7 +318,7 @@ func CreateTokenWithIdToken(client *impl.DefaultHttpClient, req *request.Default
}

createTokenWithIdTokenResponse := new(CreateTokenWithIdTokenResponse)
err = jsoniter.Unmarshal(data, createTokenWithIdTokenResponse)
err = utils.Unmarshal(data, createTokenWithIdTokenResponse)
if err != nil {
return nil, err
}
Expand Down
Empty file modified core/auth/internal/iam_service_test.go
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions core/auth/internal/metadata.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package internal

import (
"encoding/json"
"github.com/fecloud-sdk/fecloud-sdk-go/core/sdkerr"
"github.com/fecloud-sdk/fecloud-sdk-go/core/utils"
"io/ioutil"
"net/http"
"time"
Expand Down Expand Up @@ -65,7 +65,7 @@ func GetCredentialFromMetadata() (*Credential, error) {
}

respModel := &GetTemporaryCredentialFromMetadataResponse{}
err = json.Unmarshal(body, respModel)
err = utils.Unmarshal(body, respModel)
if err != nil {
return nil, err
}
Expand Down
Empty file modified core/auth/provider/credential_provider.go
100755 → 100644
Empty file.
Empty file modified core/auth/provider/env_provider.go
100755 → 100644
Empty file.
Empty file modified core/auth/provider/env_provider_test.go
100755 → 100644
Empty file.
Empty file modified core/auth/provider/metadata_provider.go
100755 → 100644
Empty file.
Empty file modified core/auth/provider/metadata_provider_test.go
100755 → 100644
Empty file.
Empty file modified core/auth/provider/profile_provider.go
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions core/auth/provider/profile_provider_test.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func TestProfileCredentialProvider_GetCredentials(t *testing.T) {

file, err := os.Create(path)
assert.Nil(t, err)
err = file.Chmod(0600)
assert.Nil(t, err)
_, err = file.WriteString(credentialStr)
assert.Nil(t, err)
err = file.Close()
Expand Down
Empty file modified core/auth/provider/provider_chain.go
100755 → 100644
Empty file.
Empty file modified core/auth/provider/provider_chain_test.go
100755 → 100644
Empty file.
Empty file modified core/auth/signer/derived_signer.go
100755 → 100644
Empty file.
Empty file modified core/auth/signer/escape.go
100755 → 100644
Empty file.
Empty file modified core/auth/signer/signer.go
100755 → 100644
Empty file.
51 changes: 44 additions & 7 deletions core/config/http_config.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ import (
"fmt"
"github.com/fecloud-sdk/fecloud-sdk-go/core/httphandler"
"net"
"net/http"
"time"
)

const DefaultTimeout = 120 * time.Second
const DefaultRetries = 0
const DefaultIgnoreSSLVerification = false
const (
DefaultTimeout = 120 * time.Second
DefaultRetries = 0
DefaultIgnoreSSLVerification = false
DefaultIgnoreContentTypeForGetRequest = false
)

type DialContext func(ctx context.Context, network string, addr string) (net.Conn, error)

Expand All @@ -39,14 +43,25 @@ type HttpConfig struct {
Retries int
HttpProxy *Proxy
IgnoreSSLVerification bool
HttpHandler *httphandler.HttpHandler
// AllowRedirects Experimental configuration, the default value is false.
// Automatic redirection is allowed when turns on, which may cause some request exceptions.
AllowRedirects bool
HttpHandler *httphandler.HttpHandler
// HttpTransport This configuration has the highest priority,
// which means specifying the HttpTransport will invalidate other configurations,
// such as DialContext, HttpProxy, IgnoreSSLVerification.
HttpTransport *http.Transport
// IgnoreContentTypeForGetRequest Ignore the request header Content-Type when sending a GET request,
// the default value is false
IgnoreContentTypeForGetRequest bool
}

func DefaultHttpConfig() *HttpConfig {
return &HttpConfig{
Timeout: DefaultTimeout,
Retries: DefaultRetries,
IgnoreSSLVerification: DefaultIgnoreSSLVerification,
Timeout: DefaultTimeout,
Retries: DefaultRetries,
IgnoreSSLVerification: DefaultIgnoreSSLVerification,
IgnoreContentTypeForGetRequest: DefaultIgnoreContentTypeForGetRequest,
}
}

Expand All @@ -70,16 +85,38 @@ func (config *HttpConfig) WithIgnoreSSLVerification(ignore bool) *HttpConfig {
return config
}

// WithAllowRedirects Experimental configuration, the default value is false.
// Automatic redirection is allowed when turns on, which may cause some request exceptions.
func (config *HttpConfig) WithAllowRedirects(allowRedirects bool) *HttpConfig {
config.AllowRedirects = allowRedirects
return config
}

func (config *HttpConfig) WithHttpHandler(handler *httphandler.HttpHandler) *HttpConfig {
config.HttpHandler = handler
return config
}

// WithHttpTransport This configuration has the highest priority,
// which means specifying the HttpTransport will invalidate other configurations,
// such as DialContext, HttpProxy, IgnoreSSLVerification.
func (config *HttpConfig) WithHttpTransport(transport *http.Transport) *HttpConfig {
config.HttpTransport = transport
return config
}

func (config *HttpConfig) WithProxy(proxy *Proxy) *HttpConfig {
config.HttpProxy = proxy
return config
}

// WithIgnoreContentTypeForGetRequest Ignore the request header Content-Type when sending a GET request,
// the default value is false
func (config *HttpConfig) WithIgnoreContentTypeForGetRequest(ignoreContentTypeForGetRequest bool) *HttpConfig {
config.IgnoreContentTypeForGetRequest = ignoreContentTypeForGetRequest
return config
}

type Proxy struct {
Schema string
Host string
Expand Down
Empty file modified core/converter/converters.go
100755 → 100644
Empty file.
Empty file modified core/converter/types.go
100755 → 100644
Empty file.
Empty file modified core/def/field.go
100755 → 100644
Empty file.
Empty file modified core/def/http_request_def.go
100755 → 100644
Empty file.
Empty file modified core/def/multipart.go
100755 → 100644
Empty file.
Empty file modified core/exchange/exchange.go
100755 → 100644
Empty file.
Empty file modified core/exchange/reference.go
100755 → 100644
Empty file.
40 changes: 30 additions & 10 deletions core/hc_http_client.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ import (
"errors"
"fmt"
"github.com/fecloud-sdk/fecloud-sdk-go/core/auth"
"github.com/fecloud-sdk/fecloud-sdk-go/core/config"
"github.com/fecloud-sdk/fecloud-sdk-go/core/converter"
"github.com/fecloud-sdk/fecloud-sdk-go/core/def"
"github.com/fecloud-sdk/fecloud-sdk-go/core/exchange"
"github.com/fecloud-sdk/fecloud-sdk-go/core/impl"
"github.com/fecloud-sdk/fecloud-sdk-go/core/progress"
"github.com/fecloud-sdk/fecloud-sdk-go/core/request"
"github.com/fecloud-sdk/fecloud-sdk-go/core/response"
"github.com/fecloud-sdk/fecloud-sdk-go/core/sdkerr"
jsoniter "github.com/json-iterator/go"
"github.com/fecloud-sdk/fecloud-sdk-go/core/utils"
"go.mongodb.org/mongo-driver/bson"
"io/ioutil"
"net"
Expand All @@ -57,6 +59,7 @@ type HcHttpClient struct {
credential auth.ICredential
extraHeader map[string]string
httpClient *impl.DefaultHttpClient
httpConfig config.HttpConfig
}

func NewHcHttpClient(httpClient *impl.DefaultHttpClient) *HcHttpClient {
Expand All @@ -73,6 +76,11 @@ func (hc *HcHttpClient) WithCredential(credential auth.ICredential) *HcHttpClien
return hc
}

func (hc *HcHttpClient) WithHttpConfig(httpConfig config.HttpConfig) *HcHttpClient {
hc.httpConfig = httpConfig
return hc
}

func (hc *HcHttpClient) GetCredential() auth.ICredential {
return hc.credential
}
Expand Down Expand Up @@ -154,8 +162,8 @@ func (hc *HcHttpClient) buildRequest(req interface{}, reqDef *def.HttpRequestDef
WithMethod(reqDef.Method).
WithPath(reqDef.Path)

if reqDef.ContentType != "" {
builder.AddHeaderParam(contentType, reqDef.ContentType)
if pq, ok := req.(progress.Request); ok {
builder.WithProgressListener(pq.GetProgressListener()).WithProgressInterval(pq.GetProgressInterval())
}

uaValue := "fecloud-usdk-go/3.0"
Expand Down Expand Up @@ -188,7 +196,7 @@ func (hc *HcHttpClient) buildRequest(req interface{}, reqDef *def.HttpRequestDef

func (hc *HcHttpClient) fillParamsFromReq(req interface{}, t reflect.Type, reqDef *def.HttpRequestDef,
attrMaps map[string]string, builder *request.HttpRequestBuilder) (*request.HttpRequestBuilder, error) {

hasBody := false
for _, fieldDef := range reqDef.RequestFields {
value, err := hc.getFieldValueByName(fieldDef.Name, attrMaps, req)
if err != nil {
Expand Down Expand Up @@ -217,11 +225,16 @@ func (hc *HcHttpClient) fillParamsFromReq(req interface{}, t reflect.Type, reqDe
} else {
builder.WithBody("", value.Interface())
}
hasBody = true
case def.Form:
builder.AddFormParam(fieldDef.JsonTag, value.Interface().(def.FormData))
}
}

if reqDef.ContentType != "" && !(hc.httpConfig.IgnoreContentTypeForGetRequest && reqDef.Method == "GET" && !hasBody) {
builder.AddHeaderParam(contentType, reqDef.ContentType)
}

return builder, nil
}

Expand Down Expand Up @@ -262,13 +275,20 @@ func (hc *HcHttpClient) getFieldValueByName(name string, jsonTag map[string]stri

func flattenEnumStruct(value reflect.Value) (reflect.Value, error) {
if value.Kind() == reflect.Struct {
v, e := jsoniter.Marshal(value.Interface())
if method := value.MethodByName("Value"); method.IsValid() {
return method.Call(nil)[0], nil
}

v, e := utils.Marshal(value.Interface())
if e == nil {
if strings.HasPrefix(string(v), "\"") {
return reflect.ValueOf(strings.Trim(string(v), "\"")), nil
} else {
return reflect.ValueOf(string(v)), nil
str := string(v)
if strings.HasSuffix(str, "\n") {
str = strings.Trim(str, "\n")
}
if strings.HasPrefix(str, "\"") {
str = strings.Trim(str, "\"")
}
return reflect.ValueOf(str), nil
}
return reflect.ValueOf(nil), e
}
Expand Down Expand Up @@ -367,7 +387,7 @@ func (hc *HcHttpClient) deserializeResponseFields(resp *response.DefaultHttpResp
} else if strings.Contains(resp.Response.Header.Get(contentType), applicationBson) {
err = bson.Unmarshal(data, reqDef.Response)
} else {
err = jsoniter.Unmarshal(data, &reqDef.Response)
err = utils.Unmarshal(data, &reqDef.Response)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/hc_http_client_builder.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ func (builder *HcHttpClientBuilder) Build() *HcHttpClient {
}
}

hcHttpClient := NewHcHttpClient(defaultHttpClient).WithEndpoints(builder.endpoints).WithCredential(builder.credentials)
hcHttpClient := NewHcHttpClient(defaultHttpClient).WithEndpoints(builder.endpoints).WithCredential(builder.credentials).WithHttpConfig(*builder.httpConfig)
return hcHttpClient
}
Empty file modified core/hc_http_client_builder_test.go
100755 → 100644
Empty file.
Empty file modified core/httphandler/http_handler.go
100755 → 100644
Empty file.
Loading

0 comments on commit faff3f8

Please sign in to comment.