github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/appsec/configuration_version.go (about)

     1  package appsec
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  )
     8  
     9  type (
    10  	// The ConfigurationVersion interface supports retrieving the versions of a configuration.
    11  	ConfigurationVersion interface {
    12  		// GetConfigurationVersions lists available versions for the specified security configuration.
    13  		//
    14  		// See: https://techdocs.akamai.com/application-security/reference/get-config-versions
    15  		GetConfigurationVersions(ctx context.Context, params GetConfigurationVersionsRequest) (*GetConfigurationVersionsResponse, error)
    16  	}
    17  
    18  	// GetConfigurationVersionsRequest is used to retrieve the versions of a security configuration.
    19  	GetConfigurationVersionsRequest struct {
    20  		ConfigID      int `json:"configId"`
    21  		ConfigVersion int `json:"configVersion"`
    22  	}
    23  
    24  	// GetConfigurationVersionsResponse is returned from a call to GetConfigurationVersions.
    25  	GetConfigurationVersionsResponse struct {
    26  		ConfigID           int    `json:"configId,omitempty"`
    27  		ConfigName         string `json:"configName,omitempty"`
    28  		LastCreatedVersion int    `json:"lastCreatedVersion,omitempty"`
    29  		Page               int    `json:"page,omitempty"`
    30  		PageSize           int    `json:"pageSize,omitempty"`
    31  		TotalSize          int    `json:"totalSize,omitempty"`
    32  		VersionList        []struct {
    33  			ConfigID   int `json:"configId,omitempty"`
    34  			Production struct {
    35  				Status string `json:"status,omitempty"`
    36  			} `json:"production,omitempty"`
    37  			Staging struct {
    38  				Status string `json:"status,omitempty"`
    39  			} `json:"staging,omitempty"`
    40  			Version int `json:"version,omitempty"`
    41  			BasedOn int `json:"basedOn,omitempty"`
    42  		} `json:"versionList,omitempty"`
    43  	}
    44  )
    45  
    46  func (p *appsec) GetConfigurationVersions(ctx context.Context, params GetConfigurationVersionsRequest) (*GetConfigurationVersionsResponse, error) {
    47  	logger := p.Log(ctx)
    48  	logger.Debug("GetConfigurationVersions")
    49  
    50  	uri := fmt.Sprintf(
    51  		"/appsec/v1/configs/%d/versions?page=-1&detail=false",
    52  		params.ConfigID)
    53  
    54  	req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
    55  	if err != nil {
    56  		return nil, fmt.Errorf("failed to create GetConfigurationVersions request: %w", err)
    57  	}
    58  
    59  	var result GetConfigurationVersionsResponse
    60  	resp, err := p.Exec(req, &result)
    61  	if err != nil {
    62  		return nil, fmt.Errorf("get configuration versions request failed: %w", err)
    63  	}
    64  	if resp.StatusCode != http.StatusOK {
    65  		return nil, p.Error(resp)
    66  	}
    67  
    68  	return &result, nil
    69  }