Skip to content

Commit

Permalink
feat: onboard sec profile create
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Nov 27, 2023
1 parent 05ceb19 commit 319f2c0
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
52 changes: 52 additions & 0 deletions cmd/securityprofiles/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package securityprofiles

import (
"internal/apiclient"
"internal/client/securityprofiles"

"github.com/apigee/apigeecli/cmd/utils"
"github.com/spf13/cobra"
)

// CreateCmd to get a securityprofile
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Create a new Security Profile",
Long: "Create a new Security Profile",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
content, err := utils.ReadFile(securityActionFile)
if err != nil {
return err
}
_, err = securityprofiles.Create(name, content)
return
},
}

var securityActionFile string

func init() {
CreateCmd.Flags().StringVarP(&name, "name", "n",
"", "Security Action name")
CreateCmd.Flags().StringVarP(&securityActionFile, "file", "f",
"", "Path to a file containing Security Profile content")
_ = CreateCmd.MarkFlagRequired("name")
_ = CreateCmd.MarkFlagRequired("file")
}
1 change: 1 addition & 0 deletions cmd/securityprofiles/securityprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func init() {
Cmd.AddCommand(DeleteCmd)
Cmd.AddCommand(AttachCmd)
Cmd.AddCommand(DetachCmd)
Cmd.AddCommand(CreateCmd)

_ = Cmd.MarkFlagRequired("org")
}
32 changes: 32 additions & 0 deletions internal/client/securityprofiles/securityprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package securityprofiles

import (
"encoding/json"
"net/url"
"path"
"strconv"
Expand All @@ -23,8 +24,39 @@ import (
"internal/apiclient"
)

type secprofile struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
ProfileConfig profileConfig `json:"profileConfig"`
ScoreConfigs []scoreConfig `json:"scoreConfigs,omitempty"`
}

type profileConfig struct {
Categories []category `json:"categories"`
}

type scoreConfig struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
ScorePath string `json:"scorePath,omitempty"`
}

type category struct {
Abuse interface{} `json:"abuse,omitempty"`
Mediation interface{} `json:"mediation,omitempty"`
Authorization interface{} `json:"authorization,omitempty"`
Threat interface{} `json:"threat,omitempty"`
Mtls interface{} `json:"mtls,omitempty"`
Cors interface{} `json:"cors,omitempty"`
}

// Create
func Create(name string, content []byte) (respBody []byte, err error) {
sc := secprofile{}
if err = json.Unmarshal(content, &sc); err != nil {
return nil, err
}
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "securityProfiles")
q := u.Query()
Expand Down

0 comments on commit 319f2c0

Please sign in to comment.