Skip to content

Commit

Permalink
Merge pull request #140 from akamai/release/v2.7.0
Browse files Browse the repository at this point in the history
Release/v2.7.0
  • Loading branch information
robertolopezlopez authored Oct 19, 2021
2 parents fc044c9 + 2cce7d8 commit 4314ddd
Show file tree
Hide file tree
Showing 29 changed files with 3,623 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# EDGEGRID GOLANG RELEASE NOTES

## 2.7.0 (Oct 19, 2021)

#### FEATURES/ENHANCEMENTS:
* [IMPORTANT] Added DataStream API support
* Stream operations
* Stream activation operations
* Read access to various DataStream properties
* Added HAPI v1 support
* Delete edge hostname

## 2.6.0 (Aug 16, 2021)

#### BUG FIXES:
Expand Down
259 changes: 259 additions & 0 deletions pkg/datastream/connectors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
package datastream

import validation "github.com/go-ozzo/ozzo-validation/v4"

type (
// S3Connector provides details about the Amazon S3 connector in a stream
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#amazons3
S3Connector struct {
ConnectorType ConnectorType `json:"connectorType"`
AccessKey string `json:"accessKey"`
Bucket string `json:"bucket"`
ConnectorName string `json:"connectorName"`
Path string `json:"path"`
Region string `json:"region"`
SecretAccessKey string `json:"secretAccessKey"`
}

// AzureConnector provides details about the Azure Storage connector configuration in a data stream
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#azurestorage
AzureConnector struct {
ConnectorType ConnectorType `json:"connectorType"`
AccessKey string `json:"accessKey"`
AccountName string `json:"accountName"`
ConnectorName string `json:"connectorName"`
ContainerName string `json:"containerName"`
Path string `json:"path"`
}

// DatadogConnector provides detailed information about Datadog connector
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#datadog
DatadogConnector struct {
ConnectorType ConnectorType `json:"connectorType"`
AuthToken string `json:"authToken"`
CompressLogs bool `json:"compressLogs"`
ConnectorName string `json:"connectorName"`
Service string `json:"service,omitempty"`
Source string `json:"source,omitempty"`
Tags string `json:"tags,omitempty"`
URL string `json:"url"`
}

// SplunkConnector provides detailed information about the Splunk connector
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#splunk
SplunkConnector struct {
ConnectorType ConnectorType `json:"connectorType"`
CompressLogs bool `json:"compressLogs"`
ConnectorName string `json:"connectorName"`
EventCollectorToken string `json:"eventCollectorToken"`
URL string `json:"url"`
}

// GCSConnector provides detailed information about the Google Cloud Storage connector
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#googlecloudstorage
GCSConnector struct {
ConnectorType ConnectorType `json:"connectorType"`
Bucket string `json:"bucket"`
ConnectorName string `json:"connectorName"`
Path string `json:"path,omitempty"`
PrivateKey string `json:"privateKey"`
ProjectID string `json:"projectId"`
ServiceAccountName string `json:"serviceAccountName"`
}

// CustomHTTPSConnector provides detailed information about the custom HTTPS endpoint
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#customhttps
CustomHTTPSConnector struct {
ConnectorType ConnectorType `json:"connectorType"`
AuthenticationType AuthenticationType `json:"authenticationType"`
CompressLogs bool `json:"compressLogs"`
ConnectorName string `json:"connectorName"`
Password string `json:"password,omitempty"`
URL string `json:"url"`
UserName string `json:"userName,omitempty"`
}

// SumoLogicConnector provides detailed information about the Sumo Logic connector
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#sumologic
SumoLogicConnector struct {
ConnectorType ConnectorType `json:"connectorType"`
CollectorCode string `json:"collectorCode"`
CompressLogs bool `json:"compressLogs"`
ConnectorName string `json:"connectorName"`
Endpoint string `json:"endpoint"`
}

// OracleCloudStorageConnector provides details about the Oracle Cloud Storage connector
// See: https://developer.akamai.com/api/core_features/datastream2_config/v1.html#oraclecloudstorage
OracleCloudStorageConnector struct {
ConnectorType ConnectorType `json:"connectorType"`
AccessKey string `json:"accessKey"`
Bucket string `json:"bucket"`
ConnectorName string `json:"connectorName"`
Namespace string `json:"namespace"`
Path string `json:"path"`
Region string `json:"region"`
SecretAccessKey string `json:"secretAccessKey"`
}

// ConnectorType is used to create an "enum" of possible ConnectorTypes
ConnectorType string

// AuthenticationType is used to create an "enum" of possible AuthenticationTypes of the CustomHTTPSConnector
AuthenticationType string
)

