* Update Request Header Prefixes and Upgrade API Version to 0.6.0 - Changed all HTTP request header prefixes from `x-sls-` to `x-log-` to comply with the latest API specifications. - Adjusted header prefix validation in `signature.go` to support `x-log-` and `x-acs-`. - Replaced `x-sls-bodyrawsize` with `x-log-bodyrawsize` in multiple files (`log_project.go`, `request.go`, etc.). - Updated header fields for compression type and signing method (e.g., `x-sls-compresstype` to `x-log-compresstype`). - Modified authorization logic to replace `SLS` with `LOG`. * Refactor signature generation logic for improved readability and maintainability Split the signature generation logic into several independent functions, including header extraction, standardized header construction, and resource string generation. This modular design enhances code clarity, reduces redundant logic, and improves error handling mechanisms. Additionally, comments and code structure have been optimized to ensure easier extension and debugging. --------- Co-authored-by: 优胜 <zhushaofei.zsf@alibaba-inc.com>
		
			
				
	
	
		
			92 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
		
			Executable File
		
	
	
	
	
| package alils
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"fmt"
 | |
| 	"io"
 | |
| 	"net/http"
 | |
| 	"net/http/httputil"
 | |
| )
 | |
| 
 | |
| // MachineGroupAttribute defines the Attribute
 | |
| type MachineGroupAttribute struct {
 | |
| 	ExternalName string `json:"externalName"`
 | |
| 	TopicName    string `json:"groupTopic"`
 | |
| }
 | |
| 
 | |
| // MachineGroup defines the machine Group
 | |
| type MachineGroup struct {
 | |
| 	Name          string   `json:"groupName"`
 | |
| 	Type          string   `json:"groupType"`
 | |
| 	MachineIDType string   `json:"machineIdentifyType"`
 | |
| 	MachineIDList []string `json:"machineList"`
 | |
| 
 | |
| 	Attribute MachineGroupAttribute `json:"groupAttribute"`
 | |
| 
 | |
| 	CreateTime     uint32
 | |
| 	LastModifyTime uint32
 | |
| 
 | |
| 	project *LogProject
 | |
| }
 | |
| 
 | |
| // Machine defines the Machine
 | |
| type Machine struct {
 | |
| 	IP            string
 | |
| 	UniqueID      string `json:"machine-uniqueid"`
 | |
| 	UserdefinedID string `json:"userdefined-id"`
 | |
| }
 | |
| 
 | |
| // MachineList defines the Machine List
 | |
| type MachineList struct {
 | |
| 	Total    int
 | |
| 	Machines []*Machine
 | |
| }
 | |
| 
 | |
| // ListMachines returns the machine list of this machine group.
 | |
| func (m *MachineGroup) ListMachines() (ms []*Machine, total int, err error) {
 | |
| 	h := map[string]string{
 | |
| 		"x-log-bodyrawsize": "0",
 | |
| 	}
 | |
| 
 | |
| 	uri := fmt.Sprintf("/machinegroups/%v/machines", m.Name)
 | |
| 	r, err := request(m.project, "GET", uri, h, nil)
 | |
| 	if err != nil {
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	buf, err := io.ReadAll(r.Body)
 | |
| 	if err != nil {
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	if r.StatusCode != http.StatusOK {
 | |
| 		errMsg := &errorMessage{}
 | |
| 		err = json.Unmarshal(buf, errMsg)
 | |
| 		if err != nil {
 | |
| 			err = fmt.Errorf("failed to remove config from machine group")
 | |
| 			dump, _ := httputil.DumpResponse(r, true)
 | |
| 			fmt.Println(dump)
 | |
| 			return
 | |
| 		}
 | |
| 		err = fmt.Errorf("%v:%v", errMsg.Code, errMsg.Message)
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	body := &MachineList{}
 | |
| 	err = json.Unmarshal(buf, body)
 | |
| 	if err != nil {
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	ms = body.Machines
 | |
| 	total = body.Total
 | |
| 
 | |
| 	return
 | |
| }
 | |
| 
 | |
| // GetAppliedConfigs returns applied configs of this machine group.
 | |
| func (m *MachineGroup) GetAppliedConfigs() (confNames []string, err error) {
 | |
| 	confNames, err = m.project.GetAppliedConfigs(m.Name)
 | |
| 	return
 | |
| }
 |