github.com/akamai/AkamaiOPEN-edgegrid-golang@v1.2.2/api-endpoints-v2/activations.go (about)

     1  package apiendpoints
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
     7  )
     8  
     9  type Activation struct {
    10  	Networks               []string `json:"networks"`
    11  	NotificationRecipients []string `json:"notificationRecipients"`
    12  	Notes                  string   `json:"notes"`
    13  }
    14  
    15  type ActivateEndpointOptions struct {
    16  	APIEndPointId int
    17  	VersionNumber int
    18  }
    19  
    20  func ActivateEndpoint(options *ActivateEndpointOptions, activation *Activation) (*Activation, error) {
    21  	req, err := client.NewJSONRequest(
    22  		Config,
    23  		"POST",
    24  		fmt.Sprintf(
    25  			"/api-definitions/v2/endpoints/%d/versions/%d/activate",
    26  			options.APIEndPointId,
    27  			options.VersionNumber,
    28  		),
    29  		activation,
    30  	)
    31  
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	res, err := client.Do(Config, req)
    37  
    38  	if client.IsError(res) {
    39  		return nil, client.NewAPIError(res)
    40  	}
    41  
    42  	return activation, nil
    43  }
    44  
    45  func DeactivateEndpoint(options *ActivateEndpointOptions, activation *Activation) (*Activation, error) {
    46  	req, err := client.NewJSONRequest(
    47  		Config,
    48  		"DELETE",
    49  		fmt.Sprintf(
    50  			"/api-definitions/v2/endpoints/%d/versions/%d/deactivate",
    51  			options.APIEndPointId,
    52  			options.VersionNumber,
    53  		),
    54  		activation,
    55  	)
    56  
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  
    61  	res, err := client.Do(Config, req)
    62  
    63  	if client.IsError(res) {
    64  		return nil, client.NewAPIError(res)
    65  	}
    66  
    67  	return activation, nil
    68  }
    69  
    70  func IsActive(endpoint *Endpoint, network string) bool {
    71  	if network == "production" {
    72  		if endpoint.ProductionStatus == StatusPending || endpoint.ProductionStatus == StatusActive {
    73  			return true
    74  		}
    75  	}
    76  
    77  	if network == "staging" {
    78  		if endpoint.StagingStatus == StatusPending || endpoint.StagingStatus == StatusActive {
    79  			return true
    80  		}
    81  	}
    82  
    83  	return false
    84  }