const (
// ConnectorTypeAzure const
ConnectorTypeAzure ConnectorType = "AZURE"
// ConnectorTypeS3 const
ConnectorTypeS3 ConnectorType = "S3"
// ConnectorTypeDataDog const
ConnectorTypeDataDog ConnectorType = "DATADOG"
// ConnectorTypeSplunk const
ConnectorTypeSplunk ConnectorType = "SPLUNK"
// ConnectorTypeGcs const
ConnectorTypeGcs ConnectorType = "GCS"
// ConnectorTypeHTTPS const
ConnectorTypeHTTPS ConnectorType = "HTTPS"
// ConnectorTypeSumoLogic const
ConnectorTypeSumoLogic ConnectorType = "SUMO_LOGIC"
// ConnectorTypeOracle const
ConnectorTypeOracle ConnectorType = "Oracle_Cloud_Storage"

// AuthenticationTypeNone const
AuthenticationTypeNone AuthenticationType = "NONE"
// AuthenticationTypeBasic const
AuthenticationTypeBasic AuthenticationType = "BASIC"
)

// SetConnectorType for S3Connector
func (c *S3Connector) SetConnectorType() {
c.ConnectorType = ConnectorTypeS3
}

// Validate validates S3Connector
func (c *S3Connector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeS3)),
"AccessKey": validation.Validate(c.AccessKey, validation.Required),
"Bucket": validation.Validate(c.Bucket, validation.Required),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"Path": validation.Validate(c.Path, validation.Required),
"Region": validation.Validate(c.Region, validation.Required),
"SecretAccessKey": validation.Validate(c.SecretAccessKey, validation.Required),
}.Filter()
}

// SetConnectorType for AzureConnector
func (c *AzureConnector) SetConnectorType() {
c.ConnectorType = ConnectorTypeAzure
}

// Validate validates AzureConnector
func (c *AzureConnector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeAzure)),
"AccessKey": validation.Validate(c.AccessKey, validation.Required),
"AccountName": validation.Validate(c.AccountName, validation.Required),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"ContainerName": validation.Validate(c.ContainerName, validation.Required),
"Path": validation.Validate(c.Path, validation.Required),
}.Filter()
}

// SetConnectorType for DatadogConnector
func (c *DatadogConnector) SetConnectorType() {
c.ConnectorType = ConnectorTypeDataDog
}

// Validate validates DatadogConnector
func (c *DatadogConnector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeDataDog)),
"AuthToken": validation.Validate(c.AuthToken, validation.Required),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"URL": validation.Validate(c.URL, validation.Required),
}.Filter()
}

// SetConnectorType for SplunkConnector
func (c *SplunkConnector) SetConnectorType() {
c.ConnectorType = ConnectorTypeSplunk
}

// Validate validates SplunkConnector
func (c *SplunkConnector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeSplunk)),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"EventCollectorToken": validation.Validate(c.EventCollectorToken, validation.Required),
"URL": validation.Validate(c.URL, validation.Required),
}.Filter()
}

// SetConnectorType for GCSConnector
func (c *GCSConnector) SetConnectorType() {
c.ConnectorType = ConnectorTypeGcs
}

// Validate validates GCSConnector
func (c *GCSConnector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeGcs)),
"Bucket": validation.Validate(c.Bucket, validation.Required),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"PrivateKey": validation.Validate(c.PrivateKey, validation.Required),
"ProjectID": validation.Validate(c.ProjectID, validation.Required),
"ServiceAccountName": validation.Validate(c.ServiceAccountName, validation.Required),
}.Filter()
}

