Skip to content

Commit 171f4b1

Browse files
committed
Merge branch 'master' into support-pkcs
2 parents 25cdfcf + b890cb8 commit 171f4b1

File tree

91 files changed

+3617
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3617
-95
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2025 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package cmd
20+
21+
import (
22+
"fmt"
23+
24+
"net/http"
25+
26+
"github.com/spf13/cobra"
27+
"github.com/wso2/product-apim-tooling/import-export-cli/credentials"
28+
"github.com/wso2/product-apim-tooling/import-export-cli/impl"
29+
"github.com/wso2/product-apim-tooling/import-export-cli/utils"
30+
)
31+
32+
var mcpServerStateChangeEnvironment string
33+
var mcpServerNameForStateChange string
34+
var mcpServerVersionForStateChange string
35+
var mcpServerProviderForStateChange string
36+
var mcpServerStateChangeAction string
37+
38+
// ChangeMCPServerStatus command related usage info
39+
const changeMCPServerStatusCmdLiteral = "mcp-server"
40+
const changeMCPServerStatusCmdShortDesc = "Change Status of an MCP Server"
41+
const changeMCPServerStatusCmdLongDesc = "Change the lifecycle status of an MCP Server in an environment"
42+
43+
const changeMCPServerStatusCmdExamples = utils.ProjectName + ` ` + changeStatusCmdLiteral + ` ` + changeMCPServerStatusCmdLiteral + ` -a Publish -n MyMCPServer -v 1.0.0 -r admin -e dev
44+
` + utils.ProjectName + ` ` + changeStatusCmdLiteral + ` ` + changeMCPServerStatusCmdLiteral + ` -a Publish -n MyMCPServer -v 2.1.0 -e production
45+
NOTE: The 4 flags (--action (-a), --name (-n), --version (-v), and --environment (-e)) are mandatory.`
46+
47+
// changeMCPServerStatusCmd represents change-status mcp-server command
48+
var ChangeMCPServerStatusCmd = &cobra.Command{
49+
Use: changeMCPServerStatusCmdLiteral + " (--action <action-of-the-mcpserver-state-change> --name <name-of-the-mcpserver> --version <version-of-the-mcpserver> --provider " +
50+
"<provider-of-the-mcpserver> --environment <environment-from-which-the-mcpserver-state-should-be-changed>)",
51+
Short: changeMCPServerStatusCmdShortDesc,
52+
Long: changeMCPServerStatusCmdLongDesc,
53+
Example: changeMCPServerStatusCmdExamples,
54+
Run: func(cmd *cobra.Command, args []string) {
55+
utils.Logln(utils.LogPrefixInfo + changeMCPServerStatusCmdLiteral + " called")
56+
cred, err := GetCredentials(mcpServerStateChangeEnvironment)
57+
if err != nil {
58+
utils.HandleErrorAndExit("Error getting credentials ", err)
59+
}
60+
executeChangeMCPServerStatusCmd(cred)
61+
},
62+
}
63+
64+
// executeChangeMCPServerStatusCmd executes the change mcp server status command
65+
func executeChangeMCPServerStatusCmd(credential credentials.Credential) {
66+
accessToken, preCommandErr := credentials.GetOAuthAccessToken(credential, mcpServerStateChangeEnvironment)
67+
if preCommandErr == nil {
68+
resp, err := impl.ChangeMCPServerStatusInEnv(accessToken, mcpServerStateChangeEnvironment, mcpServerStateChangeAction,
69+
mcpServerNameForStateChange, mcpServerVersionForStateChange, mcpServerProviderForStateChange)
70+
if err != nil {
71+
utils.HandleErrorAndExit("Error while changing the MCP Server status", err)
72+
}
73+
// Print info on response
74+
utils.Logf(utils.LogPrefixInfo+"ResponseStatus: %v\n", resp.Status())
75+
if resp.StatusCode() == http.StatusOK {
76+
// 200 OK
77+
fmt.Println(mcpServerNameForStateChange + " MCP Server state changed successfully!")
78+
} else if resp.StatusCode() == http.StatusInternalServerError {
79+
// 500 Internal Server Error
80+
fmt.Println(string(resp.Body()))
81+
} else {
82+
// Neither 200 nor 500
83+
fmt.Println("Error while changing MCP Server Status: ", resp.Status(), "\n", string(resp.Body()))
84+
}
85+
} else {
86+
// Error changing the MCP Server status
87+
fmt.Println("Error getting OAuth tokens while changing status of the MCP Server:" + preCommandErr.Error())
88+
}
89+
}
90+
91+
func init() {
92+
ChangeStatusCmd.AddCommand(ChangeMCPServerStatusCmd)
93+
ChangeMCPServerStatusCmd.Flags().StringVarP(&mcpServerStateChangeAction, "action", "a", "",
94+
"Action to be taken to change the status of the MCP Server")
95+
ChangeMCPServerStatusCmd.Flags().StringVarP(&mcpServerNameForStateChange, "name", "n", "",
96+
"Name of the MCP Server to be state changed")
97+
ChangeMCPServerStatusCmd.Flags().StringVarP(&mcpServerVersionForStateChange, "version", "v", "",
98+
"Version of the MCP Server to be state changed")
99+
ChangeMCPServerStatusCmd.Flags().StringVarP(&mcpServerProviderForStateChange, "provider", "r", "",
100+
"Provider of the MCP Server")
101+
ChangeMCPServerStatusCmd.Flags().StringVarP(&mcpServerStateChangeEnvironment, "environment", "e",
102+
"", "Environment of which the MCP Server state should be changed")
103+
// Mark required flags
104+
_ = ChangeMCPServerStatusCmd.MarkFlagRequired("action")
105+
_ = ChangeMCPServerStatusCmd.MarkFlagRequired("name")
106+
_ = ChangeMCPServerStatusCmd.MarkFlagRequired("version")
107+
_ = ChangeMCPServerStatusCmd.MarkFlagRequired("environment")
108+
}

