diff --git a/client.go b/client.go new file mode 100644 index 00000000..b70f614e --- /dev/null +++ b/client.go @@ -0,0 +1,111 @@ +package sls + +import ( + "encoding/json" + "fmt" +) + +// Error defines sls error +type Error struct { + Code string `json:"errorCode"` + Message string `json:"errorMessage"` + RequestID string `json:"requestID"` +} + +// NewClientError new client error +func NewClientError(message string) *Error { + err := new(Error) + err.Code = "ClientError" + err.Message = message + return err +} + +func (e Error) String() string { + b, err := json.MarshalIndent(e, "", " ") + if err != nil { + return "" + } + return string(b) +} + +func (e Error) Error() string { + return e.String() +} + +// Client ... +type Client struct { + Endpoint string // IP or hostname of SLS endpoint + AccessKeyID string + AccessKeySecret string + SecurityToken string +} + +func convert(c *Client, projName string) *LogProject { + return &LogProject{ + Name: projName, + Endpoint: c.Endpoint, + AccessKeyID: c.AccessKeyID, + AccessKeySecret: c.AccessKeySecret, + SecurityToken: c.SecurityToken, + } +} + +// CreateProject create a new loghub project. +func (c *Client) CreateProject(name, description string) (*LogProject, error) { + type Body struct { + ProjectName string `json:"projectName"` + Description string `json:"description"` + } + body, err := json.Marshal(Body{ + ProjectName: name, + Description: description, + }) + if err != nil { + return nil, err + } + + h := map[string]string{ + "x-log-bodyrawsize": fmt.Sprintf("%d", len(body)), + "Content-Type": "application/json", + "Accept-Encoding": "deflate", // TODO: support lz4 + } + + uri := "/" + proj := convert(c, name) + _, err = request(proj, "POST", uri, h, body) + if err != nil { + return nil, err + } + + return proj, nil +} + +func (c *Client) GetProject(name string) (*LogProject, error) { + h := map[string]string{ + "x-log-bodyrawsize": "0", + } + + uri := "/" + proj := convert(c, name) + _, err := request(proj, "GET", uri, h, nil) + if err != nil { + return nil, err + } + + return proj, nil +} + +func (c *Client) DeleteProject(name string) error { + h := map[string]string{ + "x-log-bodyrawsize": "0", + } + + proj := convert(c, name) + uri := "/" + _, err := request(proj, "DELETE", uri, h, nil) + if err != nil { + return err + } + + return nil +} diff --git a/config.go b/config.go index 2d196d68..0152040c 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,7 @@ package sls const ( - version = "0.5.0" // SDK version + version = "0.6.0" // SDK version signatureMethod = "hmac-sha1" // Signature method // OffsetNewest stands for the log head offset, i.e. the offset that will be @@ -12,8 +12,8 @@ const ( OffsetOldest = "begin" // ProgressHeader stands for the progress header in GetLogs response - ProgressHeader = "X-Sls-Progress" + ProgressHeader = "X-Log-Progress" // GetLogsCountHeader stands for the count header in GetLogs response - GetLogsCountHeader = "X-Sls-Count" + GetLogsCountHeader = "X-Log-Count" ) diff --git a/example/log_config_sample.go b/example/log_config_sample.go index d5c27d7a..1c3f5a22 100644 --- a/example/log_config_sample.go +++ b/example/log_config_sample.go @@ -1,5 +1,6 @@ package main +/* import ( "fmt" sls "github.com/galaxydi/go-loghub" @@ -119,3 +120,4 @@ func createConfig(configName string, projectName string, logstore string, servic } return nil } +*/ diff --git a/log_project.go b/log_project.go index b0fe2856..e7964d15 100644 --- a/log_project.go +++ b/log_project.go @@ -7,39 +7,13 @@ import ( "net/http" ) -// Error defines sls error -type Error struct { - Code string `json:"errorCode"` - Message string `json:"errorMessage"` -} - -// NewClientError new client error -func NewClientError(message string) *Error { - err := new(Error) - err.Code = "ClientError" - err.Message = message - return err -} - -func (e Error) String() string { - b, err := json.MarshalIndent(e, "", " ") - if err != nil { - return "" - } - return string(b) -} - -func (e Error) Error() string { - return e.String() -} - // LogProject defines log project type LogProject struct { Name string // Project name Endpoint string // IP or hostname of SLS endpoint AccessKeyID string AccessKeySecret string - SessionToken string + SecurityToken string } // NewLogProject creates a new SLS project. @@ -55,14 +29,14 @@ func NewLogProject(name, endpoint, accessKeyID, accessKeySecret string) (p *LogP // WithToken add token parameter func (p *LogProject) WithToken(token string) (*LogProject, error) { - p.SessionToken = token + p.SecurityToken = token return p, nil } // ListLogStore returns all logstore names of project p. func (p *LogProject) ListLogStore() ([]string, error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/logstores") @@ -91,7 +65,7 @@ func (p *LogProject) ListLogStore() ([]string, error) { // GetLogStore returns logstore according by logstore name. func (p *LogProject) GetLogStore(name string) (*LogStore, error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } r, err := request(p, "GET", "/logstores/"+name, h, nil) @@ -108,6 +82,7 @@ func (p *LogProject) GetLogStore(name string) (*LogStore, error) { s := &LogStore{} json.Unmarshal(buf, s) + s.Name = name s.project = p return s, nil } @@ -133,7 +108,7 @@ func (p *LogProject) CreateLogStore(name string, ttl, shardCnt int) error { } h := map[string]string{ - "x-sls-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", "Accept-Encoding": "deflate", // TODO: support lz4 } @@ -155,7 +130,7 @@ func (p *LogProject) CreateLogStore(name string, ttl, shardCnt int) error { // DeleteLogStore deletes a logstore according by logstore name. func (p *LogProject) DeleteLogStore(name string) (err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } r, err := request(p, "DELETE", "/logstores/"+name, h, nil) @@ -191,7 +166,7 @@ func (p *LogProject) UpdateLogStore(name string, ttl, shardCnt int) (err error) } h := map[string]string{ - "x-sls-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", "Accept-Encoding": "deflate", // TODO: support lz4 } @@ -213,7 +188,7 @@ func (p *LogProject) UpdateLogStore(name string, ttl, shardCnt int) (err error) // The offset starts from 0 and the size is the max number of machine groups could be returned. func (p *LogProject) ListMachineGroup(offset, size int) (m []string, total int, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } if size <= 0 { size = 500 @@ -246,7 +221,7 @@ func (p *LogProject) ListMachineGroup(offset, size int) (m []string, total int, // CheckMachineGroupExist check machine group exist or not func (p *LogProject) CheckMachineGroupExist(name string) (exist bool, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } r, err := request(p, "GET", "/machinegroups/"+name, h, nil) if err != nil { @@ -270,7 +245,7 @@ func (p *LogProject) CheckMachineGroupExist(name string) (exist bool, err error) // GetMachineGroup retruns machine group according by machine group name. func (p *LogProject) GetMachineGroup(name string) (m *MachineGroup, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } resp, err := request(p, "GET", "/machinegroups/"+name, h, nil) if err != nil { @@ -298,7 +273,7 @@ func (p *LogProject) CreateMachineGroup(m *MachineGroup) error { } h := map[string]string{ - "x-sls-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", "Accept-Encoding": "deflate", // TODO: support lz4 } @@ -324,7 +299,7 @@ func (p *LogProject) UpdateMachineGroup(m *MachineGroup) (err error) { } h := map[string]string{ - "x-sls-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", "Accept-Encoding": "deflate", // TODO: support lz4 } @@ -345,7 +320,7 @@ func (p *LogProject) UpdateMachineGroup(m *MachineGroup) (err error) { // DeleteMachineGroup deletes machine group according machine group name. func (p *LogProject) DeleteMachineGroup(name string) (err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } r, err := request(p, "DELETE", "/machinegroups/"+name, h, nil) if err != nil { @@ -366,7 +341,7 @@ func (p *LogProject) DeleteMachineGroup(name string) (err error) { // The offset starts from 0 and the size is the max number of configs could be returned. func (p *LogProject) ListConfig(offset, size int) (cfgNames []string, total int, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } if size <= 0 { size = 100 @@ -398,7 +373,7 @@ func (p *LogProject) ListConfig(offset, size int) (cfgNames []string, total int, // CheckConfigExist check config exist or not func (p *LogProject) CheckConfigExist(name string) (exist bool, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } r, err := request(p, "GET", "/configs/"+name, h, nil) if err != nil { @@ -423,7 +398,7 @@ func (p *LogProject) CheckConfigExist(name string) (exist bool, err error) { // GetConfig returns config according by config name. func (p *LogProject) GetConfig(name string) (c *LogConfig, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } r, err := request(p, "GET", "/configs/"+name, h, nil) if err != nil { @@ -451,7 +426,7 @@ func (p *LogProject) UpdateConfig(c *LogConfig) (err error) { } h := map[string]string{ - "x-sls-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", "Accept-Encoding": "deflate", // TODO: support lz4 } @@ -477,7 +452,7 @@ func (p *LogProject) CreateConfig(c *LogConfig) (err error) { } h := map[string]string{ - "x-sls-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/json", "Accept-Encoding": "deflate", // TODO: support lz4 } @@ -498,7 +473,7 @@ func (p *LogProject) CreateConfig(c *LogConfig) (err error) { // DeleteConfig deletes a config according by config name. func (p *LogProject) DeleteConfig(name string) (err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } r, err := request(p, "DELETE", "/configs/"+name, h, nil) if err != nil { @@ -518,7 +493,7 @@ func (p *LogProject) DeleteConfig(name string) (err error) { // GetAppliedMachineGroups returns applied machine group names list according config name. func (p *LogProject) GetAppliedMachineGroups(confName string) (groupNames []string, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/configs/%v/machinegroups", confName) r, err := request(p, "GET", uri, h, nil) @@ -546,7 +521,7 @@ func (p *LogProject) GetAppliedMachineGroups(confName string) (groupNames []stri // GetAppliedConfigs returns applied config names list according machine group name groupName. func (p *LogProject) GetAppliedConfigs(groupName string) (confNames []string, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/machinegroups/%v/configs", groupName) r, err := request(p, "GET", uri, h, nil) @@ -574,7 +549,7 @@ func (p *LogProject) GetAppliedConfigs(groupName string) (confNames []string, er // ApplyConfigToMachineGroup applies config to machine group. func (p *LogProject) ApplyConfigToMachineGroup(confName, groupName string) (err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/machinegroups/%v/configs/%v", groupName, confName) r, err := request(p, "PUT", uri, h, nil) @@ -595,7 +570,7 @@ func (p *LogProject) ApplyConfigToMachineGroup(confName, groupName string) (err // RemoveConfigFromMachineGroup removes config from machine group. func (p *LogProject) RemoveConfigFromMachineGroup(confName, groupName string) (err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/machinegroups/%v/configs/%v", groupName, confName) r, err := request(p, "DELETE", uri, h, nil) diff --git a/log_store.go b/log_store.go index 17082a2d..7cf963c7 100644 --- a/log_store.go +++ b/log_store.go @@ -33,7 +33,7 @@ type Shard struct { // ListShards returns shard id list of this logstore. func (s *LogStore) ListShards() (shardIDs []int, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/logstores/%v/shards", s.Name) r, err := request(s.project, "GET", uri, h, nil) @@ -76,8 +76,8 @@ func (s *LogStore) PutLogs(lg *LogGroup) (err error) { } h := map[string]string{ - "x-sls-compresstype": "lz4", - "x-sls-bodyrawsize": fmt.Sprintf("%v", len(body)), + "x-log-compresstype": "lz4", + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), "Content-Type": "application/x-protobuf", } @@ -101,7 +101,7 @@ func (s *LogStore) PutLogs(lg *LogGroup) (err error) { // For more detail please read: http://gitlab.alibaba-inc.com/sls/doc/blob/master/api/shard.md#logstore func (s *LogStore) GetCursor(shardID int, from string) (cursor string, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/logstores/%v/shards/%v?type=cursor&from=%v", s.Name, shardID, from) @@ -149,7 +149,7 @@ func (s *LogStore) GetCursor(shardID int, from string) (cursor string, err error func (s *LogStore) GetLogsBytes(shardID int, cursor, endCursor string, logGroupMaxCount int) (out []byte, nextCursor string, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", "Accept": "application/x-protobuf", "Accept-Encoding": "lz4", } @@ -181,9 +181,9 @@ func (s *LogStore) GetLogsBytes(shardID int, cursor, endCursor string, err = fmt.Errorf("%v:%v", errMsg.Code, errMsg.Message) return } - v, ok := r.Header["X-Sls-Compresstype"] + v, ok := r.Header["X-Log-Compresstype"] if !ok || len(v) == 0 { - err = fmt.Errorf("can't find 'x-sls-compresstype' header") + err = fmt.Errorf("can't find 'x-log-compresstype' header") return } if v[0] != "lz4" { @@ -191,16 +191,16 @@ func (s *LogStore) GetLogsBytes(shardID int, cursor, endCursor string, return } - v, ok = r.Header["X-Sls-Cursor"] + v, ok = r.Header["X-Log-Cursor"] if !ok || len(v) == 0 { - err = fmt.Errorf("can't find 'x-sls-cursor' header") + err = fmt.Errorf("can't find 'x-log-cursor' header") return } nextCursor = v[0] - v, ok = r.Header["X-Sls-Bodyrawsize"] + v, ok = r.Header["X-Log-Bodyrawsize"] if !ok || len(v) == 0 { - err = fmt.Errorf("can't find 'x-sls-bodyrawsize' header") + err = fmt.Errorf("can't find 'x-log-bodyrawsize' header") return } bodyRawSize, err := strconv.Atoi(v[0]) @@ -253,7 +253,7 @@ func (s *LogStore) GetLogs(topic string, from int64, to int64, queryExp string, maxLineNum int64, offset int64, reverse bool) (*GetLogsResponse, error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", "Accept": "application/json", } @@ -290,3 +290,97 @@ func (s *LogStore) GetLogs(topic string, from int64, to int64, queryExp string, return &getLogsResponse, nil } + +func (s *LogStore) CreateIndex(index Index) error { + body, err := json.Marshal(index) + if err != nil { + return err + } + + h := map[string]string{ + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), + "Content-Type": "application/json", + "Accept-Encoding": "deflate", // TODO: support lz4 + } + + uri := fmt.Sprintf("/logstores/%s/index", s.Name) + _, err = request(s.project, "POST", uri, h, body) + return err +} + +func (s *LogStore) UpdateIndex(index Index) error { + body, err := json.Marshal(index) + if err != nil { + return err + } + + h := map[string]string{ + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), + "Content-Type": "application/json", + "Accept-Encoding": "deflate", // TODO: support lz4 + } + + uri := fmt.Sprintf("/logstores/%s/index", s.Name) + _, err = request(s.project, "PUT", uri, h, body) + return err +} + +func (s *LogStore) DeleteIndex() error { + type Body struct { + project string `json:"projectName"` + store string `json:"logstoreName"` + } + + body, err := json.Marshal(Body{ + project: s.project.Name, + store: s.Name, + }) + if err != nil { + return err + } + + h := map[string]string{ + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), + "Content-Type": "application/json", + "Accept-Encoding": "deflate", // TODO: support lz4 + } + + uri := fmt.Sprintf("/logstores/%s/index", s.Name) + _, err = request(s.project, "DELETE", uri, h, body) + return err +} + +func (s *LogStore) GetIndex() (*Index, error) { + type Body struct { + project string `json:"projectName"` + store string `json:"logstoreName"` + } + + body, err := json.Marshal(Body{ + project: s.project.Name, + store: s.Name, + }) + if err != nil { + return nil, err + } + + h := map[string]string{ + "x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), + "Content-Type": "application/json", + "Accept-Encoding": "deflate", // TODO: support lz4 + } + + uri := fmt.Sprintf("/logstores/%s/index", s.Name) + resp, err := request(s.project, "GET", uri, h, body) + if err != nil { + } + + index := &Index{} + data, _ := ioutil.ReadAll(resp.Body) + err = json.Unmarshal(data, index) + if err != nil { + return nil, err + } + + return index, err +} diff --git a/machine_group.go b/machine_group.go index ff7e07c9..1c96b28c 100644 --- a/machine_group.go +++ b/machine_group.go @@ -47,7 +47,7 @@ type MachineList struct { // ListMachines returns machine list of this machine group. func (m *MachineGroup) ListMachines() (ms []*Machine, total int, err error) { h := map[string]string{ - "x-sls-bodyrawsize": "0", + "x-log-bodyrawsize": "0", } uri := fmt.Sprintf("/machinegroups/%v/machines", m.Name) diff --git a/model.go b/model.go index 30b733bd..cfec09ad 100644 --- a/model.go +++ b/model.go @@ -6,3 +6,24 @@ type GetLogsResponse struct { Count int64 `json:"count"` Logs []map[string]string `json:"logs"` } + +// IndexKey ... +type IndexKey struct { + Token []string `json:"token"` // tokens that split the log line. + CaseSensitive bool `json:"caseSensitive"` + Type string `json:"type"` // text, long, double +} + +type IndexLine struct { + Token []string `json:"token"` + CaseSensitive bool `json:"caseSensitive"` + IncludeKeys []string `json:"include_keys,omitempty"` + ExcludeKeys []string `json:"exclude_keys,omitempty"` +} + +// Index is an index config for a log store. +type Index struct { + TTL int `json:"ttl"` + Keys map[string]IndexKey `json:"keys,omitempty"` + Line *IndexLine `json:"line,omitempty"` +} diff --git a/request.go b/request.go index 653f8499..279a6d4b 100644 --- a/request.go +++ b/request.go @@ -7,36 +7,37 @@ import ( "net/http" "net/http/httputil" + "encoding/json" + "io/ioutil" + "github.com/golang/glog" ) // request sends a request to SLS. func request(project *LogProject, method, uri string, headers map[string]string, - body []byte) (resp *http.Response, err error) { + body []byte) (*http.Response, error) { - // The caller should provide 'x-sls-bodyrawsize' header - if _, ok := headers["x-sls-bodyrawsize"]; !ok { - err = fmt.Errorf("Can't find 'x-sls-bodyrawsize' header") - return + // The caller should provide 'x-log-bodyrawsize' header + if _, ok := headers["x-log-bodyrawsize"]; !ok { + return nil, fmt.Errorf("Can't find 'x-log-bodyrawsize' header") } // SLS public request headers headers["Host"] = project.Name + "." + project.Endpoint headers["Date"] = nowRFC1123() - headers["x-sls-apiversion"] = version - headers["x-sls-signaturemethod"] = signatureMethod + headers["x-log-apiversion"] = version + headers["x-log-signaturemethod"] = signatureMethod // Access with token - if project.SessionToken != "" { - headers["x-acs-security-token"] = project.SessionToken + if project.SecurityToken != "" { + headers["x-acs-security-token"] = project.SecurityToken } if body != nil { bodyMD5 := fmt.Sprintf("%X", md5.Sum(body)) headers["Content-MD5"] = bodyMD5 if _, ok := headers["Content-Type"]; !ok { - err = fmt.Errorf("Can't find 'Content-Type' header") - return + return nil, fmt.Errorf("Can't find 'Content-Type' header") } } @@ -44,17 +45,17 @@ func request(project *LogProject, method, uri string, headers map[string]string, // Authorization = "SLS :" digest, err := signature(project, method, uri, headers) if err != nil { - return + return nil, err } auth := fmt.Sprintf("SLS %v:%v", project.AccessKeyID, digest) headers["Authorization"] = auth // Initialize http request reader := bytes.NewReader(body) - urlStr := fmt.Sprintf("http://%v.%v%v", project.Name, project.Endpoint, uri) + urlStr := fmt.Sprintf("https://%v.%v%v", project.Name, project.Endpoint, uri) req, err := http.NewRequest(method, urlStr, reader) if err != nil { - return + return nil, err } for k, v := range headers { req.Header.Add(k, v) @@ -69,9 +70,18 @@ func request(project *LogProject, method, uri string, headers map[string]string, } // Get ready to do request - resp, err = http.DefaultClient.Do(req) + resp, err := http.DefaultClient.Do(req) if err != nil { - return + return nil, err + } + + // Parse the sls error from body. + if resp.StatusCode != http.StatusOK { + err := &Error{} + buf, _ := ioutil.ReadAll(resp.Body) + json.Unmarshal(buf, err) + err.RequestID = resp.Header.Get("x-log-requestid") + return nil, err } if glog.V(1) { @@ -81,5 +91,5 @@ func request(project *LogProject, method, uri string, headers map[string]string, } glog.Infof("HTTP Response:\n%v", string(dump)) } - return + return resp, nil } diff --git a/signature.go b/signature.go index 012cabf0..4d17a736 100644 --- a/signature.go +++ b/signature.go @@ -44,7 +44,7 @@ func signature(project *LogProject, method, uri string, slsHeaders := make(map[string]string, len(headers)) for k, v := range headers { l := strings.TrimSpace(strings.ToLower(k)) - if strings.HasPrefix(l, "x-sls-") || strings.HasPrefix(l, "x-acs-") { + if strings.HasPrefix(l, "x-log-") || strings.HasPrefix(l, "x-acs-") { slsHeaders[l] = strings.TrimSpace(v) slsHeaderKeys = append(slsHeaderKeys, l) } diff --git a/signature_test.go b/signature_test.go index 01a9cfcd..dc523e2b 100644 --- a/signature_test.go +++ b/signature_test.go @@ -19,12 +19,12 @@ var project = &LogProject{ func TestSignatureGet(t *testing.T) { defer glog.Flush() h := map[string]string{ - "x-sls-apiversion": "0.4.0", - "x-sls-signaturemethod": "hmac-sha1", - "x-sls-bodyrawsize": "0", + "x-log-apiversion": "0.6.0", + "x-log-signaturemethod": "hmac-sha1", + "x-log-bodyrawsize": "0", "Date": "Mon, 3 Jan 2010 08:33:47 GMT", } - digest := "3DGtV4yTxzzqTCxfXTPGKWmHX8M=" + digest := "Rwm6cTKzoti4HWoe+GKcb6Kv07E=" s, err := signature(project, "GET", "/logstores", h) if err != nil { t.Fatal(err) @@ -76,16 +76,16 @@ func TestSignaturePost(t *testing.T) { t.Fatal(err) } h := map[string]string{ - "x-sls-apiversion": "0.4.0", - "x-sls-signaturemethod": "hmac-sha1", - "x-sls-bodyrawsize": "50", + "x-log-apiversion": "0.6.0", + "x-log-signaturemethod": "hmac-sha1", + "x-log-bodyrawsize": "50", "Content-MD5": md5Sum, "Content-Type": "application/x-protobuf", "Content-Length": "50", "Date": "Mon, 3 Jan 2010 08:33:47 GMT", } - digest := "WgfedxpxXG9q2r27d1ex/bHy+tY=" + digest := "87xQWqFaOSewqRIma8kPjGYlXHc=" s, err := signature(project, "GET", "/logstores/app_log", h) if err != nil { t.Fatal(err)