// SetConnectorType for CustomHTTPSConnector
func (c *CustomHTTPSConnector) SetConnectorType() {
c.ConnectorType = ConnectorTypeHTTPS
}

// Validate validates CustomHTTPSConnector
func (c *CustomHTTPSConnector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeHTTPS)),
"AuthenticationType": validation.Validate(c.AuthenticationType, validation.Required, validation.In(AuthenticationTypeBasic, AuthenticationTypeNone)),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"URL": validation.Validate(c.URL, validation.Required),
}.Filter()
}

// SetConnectorType for SumoLogicConnector
func (c *SumoLogicConnector) SetConnectorType() {
c.ConnectorType = ConnectorTypeSumoLogic
}

// Validate validates SumoLogicConnector
func (c *SumoLogicConnector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeSumoLogic)),
"CollectorCode": validation.Validate(c.CollectorCode, validation.Required),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
}.Filter()
}

// SetConnectorType for OracleCloudStorageConnector
func (c *OracleCloudStorageConnector) SetConnectorType() {
c.ConnectorType = ConnectorTypeOracle
}

// Validate validates OracleCloudStorageConnector
func (c *OracleCloudStorageConnector) Validate() error {
return validation.Errors{
"ConnectorType": validation.Validate(c.ConnectorType, validation.Required, validation.In(ConnectorTypeOracle)),
"AccessKey": validation.Validate(c.AccessKey, validation.Required),
"Bucket": validation.Validate(c.Bucket, validation.Required),
"ConnectorName": validation.Validate(c.ConnectorName, validation.Required),
"Namespace": validation.Validate(c.Namespace, validation.Required),
"Path": validation.Validate(c.Path, validation.Required),
"Region": validation.Validate(c.Region, validation.Required),
"SecretAccessKey": validation.Validate(c.SecretAccessKey, validation.Required),
}.Filter()
}
47 changes: 47 additions & 0 deletions pkg/datastream/ds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package datastream

import (
"errors"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v2/pkg/session"
)

var (
// ErrStructValidation is returned when given struct validation failed
ErrStructValidation = errors.New("struct validation")
)

type (
// DS is the ds api interface
DS interface {
Activation
Properties
Stream
}

ds struct {
session.Session
}

// Option defines a DS option
Option func(*ds)

// ClientFunc is a ds client new method, this can be used for mocking
ClientFunc func(sess session.Session, ops ...Option) DS
)

// Client returns a new ds Client instance with the specified controller
func Client(sess session.Session, opts ...Option) DS {
c := &ds{
Session: sess,
}

for _, opt := range opts {
opt(c)
}
return c
}

// DelimiterTypePtr returns the address of the DelimiterType
func DelimiterTypePtr(d DelimiterType) *DelimiterType {
return &d
}
65 changes: 65 additions & 0 deletions pkg/datastream/ds_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package datastream

import (
"crypto/tls"
"crypto/x509"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v2/pkg/edgegrid"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v2/pkg/session"
"github.com/stretchr/testify/require"
"github.com/tj/assert"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)

func mockAPIClient(t *testing.T, mockServer *httptest.Server) DS {
serverURL, err := url.Parse(mockServer.URL)
require.NoError(t, err)
certPool := x509.NewCertPool()
certPool.AddCert(mockServer.Certificate())
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: certPool,
},
},
}

s, err := session.New(
session.WithClient(httpClient),
session.WithSigner(&edgegrid.Config{Host: serverURL.Host}),
)
assert.NoError(t, err)
return Client(s)
}

func TestClient(t *testing.T) {
sess, err := session.New()
require.NoError(t, err)
tests := map[string]struct {
options []Option
expected *ds
}{
"no options provided, return default": {
options: nil,
expected: &ds{
Session: sess,
},
},
"option provided, overwrite session": {
options: []Option{func(c *ds) {
c.Session = nil
}},
expected: &ds{
Session: nil,
},
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
res := Client(sess, test.options...)
assert.Equal(t, res, test.expected)
})
}
}
Loading

0 comments on commit 4314ddd

Please sign in to comment.