Skip to content

Commit

Permalink
marketplace registration code
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Jul 16, 2024
1 parent b804923 commit 0bf64a3
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
8 changes: 8 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package api

import (
//"github.com/RobotsAndPencils/go-saml"
"fmt"

jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -55,6 +57,12 @@ func (a *API) Launch() error {
}
}

marketplace := ecs.Marketplace{}
err := marketplace.RegisterMarketplace()
if err != nil {
return fmt.Errorf("register marketplace error: %s", err)
}

a.asController = AutoscalingController{}

a.createAuthMiddleware()
Expand Down
4 changes: 4 additions & 0 deletions api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,13 +1242,17 @@ func (c *Controller) Bootstrap(b *Flags) error {
}
// create env vars
if b.ParamstoreEnabled {
if b.ProdCode == "" {
b.ProdCode = "3x0v7m3npdgzaiw2f8lwsgju5" // default prod code
}
parameters := []service.DeployServiceParameter{
{Name: "PARAMSTORE_ENABLED", Value: "yes"},
{Name: "PARAMSTORE_PREFIX", Value: b.ParamstorePrefix},
{Name: "JWT_SECRET", Value: util.RandStringBytesMaskImprSrc(32)},
{Name: "DEPLOY_PASSWORD", Value: deployPassword},
{Name: "URL_PREFIX", Value: "/ecs-deploy"},
{Name: "AWS_ACCOUNT_ENV", Value: b.Environment},
{Name: "PROD_CODE", Value: b.ProdCode},
}
if b.ParamstoreKmsArn != "" {
parameters = append(parameters, service.DeployServiceParameter{Name: "PARAMSTORE_KMS_ARN", Value: b.ParamstoreKmsArn})
Expand Down
1 change: 1 addition & 0 deletions api/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Flags struct {
Server bool
DeleteCluster string
LoadBalancers []service.LoadBalancer
ProdCode string
}

func NewFlags() *Flags {
Expand Down
1 change: 1 addition & 0 deletions cmd/ecs-deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func addFlags(f *api.Flags, fs *pflag.FlagSet) {
fs.BoolVar(&f.Server, "server", f.Server, "start server")
fs.StringVar(&f.DeleteCluster, "delete-cluster", f.DeleteCluster, "delete-cluster <cluster name>")
fs.BoolVar(&f.DisableEcsDeploy, "disable-ecs-deploy", f.DisableEcsDeploy, "disable ecs deploy during bootstrap")
fs.StringVar(&f.ProdCode, "aws-prod-code", f.ProdCode, "aws marketplace product code")
fs.MarkHidden("disable-ecs-deploy")
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go/codec v0.0.0-2019020

require (
github.com/appleboy/gin-jwt/v2 v2.7.0
github.com/aws/aws-sdk-go v1.51.6
github.com/aws/aws-sdk-go v1.54.19
github.com/crewjam/saml v0.4.14
github.com/ghodss/yaml v1.0.0
github.com/gin-contrib/location v0.0.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhpl
github.com/aws/aws-sdk-go v1.18.5/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.51.6 h1:Ld36dn9r7P9IjU8WZSaswQ8Y/XUCRpewim5980DwYiU=
github.com/aws/aws-sdk-go v1.51.6/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.54.19 h1:tyWV+07jagrNiCcGRzRhdtVjQs7Vy41NwsuOcl0IbVI=
github.com/aws/aws-sdk-go v1.54.19/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
Expand Down
37 changes: 37 additions & 0 deletions provider/ecs/marketplace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ecs

import (
"fmt"
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/marketplacemetering"
)

// Marketplace struct
type Marketplace struct {
}

func (a *Marketplace) RegisterMarketplace() error {
sess, err := session.NewSession(&aws.Config{Region: aws.String(os.Getenv("AWS_REGION"))})
if err != nil {
return fmt.Errorf("couldn't initialize S3: %s", err)
}

productCode := os.Getenv("PROD_CODE")

// Create a MarketplaceMetering client from just a session.
svc := marketplacemetering.New(sess)

_, err = svc.RegisterUsage(&marketplacemetering.RegisterUsageInput{
ProductCode: aws.String(productCode),
PublicKeyVersion: aws.Int64(1),
})

if err != nil {
return fmt.Errorf("RegisterUsage error: %s", err)
}

return nil
}

0 comments on commit 0bf64a3

Please sign in to comment.