Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor arg validation
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Rangwala <[email protected]>
aayushrangwala committed Dec 19, 2023
1 parent 46de8c2 commit 60a600a
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions internal/interconnections/create.go
Original file line number Diff line number Diff line change
@@ -28,20 +28,16 @@ func (c *Client) Create() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true

if projectID == "" && organizationID == "" {
return errors.New("could you provide at least either of projectID OR organizationID")
}

if vlanFabricVcCreate(vlans) || vrfsFabricVcCreate(vrfs) && svcTokenType == "" {
return errors.New("flag 'service-token-type' is required for vlan or vrfs fabric VC create")
}

var interconn *metal.Interconnection
var err error

if err := validInputArgs(projectID, organizationID, vlans, vrfs, svcTokenType); err != nil {
return err
}

createOrganizationInterconnectionRequest := metal.CreateOrganizationInterconnectionRequest{}

switch true {
switch {
case vlanFabricVcCreate(vlans):
in := metal.NewVlanFabricVcCreateInput(
metro, name, redundancy, metal.VlanFabricVcCreateInputServiceTokenType(svcTokenType),
@@ -131,3 +127,19 @@ func (c *Client) handleCreate(projectID, organizationID string,
Execute()
return interconn, err
}

func validInputArgs(projectID, organizationID string, vlans []int32, vrfs []string, svcTokenType string) error {
if projectID == "" && organizationID == "" {
return errors.New("could you provide at least either of projectID OR organizationID")
}

if vlanFabricVcCreate(vlans) || vrfsFabricVcCreate(vrfs) && svcTokenType == "" {
return errors.New("flag 'service-token-type' is required for vlan or vrfs fabric VC create")
}

if vlanFabricVcCreate(vlans) && vrfsFabricVcCreate(vrfs) {
return errors.New("vLans and vrfs both are provided. Please provide any one type of interconnection")
}

return nil
}

0 comments on commit 60a600a

Please sign in to comment.