Skip to content

Commit

Permalink
Merge pull request #440 from sajinieKavindya/master
Browse files Browse the repository at this point in the history
Support Activating and Deactivating File Inbound Endpoints via CLI and ICP
  • Loading branch information
sajinieKavindya authored Dec 16, 2024
2 parents b50991d + 99603ae commit 015c70f
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 6 deletions.
64 changes: 64 additions & 0 deletions cmd/cmd/activate/inboundendpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you 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 activate

import (
"fmt"

"github.com/spf13/cobra"
"github.com/wso2/product-mi-tooling/cmd/credentials"
impl "github.com/wso2/product-mi-tooling/cmd/impl"
miUtils "github.com/wso2/product-mi-tooling/cmd/utils"
)

var activateInboundEndpointCmdEnvironment string

const artifactInboundEndpoint = "inbound endpoint"
const activateInboundEndpointCmdLiteral = "inbound-endpoint [inboundendpoint-name]"

var activateInboundEndpointCmd = &cobra.Command{
Use: activateInboundEndpointCmdLiteral,
Short: generateActivateCmdShortDescForArtifact(artifactInboundEndpoint),
Long: generateActivateCmdLongDescForArtifact(artifactInboundEndpoint, "inboundendpoint-name"),
Example: generateActivateCmdExamplesForArtifact(artifactInboundEndpoint, miUtils.GetTrimmedCmdLiteral(activateInboundEndpointCmdLiteral), "TestInboundEndpoint"),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
handleActivateInboundEndpointCmdArguments(args)
},
}

func init() {
ActivateCmd.AddCommand(activateInboundEndpointCmd)
setEnvFlag(activateInboundEndpointCmd, &activateInboundEndpointCmdEnvironment, artifactInboundEndpoint)
}

func handleActivateInboundEndpointCmdArguments(args []string) {
printActivateCmdVerboseLog(miUtils.GetTrimmedCmdLiteral(activateInboundEndpointCmdLiteral))
credentials.HandleMissingCredentials(activateInboundEndpointCmdEnvironment)
executeActivateInboundEndpoint(args[0])
}

func executeActivateInboundEndpoint(inboundEndpointName string) {
resp, err := impl.ActivateInboundEndpoint(activateInboundEndpointCmdEnvironment, inboundEndpointName)
if err != nil {
printErrorForArtifact(artifactInboundEndpoint, inboundEndpointName, err)
} else {
fmt.Println(resp)
}
}
64 changes: 64 additions & 0 deletions cmd/cmd/deactivate/inboundendpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you 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 deactivate

import (
"fmt"

"github.com/spf13/cobra"
"github.com/wso2/product-mi-tooling/cmd/credentials"
"github.com/wso2/product-mi-tooling/cmd/impl"
miUtils "github.com/wso2/product-mi-tooling/cmd/utils"
)

var deactivateInboundEndpointCmdEnvironment string

const artifactInboundEndpoint = "inbound endpoint"
const deactivateInboundEndpointCmdLiteral = "inbound-endpoint [inboundendpoint-name]"

var deactivateInboundEndpointCmd = &cobra.Command{
Use: deactivateInboundEndpointCmdLiteral,
Short: generateDeactivateCmdShortDescForArtifact(artifactInboundEndpoint),
Long: generateDeactivateCmdLongDescForArtifact(artifactInboundEndpoint, "inboundendpoint-name"),
Example: generateDeactivateCmdExamplesForArtifact(artifactInboundEndpoint, miUtils.GetTrimmedCmdLiteral(deactivateInboundEndpointCmdLiteral), "TestInboundEndpoint"),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
handleDeactivateInboundEndpointCmdArguments(args)
},
}

func init() {
DeactivateCmd.AddCommand(deactivateInboundEndpointCmd)
setEnvFlag(deactivateInboundEndpointCmd, &deactivateInboundEndpointCmdEnvironment, artifactInboundEndpoint)
}

func handleDeactivateInboundEndpointCmdArguments(args []string) {
printDeactivateCmdVerboseLog(miUtils.GetTrimmedCmdLiteral(deactivateInboundEndpointCmdLiteral))
credentials.HandleMissingCredentials(deactivateInboundEndpointCmdEnvironment)
executeDeactivateInboundEndpoint(args[0])
}

func executeDeactivateInboundEndpoint(inboundEndpointName string) {
resp, err := impl.DeactivateInboundEndpoint(deactivateInboundEndpointCmdEnvironment, inboundEndpointName)
if err != nil {
printErrorForArtifact(artifactInboundEndpoint, inboundEndpointName, err)
} else {
fmt.Println(resp)
}
}
4 changes: 3 additions & 1 deletion cmd/impl/getInboundEndpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import (
)

