forked from TencentBlueKing/bk-bcs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: bcs-client supports bcs-user-manager api. issue TencentBlueK…
- Loading branch information
1 parent
9ae389c
commit 55aed44
Showing
17 changed files
with
773 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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 add | ||
|
||
import ( | ||
"bk-bcs/bcs-services/bcs-client/cmd/utils" | ||
v1 "bk-bcs/bcs-services/bcs-client/pkg/usermanager/v1" | ||
"bk-bcs/bcs-services/bcs-user-manager/app/user-manager/v1http" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func initVpcCidr(c *utils.ClientContext) error { | ||
if err := c.MustSpecified(utils.OptionVpc); err != nil { | ||
return err | ||
} | ||
|
||
var data []byte | ||
var err error | ||
if !c.IsSet(utils.OptionFile) { | ||
//reading all data from stdin | ||
data, err = ioutil.ReadAll(os.Stdin) | ||
} else { | ||
data, err = c.FileData() | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
if len(data) == 0 { | ||
return fmt.Errorf("failed to grant: no available resource datas") | ||
} | ||
|
||
var cidrs []v1http.TkeCidr | ||
err = json.Unmarshal(data, &cidrs) | ||
if err != nil { | ||
return err | ||
} | ||
form := v1http.AddTkeCidrForm{ | ||
Vpc: c.String(utils.OptionVpc), | ||
TkeCidrs: cidrs, | ||
} | ||
data, err = json.Marshal(form) | ||
if err != nil { | ||
return err | ||
} | ||
userManager := v1.NewBcsUserManager(utils.GetClientOption()) | ||
err = userManager.AddVpcCidrs(data) | ||
if err != nil { | ||
return fmt.Errorf("failed to init cidr to vpc %s: %v", c.String(utils.OptionVpc), err) | ||
} | ||
|
||
fmt.Printf("success to init cidr\n") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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 add | ||
|
||
import ( | ||
"bk-bcs/bcs-services/bcs-client/cmd/utils" | ||
"fmt" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
//NewAddCommand sub command add registration | ||
func NewAddCommand() cli.Command { | ||
return cli.Command{ | ||
Name: "add", | ||
Usage: "add cidr", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "type, t", | ||
Usage: "add type, value can be cidr", | ||
}, | ||
cli.StringFlag{ | ||
Name: "from-file, f", | ||
Usage: "reading with configuration `FILE`", | ||
}, | ||
cli.StringFlag{ | ||
Name: "vpcid", | ||
Usage: "vpc id", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
return add(utils.NewClientContext(c)) | ||
}, | ||
} | ||
} | ||
|
||
func add(c *utils.ClientContext) error { | ||
if err := c.MustSpecified(utils.OptionType); err != nil { | ||
return err | ||
} | ||
|
||
resourceType := c.String(utils.OptionType) | ||
|
||
switch resourceType { | ||
case "cidr": | ||
return initVpcCidr(c) | ||
default: | ||
return fmt.Errorf("invalid type: %s", resourceType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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 create | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"bk-bcs/bcs-services/bcs-client/cmd/utils" | ||
"bk-bcs/bcs-services/bcs-client/pkg/usermanager/v1" | ||
) | ||
|
||
func createUser(c *utils.ClientContext) error { | ||
if err := c.MustSpecified(utils.OptionUserName, utils.OptionUserType); err != nil { | ||
return err | ||
} | ||
|
||
userManager := v1.NewBcsUserManager(utils.GetClientOption()) | ||
user, err := userManager.CreateOrGetUser(c.String(utils.OptionUserType), c.String(utils.OptionUserName), http.MethodPost) | ||
if err != nil { | ||
return fmt.Errorf("failed to create user: %v", err) | ||
} | ||
|
||
return printResult(user) | ||
} | ||
|
||
func printResult(single interface{}) error { | ||
fmt.Printf("%s\n", utils.TryIndent(single)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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 grant | ||
|
||
import ( | ||
"bk-bcs/bcs-services/bcs-client/cmd/utils" | ||
"fmt" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
//NewGrantCommand sub command grant registration | ||
func NewGrantCommand() cli.Command { | ||
return cli.Command{ | ||
Name: "grant", | ||
Usage: "grant permission", | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "type, t", | ||
Usage: "grant type, value can be permission", | ||
}, | ||
cli.StringFlag{ | ||
Name: "from-file, f", | ||
Usage: "reading with configuration `FILE`", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
return grant(utils.NewClientContext(c)) | ||
}, | ||
} | ||
} | ||
|
||
func grant(c *utils.ClientContext) error { | ||
if err := c.MustSpecified(utils.OptionType); err != nil { | ||
return err | ||
} | ||
|
||
resourceType := c.String(utils.OptionType) | ||
|
||
switch resourceType { | ||
case "permission": | ||
return grantPermission(c) | ||
default: | ||
return fmt.Errorf("invalid type: %s", resourceType) | ||
} | ||
} |
Oops, something went wrong.