import-export-cli/cmd/changeStatus.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* KIND, either express or implied. See the License for the
1515
* specific language governing permissions and limitations
1616
* under the License.
17-
*/
17+
*/
1818

1919
package cmd
2020

@@ -26,11 +26,12 @@ import (
2626

2727
// ChangeStatus command related usage info
2828
const changeStatusCmdLiteral = "change-status"
29-
const changeStatusCmdShortDesc = "Change Status of an API or API Product"
30-
const changeStatusCmdLongDesc = "Change the lifecycle status of an API or API Product in an environment"
29+
const changeStatusCmdShortDesc = "Change Status of an API, MCP Server or Product"
30+
const changeStatusCmdLongDesc = "Change the lifecycle status of an API, MCP Server or API Product in an environment"
3131

3232
const changeStatusCmdExamples = utils.ProjectName + ` ` + changeStatusCmdLiteral + ` ` + changeAPIStatusCmdLiteral + ` -a Publish -n TwitterAPI -v 1.0.0 -r admin -e dev
3333
` + utils.ProjectName + ` ` + changeStatusCmdLiteral + ` ` + changeAPIStatusCmdLiteral + ` -a Publish -n FacebookAPI -v 2.1.0 -e production
34+
` + utils.ProjectName + ` ` + changeStatusCmdLiteral + ` ` + changeMCPServerStatusCmdLiteral + ` -a Publish -n WeatherMCPServer -v 1.0.0 -r admin -e dev
3435
` + utils.ProjectName + ` ` + changeStatusCmdLiteral + ` ` + changeAPIProductStatusCmdLiteral + ` -a Publish -n SocialMediaProduct -v 1.0.0 -r admin -e dev`
3536

3637
// ChangeStatusCmd represents the change-status command

import-export-cli/cmd/delete.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import (
2727

2828
// Delete command related usage Info
2929
const deleteCmdLiteral = "delete"
30-
const deleteCmdShortDesc = "Delete an API/APIProduct/Application in an environment"
30+
const deleteCmdShortDesc = "Delete an API/MCPServer/APIProduct/Application in an environment"
3131
const deleteCmdLongDesc = `Delete an API available in the environment specified by flag (--environment, -e)
32+
Delete an MCP Server available in the environment specified by flag (--environment, -e)
3233
Delete an API Product available in the environment specified by flag (--environment, -e)
3334
Delete an Application of a specific user in the environment specified by flag (--environment, -e)`
3435

3536
const deleteCmdExamples = utils.ProjectName + ` ` + deleteCmdLiteral + ` ` + deleteAPICmdLiteral + ` -n TwitterAPI -v 1.0.0 -r admin -e dev
37+
` + utils.ProjectName + ` ` + deleteCmdLiteral + ` ` + deleteMCPServerCmdLiteral + ` -n WeatherMCPServer -v 1.0.0 -r admin -e dev
3638
` + utils.ProjectName + ` ` + deleteCmdLiteral + ` ` + deleteAPIProductCmdLiteral + ` -n TwitterAPI -v 1.0.0 -r admin -e dev
3739
` + utils.ProjectName + ` ` + deleteCmdLiteral + ` ` + deleteAppCmdLiteral + ` -n TestApplication -o admin -e dev`
3840

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2025 WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package cmd
20+
21+
import (
22+
"fmt"
23+
24+
"github.com/spf13/cobra"
25+
"github.com/wso2/product-apim-tooling/import-export-cli/credentials"
26+
"github.com/wso2/product-apim-tooling/import-export-cli/impl"
27+
k8sUtils "github.com/wso2/product-apim-tooling/import-export-cli/operator/utils"
28+
"github.com/wso2/product-apim-tooling/import-export-cli/utils"
29+
)
30+
31+
var deleteMCPServerEnvironment string
32+
var deleteMCPServerName string
33+
var deleteMCPServerVersion string
34+
var deleteMCPServerProvider string
35+
36+
// DeleteMCPServer command related usage info
37+
const deleteMCPServerCmdLiteral = "mcp-server"
38+
const deleteMCPServerCmdShortDesc = "Delete MCP Server"
39+
const deleteMCPServerCmdLongDesc = "Delete an MCP Server from an environment"
40+
41+
const deleteMCPServerCmdExamplesDefault = utils.ProjectName + ` ` + deleteCmdLiteral + ` ` + deleteMCPServerCmdLiteral + ` -n ChoreoConnect -v 1.0.0 -r admin -e dev
42+
` + utils.ProjectName + ` ` + deleteCmdLiteral + ` ` + deleteMCPServerCmdLiteral + ` -n ChoreoConnect -v 2.1.0 -e production
43+
NOTE: The 3 flags (--name (-n), --version (-v), and --environment (-e)) are mandatory.`
44+
45+
// DeleteMCPServerCmd represents the delete mcp-server command
46+
var DeleteMCPServerCmd = &cobra.Command{
47+
Use: deleteMCPServerCmdLiteral + " (--name <name-of-the-mcp-server> --version <version-of-the-mcp-server> --provider <provider-of-the-mcp-server> --environment " +
48+
"<environment-from-which-the-mcp-server-should-be-deleted>)",
49+
Short: deleteMCPServerCmdShortDesc,
50+
Long: deleteMCPServerCmdLongDesc,
51+
Example: deleteMCPServerCmdExamplesDefault,
52+
DisableFlagParsing: isK8sEnabled(),
53+
Run: func(cmd *cobra.Command, args []string) {
54+
utils.Logln(utils.LogPrefixInfo + deleteMCPServerCmdLiteral + " called")
55+
configVars := utils.GetMainConfigFromFile(utils.MainConfigFilePath)
56+
if configVars.Config.KubernetesMode {
57+
k8sArgs := []string{k8sUtils.K8sDelete, k8sUtils.ApiOpCrdApi}
58+
k8sArgs = append(k8sArgs, args...)
59+
ExecuteKubernetes(k8sArgs...)
60+
} else {
61+
cred, err := GetCredentials(deleteMCPServerEnvironment)
62+
if err != nil {
63+
utils.HandleErrorAndExit("Error getting credentials ", err)
64+
}
65+
executeDeleteMCPServerCmd(cred)
66+
}
67+
},
68+
}
69+
70+
// executeDeleteMCPServerCmd executes the delete mcp-server command
71+
func executeDeleteMCPServerCmd(credential credentials.Credential) {
72+
accessToken, preCommandErr := credentials.GetOAuthAccessToken(credential, deleteMCPServerEnvironment)
73+
if preCommandErr == nil {
74+
resp, err := impl.DeleteMCPServer(accessToken, deleteMCPServerEnvironment, deleteMCPServerName, deleteMCPServerVersion, deleteMCPServerProvider)
75+
if err != nil {
76+
utils.HandleErrorAndExit("Error while deleting MCP Server ", err)
77+
}
78+
impl.PrintDeleteMCPServerResponse(resp, err)
79+
} else {
80+
// Error deleting MCP Server
81+
fmt.Println("Error getting OAuth tokens while deleting MCP Server:" + preCommandErr.Error())
82+
}
83+
}
84+
85+
// Init using Cobra
86+
func init() {
87+
DeleteCmd.AddCommand(DeleteMCPServerCmd)
88+
DeleteMCPServerCmd.Flags().StringVarP(&deleteMCPServerName, "name", "n", "",
89+
"Name of the MCP Server to be deleted")
90+
DeleteMCPServerCmd.Flags().StringVarP(&deleteMCPServerVersion, "version", "v", "",
91+
"Version of the MCP Server to be deleted")
92+
DeleteMCPServerCmd.Flags().StringVarP(&deleteMCPServerProvider, "provider", "r", "",
93+
"Provider of the MCP Server to be deleted")
94+
DeleteMCPServerCmd.Flags().StringVarP(&deleteMCPServerEnvironment, "environment", "e",
95+
"", "Environment from which the MCP Server should be deleted")
96+
97+
// fetches the main-config.yaml file silently; i.e. if it's not created, ignore the error and assume that
98+
// this is the default mode.
99+
configVars := utils.GetMainConfigFromFileSilently(utils.MainConfigFilePath)
100+
if configVars == nil || !configVars.Config.KubernetesMode {
101+
// Mark required flags
102+
_ = DeleteMCPServerCmd.MarkFlagRequired("name")
103+
_ = DeleteMCPServerCmd.MarkFlagRequired("version")
104+
_ = DeleteMCPServerCmd.MarkFlagRequired("environment")
105+
}
106+
}

import-export-cli/cmd/export.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ import (
2525

2626
// Export command related usage Info
2727
const ExportCmdLiteral = "export"
28-
const exportCmdShortDesc = "Export an API/API Product/Application/Policy in an environment"
28+
const exportCmdShortDesc = "Export an API/MCPServer/API Product/Application/Policy in an environment"
2929

3030
const exportCmdLongDesc = `Export an API available in the environment specified by flag (--environment, -e)
3131
Export APIs available in the environment specified by flag (--environment, -e)
32+
Export an MCP Server available in the environment specified by flag (--environment, -e)
3233
Export an API Product available in the environment specified by flag (--environment, -e)
3334
Export an Application of a specific user (--owner, -o) in the environment specified by flag (--environment, -e)`
3435

3536
const exportCmdExamples = utils.ProjectName + ` ` + ExportCmdLiteral + ` ` + ExportAPICmdLiteral + ` -n TwitterAPI -v 1.0.0 -r admin -e dev
3637
` + utils.ProjectName + ` ` + ExportCmdLiteral + ` ` + ExportAPIsCmdLiteral + ` -e dev
38+
` + utils.ProjectName + ` ` + ExportCmdLiteral + ` ` + ExportMCPServerCmdLiteral + ` -n WeatherMCPServer -v 1.0.0 -e dev
3739
` + utils.ProjectName + ` ` + ExportCmdLiteral + ` ` + ExportAPIProductCmdLiteral + ` -n LeasingAPIProduct -v 1.0.0 -e dev
3840
` + utils.ProjectName + ` ` + ExportCmdLiteral + ` ` + ExportAppCmdLiteral + ` -n SampleApp -o admin -e dev`
3941

0 commit comments

Comments
 (0)