const (
defaultInboundEndpointListTableFormat = "table {{.Name}}\t{{.Type}}"
defaultInboundEndpointListTableFormat = "table {{.Name}}\t{{.Type}}\t{{.Status}}"
defaultInboundEndpointDetailedFormat = "detail Name - {{.Name}}\n" +
"Type - {{.Type}}\n" +
"Stats - {{.Stats}}\n" +
"Tracing - {{.Tracing}}\n" +
"Status - {{.Status}}\n" +
"Parameters :\n" +
"NAME\tVALUE\n" +
"{{range .Parameters}}{{.Name}}\t{{.Value}}\n{{end}}"
Expand Down Expand Up @@ -68,6 +69,7 @@ func PrintInboundEndpointList(inboundEPList *artifactUtils.InboundEndpointList,
inboundEPListTableHeaders := map[string]string{
"Name": nameHeader,
"Type": typeHeader,
"Status": statusHeader,
}
if err := inboundEPListContext.Write(renderer, inboundEPListTableHeaders); err != nil {
fmt.Println("Error executing template:", err.Error())
Expand Down
38 changes: 38 additions & 0 deletions cmd/impl/inboundEndpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. licenses this file to you 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 impl

import (
"github.com/wso2/product-mi-tooling/cmd/utils"
)

// ActivateInboundEndpoint activates an inbound endpoint deployed in the micro integrator in a given environment
func ActivateInboundEndpoint(env, inboundEndpointName string) (interface{}, error) {
return updateInboundEndpointServiceState(env, inboundEndpointName, "active")
}

// DeactivateInboundEndpoint deactivates an inbound endpoint deployed in the micro integrator in a given environment
func DeactivateInboundEndpoint(env, inboundEndpointName string) (interface{}, error) {
return updateInboundEndpointServiceState(env, inboundEndpointName, "inactive")
}

func updateInboundEndpointServiceState(env, inboundEndpointName, state string) (interface{}, error) {
url := utils.GetMIManagementEndpointOfResource(utils.MiManagementInboundEndpointResource, env, utils.MainConfigFilePath)
return updateArtifactState(url, inboundEndpointName, state, env)
}
60 changes: 60 additions & 0 deletions cmd/shell-completions/mi_bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,35 @@ _mi_activate_endpoint()
noun_aliases=()
}

_mi_activate_inbound-endpoint()
{
last_command="mi_activate_inbound-endpoint"

command_aliases=()

commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--environment=")
two_word_flags+=("--environment")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--environment=")
flags+=("--insecure")
flags+=("-k")
flags+=("--verbose")

must_have_one_flag=()
must_have_one_flag+=("--environment=")
must_have_one_flag+=("-e")
must_have_one_noun=()
noun_aliases=()
}

_mi_activate_message-processor()
{
last_command="mi_activate_message-processor"
Expand Down Expand Up @@ -1536,6 +1565,7 @@ _mi_activate()

commands=()
commands+=("endpoint")
commands+=("inbound-endpoint")
commands+=("message-processor")
commands+=("proxy-service")

Expand Down Expand Up @@ -1583,6 +1613,35 @@ _mi_deactivate_endpoint()
noun_aliases=()
}

_mi_deactivate_inbound-endpoint()
{
last_command="mi_deactivate_inbound-endpoint"

command_aliases=()

commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--environment=")
two_word_flags+=("--environment")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--environment=")
flags+=("--insecure")
flags+=("-k")
flags+=("--verbose")

must_have_one_flag=()
must_have_one_flag+=("--environment=")
must_have_one_flag+=("-e")
must_have_one_noun=()
noun_aliases=()
}

_mi_deactivate_message-processor()
{
last_command="mi_deactivate_message-processor"
Expand Down Expand Up @@ -1649,6 +1708,7 @@ _mi_deactivate()

commands=()
commands+=("endpoint")
commands+=("inbound-endpoint")
commands+=("message-processor")
commands+=("proxy-service")

Expand Down
60 changes: 60 additions & 0 deletions cmd/shell-completions/mi_bash_completion.sh-e
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,35 @@ _mi_activate_endpoint()
noun_aliases=()
}

_mi_activate_inbound-endpoint()
{
last_command="mi_activate_inbound-endpoint"

command_aliases=()

commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--environment=")
two_word_flags+=("--environment")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--environment=")
flags+=("--insecure")
flags+=("-k")
flags+=("--verbose")

must_have_one_flag=()
must_have_one_flag+=("--environment=")
must_have_one_flag+=("-e")
must_have_one_noun=()
noun_aliases=()
}

_mi_activate_message-processor()
{
last_command="mi_activate_message-processor"
Expand Down Expand Up @@ -1536,6 +1565,7 @@ _mi_activate()

commands=()
commands+=("endpoint")
commands+=("inbound-endpoint")
commands+=("message-processor")
commands+=("proxy-service")

Expand Down Expand Up @@ -1583,6 +1613,35 @@ _mi_deactivate_endpoint()
noun_aliases=()
}

_mi_deactivate_inbound-endpoint()
{
last_command="mi_deactivate_inbound-endpoint"

command_aliases=()

commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--environment=")
two_word_flags+=("--environment")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--environment=")
flags+=("--insecure")
flags+=("-k")
flags+=("--verbose")

must_have_one_flag=()
must_have_one_flag+=("--environment=")
must_have_one_flag+=("-e")
must_have_one_noun=()
noun_aliases=()
}

_mi_deactivate_message-processor()
{
last_command="mi_deactivate_message-processor"
Expand Down Expand Up @@ -1649,6 +1708,7 @@ _mi_deactivate()

commands=()
commands+=("endpoint")
commands+=("inbound-endpoint")
commands+=("message-processor")
commands+=("proxy-service")

Expand Down
2 changes: 2 additions & 0 deletions cmd/utils/artifactUtils/inboundEndpointUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type InboundEndpointList struct {
type InboundEndpointSummary struct {
Name string `json:"name"`
Type string `json:"protocol"`
Status string `json:"status"`
}

type InboundEndpoint struct {
Expand All @@ -16,6 +17,7 @@ type InboundEndpoint struct {
Stats string `json:"stats"`
Tracing string `json:"tracing"`
Parameters []Parameter `json:"parameters"`
Status string `json:"status"`
}

type Parameter struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private boolean updateInboundEndpoint(String groupId, ArtifactUpdateRequest requ
String trace = request.isValue() ? "enable" : "disable";
payload.addProperty("trace", trace);
}
if (request.getType().equals("status")) {
String status = request.isValue() ? "active" : "inactive";
payload.addProperty("status", status);
}

return DelegatesUtil.updateArtifact(Constants.INBOUND_ENDPOINTS, groupId, request, payload);
}
Expand Down
Loading

0 comments on commit 015c70f

Please sign in to comment.