From 58d27fb5218e4703bd7c1a696471f69f259226cd Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 25 Nov 2024 12:36:16 +1100 Subject: [PATCH 1/9] [SD-323] Added deployment cmd. --- cmd/deployment/by-frontend.go | 91 +++++++++++++++++++++++++++++ cmd/deployment/metadata.go | 65 +++++++++++++++++++++ go.mod | 20 +++++++ go.sum | 105 ++++++++++++++++++++++++++++++++++ main.go | 13 +++++ 5 files changed, 294 insertions(+) create mode 100644 cmd/deployment/by-frontend.go create mode 100644 cmd/deployment/metadata.go diff --git a/cmd/deployment/by-frontend.go b/cmd/deployment/by-frontend.go new file mode 100644 index 0000000..34eadf6 --- /dev/null +++ b/cmd/deployment/by-frontend.go @@ -0,0 +1,91 @@ +package project_map + +import ( + "encoding/json" + "fmt" + "github.com/alexeyco/simpletable" + "github.com/urfave/cli/v2" + "github.com/uselagoon/machinery/api/schema" + + "github.com/dpc-sdp/bay-cli/internal/helpers" +) + +type ByFrontendResponse struct { + Items map[string]string `json:"items"` +} + +func ByFrontend(c *cli.Context) error { + client, err := helpers.NewLagoonClient(nil) + if err != nil { + return err + } + + output := ByFrontendResponse{ + Items: make(map[string]string, 0), + } + + all := c.Bool("all") + args := make([]string, 0) + if all { + // @todo once all frontends are on ripple 2, remove the obsolete check. + rippleProjects := make([]schema.ProjectMetadata, 0) + err = client.ProjectsByMetadata(c.Context, "type", "ripple", &rippleProjects) + if err != nil { + return err + } + for _, p := range rippleProjects { + args = append(args, p.Name) + } + + ripple2Projects := make([]schema.ProjectMetadata, 0) + err = client.ProjectsByMetadata(c.Context, "type", "ripple2", &ripple2Projects) + if err != nil { + return err + } + for _, p := range ripple2Projects { + args = append(args, p.Name) + } + } else { + args = helpers.GetAllArgs(c) + } + + for _, v := range args { + project := &schema.ProjectMetadata{} + + err := client.ProjectByNameMetadata(c.Context, v, project) + if err != nil { + return err + } + if err != nil { + return err + } + + output.Items[v] = project.Metadata["backend-project"] + } + + if c.String("output") == "json" { + a, _ := json.Marshal(output) + fmt.Fprintf(c.App.Writer, string(a)) + } else { + table := simpletable.New() + + table.Header = &simpletable.Header{ + Cells: []*simpletable.Cell{ + {Align: simpletable.AlignLeft, Text: "Frontend"}, + {Align: simpletable.AlignLeft, Text: "Backend"}, + }, + } + + for frontend, backend := range output.Items { + r := []*simpletable.Cell{ + {Text: frontend}, + {Text: backend}, + } + table.Body.Cells = append(table.Body.Cells, r) + } + table.SetStyle(simpletable.StyleCompactLite) + fmt.Fprintf(c.App.Writer, table.String()) + } + + return nil +} diff --git a/cmd/deployment/metadata.go b/cmd/deployment/metadata.go new file mode 100644 index 0000000..a60bd0d --- /dev/null +++ b/cmd/deployment/metadata.go @@ -0,0 +1,65 @@ +package project_map + +import ( + "encoding/json" + "fmt" + "strings" + + "github.com/go-git/go-git/v5" + errors "github.com/pkg/errors" + "github.com/urfave/cli/v2" +) + +type Metadata struct { + Deployment Item `json:"deployment"` +} + +type Item struct { + Sha string `json:"sha"` + AuthorName string `json:"authorName"` + When string `json:"when"` + Tag string `json:"tag"` + Msg string `json:"msg"` +} + +func DeploymentMetadata(c *cli.Context) error { + // logger := log.New(c.App.ErrWriter, "", log.LstdFlags) + + repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true}) + if err != nil { + return errors.Wrap(err, "unable to open git repository") + } + + ref, err := repo.Head() + if err != nil { + return errors.Wrap(err, "unable to get HEAD reference") + } + + msg, err := repo.CommitObject(ref.Hash()) + if err != nil { + return errors.Wrap(err, "unable to get commit object") + } + + tag, _ := repo.Tag("HEAD") + + msgFirstLn := strings.TrimLeft(strings.Split(msg.String(), "\n")[4], " ") + + item := Item{ + Sha: fmt.Sprintf("%s", ref.Hash()), + AuthorName: fmt.Sprintf("%s", msg.Author.Name), + When: fmt.Sprintf("%s", msg.Author.When), + Msg: fmt.Sprintf("%s", msgFirstLn), + Tag: fmt.Sprintf("%s", tag), + } + + md := Metadata{ + Deployment: item, + } + + json, _ := json.Marshal(md) + + // Write string to stdout + fmt.Fprintf(c.App.Writer, "%s", json) + + return nil +} diff --git a/go.mod b/go.mod index b13112e..a6adc0b 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/alexeyco/simpletable v1.0.0 github.com/aws/aws-sdk-go-v2/config v1.28.3 github.com/aws/aws-sdk-go-v2/service/kms v1.37.5 + github.com/go-git/go-git/v5 v5.12.0 github.com/pkg/errors v0.9.1 github.com/urfave/cli/v2 v2.27.5 github.com/uselagoon/machinery v0.0.31 @@ -16,6 +17,9 @@ require ( ) require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/aws/aws-sdk-go-v2 v1.32.4 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.44 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19 // indirect @@ -28,14 +32,30 @@ require ( github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.32.4 // indirect github.com/aws/smithy-go v1.22.0 // indirect + github.com/cloudflare/circl v1.3.7 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/uuid v1.6.0 // indirect github.com/guregu/null v4.0.0+incompatible // indirect github.com/hashicorp/go-version v1.7.0 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/machinebox/graphql v0.2.2 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/skeema/knownhosts v1.2.2 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.22.0 // indirect golang.org/x/sys v0.27.0 // indirect + golang.org/x/tools v0.13.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index 53d03a1..821fabd 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,10 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= +github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/alexeyco/simpletable v1.0.0 h1:ZQ+LvJ4bmoeHb+dclF64d0LX+7QAi7awsfCrptZrpHk= github.com/alexeyco/simpletable v1.0.0/go.mod h1:VJWVTtGUnW7EKbMRH8cE13SigKGx/1fO2SeeOiGeBkk= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= @@ -170,16 +177,41 @@ github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA= github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= +github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/guregu/null v4.0.0+incompatible h1:4zw0ckM7ECd6FNNddc3Fu4aty9nTlpkkzH7dPn4/4Gw= github.com/guregu/null v4.0.0+incompatible/go.mod h1:ePGpQaN9cw0tj45IR5E5ehMvsFlLlQZAkkOXZurJ3NM= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/machinebox/graphql v0.2.2 h1:dWKpJligYKhYKO5A2gvNhkJdQMNZeChZYyBbrZkBZfo= github.com/machinebox/graphql v0.2.2/go.mod h1:F+kbVMHuwrQ5tYgU9JXlnskM8nOaFxCAEolaQybkjWA= github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= @@ -187,14 +219,25 @@ github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwM github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= +github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8= github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ= github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w= @@ -203,8 +246,16 @@ github.com/uselagoon/machinery v0.0.29 h1:invFIPv1Z1xCt8/1ilbiNDuAEPrb+AUO21BnNG github.com/uselagoon/machinery v0.0.29/go.mod h1:X0qguIO9skumMhhT0ap5CKHulKgYzy3TiIn+xlwiFQc= github.com/uselagoon/machinery v0.0.31 h1:SkJ+muPBb9Q5vNI0bgXxZai6jN103iSj3e3d3DcZlc4= github.com/uselagoon/machinery v0.0.31/go.mod h1:RsHzIMOam3hiA4CKR12yANgzdTGy6tz4D19umjMzZyw= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= @@ -213,6 +264,35 @@ golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= @@ -221,9 +301,34 @@ golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 1310558..a232191 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "github.com/dpc-sdp/bay-cli/cmd/kms" cli "github.com/urfave/cli/v2" + deployment "github.com/dpc-sdp/bay-cli/cmd/deployment" project_map "github.com/dpc-sdp/bay-cli/cmd/project-map" ) @@ -92,6 +93,18 @@ func main() { }, }, }, + { + Name: "deployment", + Usage: "commands for deployment actions", + Subcommands: []*cli.Command{ + { + Name: "metadata", + Usage: "generates a file with deployment metadata", + UsageText: "bay deployment metadata", + Action: deployment.DeploymentMetadata, + }, + }, + }, }, } From 0f5894bf02e6ee85c7c6196cf2f9f4b563bf75d7 Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 25 Nov 2024 16:56:30 +1100 Subject: [PATCH 2/9] [SD-323] Fixed tag string handling. --- cmd/deployment/metadata.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd/deployment/metadata.go b/cmd/deployment/metadata.go index a60bd0d..ae8a4b0 100644 --- a/cmd/deployment/metadata.go +++ b/cmd/deployment/metadata.go @@ -34,22 +34,31 @@ func DeploymentMetadata(c *cli.Context) error { if err != nil { return errors.Wrap(err, "unable to get HEAD reference") } + fmt.Println(ref.Hash()) msg, err := repo.CommitObject(ref.Hash()) if err != nil { return errors.Wrap(err, "unable to get commit object") } - tag, _ := repo.Tag("HEAD") + tagString := "" + + tag, err := repo.Tag("HEAD") + + if err != nil { + tagString = "No tag found" + } else { + tagString = tag.Name().Short() + } msgFirstLn := strings.TrimLeft(strings.Split(msg.String(), "\n")[4], " ") item := Item{ - Sha: fmt.Sprintf("%s", ref.Hash()), - AuthorName: fmt.Sprintf("%s", msg.Author.Name), - When: fmt.Sprintf("%s", msg.Author.When), - Msg: fmt.Sprintf("%s", msgFirstLn), - Tag: fmt.Sprintf("%s", tag), + Sha: ref.Hash().String(), + AuthorName: msg.Author.Name, + When: msg.Author.When.String(), + Msg: msgFirstLn, + Tag: tagString, } md := Metadata{ From 4c3228864c75f7affd735c8cb3be75fed7e4e612 Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 25 Nov 2024 16:58:18 +1100 Subject: [PATCH 3/9] [] Removed extraneous. --- cmd/deployment/metadata.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/deployment/metadata.go b/cmd/deployment/metadata.go index ae8a4b0..5a742a1 100644 --- a/cmd/deployment/metadata.go +++ b/cmd/deployment/metadata.go @@ -23,8 +23,6 @@ type Item struct { } func DeploymentMetadata(c *cli.Context) error { - // logger := log.New(c.App.ErrWriter, "", log.LstdFlags) - repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true}) if err != nil { return errors.Wrap(err, "unable to open git repository") From cc0caf5fb4f06939bb66b70c01bec150ccaf9a48 Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 25 Nov 2024 17:02:32 +1100 Subject: [PATCH 4/9] [] Removed template. --- cmd/deployment/by-frontend.go | 91 ----------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 cmd/deployment/by-frontend.go diff --git a/cmd/deployment/by-frontend.go b/cmd/deployment/by-frontend.go deleted file mode 100644 index 34eadf6..0000000 --- a/cmd/deployment/by-frontend.go +++ /dev/null @@ -1,91 +0,0 @@ -package project_map - -import ( - "encoding/json" - "fmt" - "github.com/alexeyco/simpletable" - "github.com/urfave/cli/v2" - "github.com/uselagoon/machinery/api/schema" - - "github.com/dpc-sdp/bay-cli/internal/helpers" -) - -type ByFrontendResponse struct { - Items map[string]string `json:"items"` -} - -func ByFrontend(c *cli.Context) error { - client, err := helpers.NewLagoonClient(nil) - if err != nil { - return err - } - - output := ByFrontendResponse{ - Items: make(map[string]string, 0), - } - - all := c.Bool("all") - args := make([]string, 0) - if all { - // @todo once all frontends are on ripple 2, remove the obsolete check. - rippleProjects := make([]schema.ProjectMetadata, 0) - err = client.ProjectsByMetadata(c.Context, "type", "ripple", &rippleProjects) - if err != nil { - return err - } - for _, p := range rippleProjects { - args = append(args, p.Name) - } - - ripple2Projects := make([]schema.ProjectMetadata, 0) - err = client.ProjectsByMetadata(c.Context, "type", "ripple2", &ripple2Projects) - if err != nil { - return err - } - for _, p := range ripple2Projects { - args = append(args, p.Name) - } - } else { - args = helpers.GetAllArgs(c) - } - - for _, v := range args { - project := &schema.ProjectMetadata{} - - err := client.ProjectByNameMetadata(c.Context, v, project) - if err != nil { - return err - } - if err != nil { - return err - } - - output.Items[v] = project.Metadata["backend-project"] - } - - if c.String("output") == "json" { - a, _ := json.Marshal(output) - fmt.Fprintf(c.App.Writer, string(a)) - } else { - table := simpletable.New() - - table.Header = &simpletable.Header{ - Cells: []*simpletable.Cell{ - {Align: simpletable.AlignLeft, Text: "Frontend"}, - {Align: simpletable.AlignLeft, Text: "Backend"}, - }, - } - - for frontend, backend := range output.Items { - r := []*simpletable.Cell{ - {Text: frontend}, - {Text: backend}, - } - table.Body.Cells = append(table.Body.Cells, r) - } - table.SetStyle(simpletable.StyleCompactLite) - fmt.Fprintf(c.App.Writer, table.String()) - } - - return nil -} From 76bec54ecf3ceb4f9488788c79da2d8514b7f469 Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 25 Nov 2024 17:04:31 +1100 Subject: [PATCH 5/9] [] Removed debug output. --- cmd/deployment/metadata.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/deployment/metadata.go b/cmd/deployment/metadata.go index 5a742a1..d48973b 100644 --- a/cmd/deployment/metadata.go +++ b/cmd/deployment/metadata.go @@ -32,7 +32,6 @@ func DeploymentMetadata(c *cli.Context) error { if err != nil { return errors.Wrap(err, "unable to get HEAD reference") } - fmt.Println(ref.Hash()) msg, err := repo.CommitObject(ref.Hash()) if err != nil { From 5dbd7e4e4d2a5a73c0eb52562c4933ca9da520eb Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Tue, 26 Nov 2024 09:34:25 +1100 Subject: [PATCH 6/9] [] Updated README. --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 6af705a..036f565 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,21 @@ This will store the encrypted file at `keys/production/oauth.pem.asc`. cat oauth.pen.asc | bay kms decrypt > oauth.pem ``` +## Project mapping +### by-backend +List FE projects that a supplied Tide CMS (Lagoon metadata `backend-project`) connect to. + +### by-frontend +Get the BE project that the supplied FE projects connect to. + +## Deployment metadata +The deployment metadata command returns a json encoded string with project metadata that is not generally available to pods during the build process. + +``` +> bay deployment metadata +{"deployment":{"sha":"58d27fb5218e4703bd7c1a696471f69f259226cd","authorName":"Guy Owen","when":"2024-11-25 12:36:16 +1100 +1100","tag":"tag not found","msg":"[SD-323] Added deployment cmd."}} +``` + # Installation ## Homebrew (OSX) From 585a1c9aae80ef1e89cff9bb1a4b28374bd169d3 Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 2 Dec 2024 13:41:32 +1100 Subject: [PATCH 7/9] [SD-323] Improved help text Co-authored-by: Nick Santamaria --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index a232191..51bc275 100644 --- a/main.go +++ b/main.go @@ -99,7 +99,7 @@ func main() { Subcommands: []*cli.Command{ { Name: "metadata", - Usage: "generates a file with deployment metadata", + Usage: "generates a json object with deployment metadata", UsageText: "bay deployment metadata", Action: deployment.DeploymentMetadata, }, From 2681119eafcffbf06553a49912558e9f209ad9a6 Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 2 Dec 2024 14:58:34 +1100 Subject: [PATCH 8/9] [SD-323] Added deployment cmd to README. --- README.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/README.md b/README.md index 036f565..6af705a 100644 --- a/README.md +++ b/README.md @@ -21,21 +21,6 @@ This will store the encrypted file at `keys/production/oauth.pem.asc`. cat oauth.pen.asc | bay kms decrypt > oauth.pem ``` -## Project mapping -### by-backend -List FE projects that a supplied Tide CMS (Lagoon metadata `backend-project`) connect to. - -### by-frontend -Get the BE project that the supplied FE projects connect to. - -## Deployment metadata -The deployment metadata command returns a json encoded string with project metadata that is not generally available to pods during the build process. - -``` -> bay deployment metadata -{"deployment":{"sha":"58d27fb5218e4703bd7c1a696471f69f259226cd","authorName":"Guy Owen","when":"2024-11-25 12:36:16 +1100 +1100","tag":"tag not found","msg":"[SD-323] Added deployment cmd."}} -``` - # Installation ## Homebrew (OSX) From 5ed15efe7b7f430bf60475b726dfd2af035b79db Mon Sep 17 00:00:00 2001 From: Guy Owen Date: Mon, 2 Dec 2024 14:59:06 +1100 Subject: [PATCH 9/9] [SD-323] Updated struct name. --- cmd/deployment/metadata.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/deployment/metadata.go b/cmd/deployment/metadata.go index d48973b..a8a3b86 100644 --- a/cmd/deployment/metadata.go +++ b/cmd/deployment/metadata.go @@ -11,10 +11,10 @@ import ( ) type Metadata struct { - Deployment Item `json:"deployment"` + DeploymentMetadata Deployment `json:"deployment"` } -type Item struct { +type Deployment struct { Sha string `json:"sha"` AuthorName string `json:"authorName"` When string `json:"when"` @@ -50,7 +50,7 @@ func DeploymentMetadata(c *cli.Context) error { msgFirstLn := strings.TrimLeft(strings.Split(msg.String(), "\n")[4], " ") - item := Item{ + item := Deployment{ Sha: ref.Hash().String(), AuthorName: msg.Author.Name, When: msg.Author.When.String(), @@ -59,7 +59,7 @@ func DeploymentMetadata(c *cli.Context) error { } md := Metadata{ - Deployment: item, + DeploymentMetadata: item, } json, _ := json.Marshal(md)