Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: v1.0.0 #71

Merged
merged 220 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
220 commits
Select commit Hold shift + click to select a range
b599d3c
chore: update root description
yjinjo Nov 4, 2024
2538da1
Merge pull request #3 from yjinjo/v0
yjinjo Nov 4, 2024
8028701
chore: update yaml directory
yjinjo Nov 4, 2024
343f064
Merge pull request #4 from yjinjo/v0
yjinjo Nov 4, 2024
32aea81
feat: comple api-resources using go routine
yjinjo Nov 4, 2024
dbf7d24
Merge pull request #5 from yjinjo/v0
yjinjo Nov 4, 2024
47a862a
feat: add login subcommand using user_id, password, and domain_id
yjinjo Nov 4, 2024
40cbb8a
Merge pull request #6 from yjinjo/v0
yjinjo Nov 4, 2024
054fca1
feat: update api-resources subcommand using pterm and show verbs by d…
yjinjo Nov 6, 2024
964f4b9
Merge pull request #7 from yjinjo/v0
yjinjo Nov 6, 2024
68ac3c7
feat: update cfctl using Evans CLI
yjinjo Nov 6, 2024
7758ac9
Merge pull request #8 from yjinjo/v0
yjinjo Nov 6, 2024
b289e6f
feat: display multiple Services using ,
yjinjo Nov 6, 2024
2053a66
chore: convery comment to Eng.
yjinjo Nov 6, 2024
f0f89b2
Merge pull request #9 from yjinjo/v0
yjinjo Nov 6, 2024
a8cec2f
feat: rollback root
yjinjo Nov 6, 2024
8fa7fe5
feat: add config subcommand's switch flag
yjinjo Nov 6, 2024
82c0a6d
Merge pull request #10 from yjinjo/v0
yjinjo Nov 6, 2024
43ae299
feat: add [config] init, environment, show, and fzf feature
yjinjo Nov 6, 2024
05a1caa
Merge pull request #11 from yjinjo/v0
yjinjo Nov 6, 2024
c1f3c41
feat: complete [config] init and config changing
yjinjo Nov 6, 2024
549388a
Merge pull request #12 from yjinjo/v0
yjinjo Nov 6, 2024
b9ae23e
feat: add short_names.yml when init and sync api resources
yjinjo Nov 6, 2024
b740ece
Merge pull request #13 from yjinjo/v0
yjinjo Nov 6, 2024
371c2ba
feat: add resize table function
yjinjo Nov 7, 2024
7f82c98
feat: complete login subcommand for LOCAL login
yjinjo Nov 7, 2024
3920b0f
Merge pull request #14 from yjinjo/v0
yjinjo Nov 7, 2024
6dbf48c
feat: implement token expiration check to reuse valid tokens during l…
yjinjo Nov 8, 2024
1339c69
Merge pull request #15 from yjinjo/v0
yjinjo Nov 8, 2024
1eef2ab
feat: add domain role type
yjinjo Nov 8, 2024
ce3e462
Merge pull request #16 from yjinjo/v0
yjinjo Nov 8, 2024
e3b65ee
feat: remove default config file
yjinjo Nov 11, 2024
e301de0
feat: remove default config file by root command
yjinjo Nov 11, 2024
068e518
chore: remove finding default config file
yjinjo Nov 11, 2024
bf255a8
feat: update api-resources to get endpoints by current environment
yjinjo Nov 11, 2024
f4e0590
feat: add exec subcommand except decode
yjinjo Nov 11, 2024
02cd476
Merge pull request #17 from yjinjo/v0
yjinjo Nov 11, 2024
902401e
feat:add exec subcommand - get service
yjinjo Nov 11, 2024
992860a
feat:add exec subcommand - get binary from protobuf
yjinjo Nov 11, 2024
2a47898
Merge pull request #18 from yjinjo/v0
yjinjo Nov 11, 2024
653cfb7
feat: add exec subcommand - paramter
yjinjo Nov 11, 2024
ad21708
Merge pull request #19 from yjinjo/v0
yjinjo Nov 11, 2024
05fa5e9
feat: add exec subcommand using grpc reflection
yjinjo Nov 12, 2024
38c0d95
feat: add exec subcommand - print as yaml
yjinjo Nov 12, 2024
41e8e47
feat: add exec subcommand - add json option
yjinjo Nov 12, 2024
9e2b242
feat: add exec subcommand - add json, csv, table option
yjinjo Nov 12, 2024
f8ccfe0
feat: add copy flag, which is copy any output format
yjinjo Nov 12, 2024
32a83f4
feat: get package name by user input, not hard coding
yjinjo Nov 12, 2024
2aca0c3
Merge pull request #20 from yjinjo/v0
yjinjo Nov 12, 2024
697f64d
feat: add cfctl release github workflow
yjinjo Nov 12, 2024
f4ada65
Merge pull request #21 from yjinjo/v0
yjinjo Nov 12, 2024
4164da4
feat: add ai feature to cfctl
yjinjo Nov 12, 2024
79ba913
Merge pull request #22 from yjinjo/v0
yjinjo Nov 12, 2024
ccaf9d3
feat: add ai feature to cfctl - not completed
yjinjo Nov 12, 2024
5e6eb76
Merge pull request #23 from yjinjo/v0
yjinjo Nov 12, 2024
8be0a94
feat: modify code such that not finding info from cfctl.yaml
yjinjo Nov 13, 2024
2f57781
Merge pull request #24 from yjinjo/v0
yjinjo Nov 13, 2024
c6afd3e
chore: add token timeout for a day
yjinjo Nov 13, 2024
d175eb9
chore: add token overwrite function
yjinjo Nov 13, 2024
db4e795
feat: add init subcommand
yjinjo Nov 13, 2024
b7c9527
chore: update docs
yjinjo Nov 13, 2024
d86c072
fix: modify default config file
yjinjo Nov 13, 2024
825abed
feat: add config by environments (local, dev, stg, prd)
yjinjo Nov 13, 2024
80e2187
Merge pull request #25 from yjinjo/v0
yjinjo Nov 13, 2024
73bc6e1
feat: add sync subcommand, which sync config.yaml and environments
yjinjo Nov 14, 2024
1967c15
feat: read all .yaml and .yml
yjinjo Nov 14, 2024
3778981
feat: update config when user set up
yjinjo Nov 14, 2024
10c0428
feat: modify login code, which is getting from config.yaml
yjinjo Nov 14, 2024
6f5a7d5
feat: modify login process
yjinjo Nov 14, 2024
a5a83b2
Merge pull request #26 from yjinjo/v0
yjinjo Nov 14, 2024
6c2b88a
fix: modify config init command to create only config.yaml
yjinjo Nov 18, 2024
bed4542
Merge pull request #27 from yjinjo/v0
yjinjo Nov 18, 2024
820df4f
fix: modify code such that allow only yaml, not yml
yjinjo Nov 18, 2024
57d9cba
feat: add proxy and static, dynamic mode
yjinjo Nov 18, 2024
831d5d9
Merge pull request #28 from yjinjo/v0
yjinjo Nov 18, 2024
4d47635
fix: get info from config.yaml, not environments' yaml files
yjinjo Nov 18, 2024
6cf7d71
Merge pull request #29 from yjinjo/v0
yjinjo Nov 18, 2024
66db469
feat: connect to grpc, not REST
yjinjo Nov 18, 2024
0be4573
Merge pull request #30 from yjinjo/v0
yjinjo Nov 18, 2024
1cd011d
refactor: get each microservices' service and endpoint
yjinjo Nov 18, 2024
31ce8c9
Merge pull request #31 from yjinjo/v0
yjinjo Nov 18, 2024
2d191bb
refactor: modify the exec command to get every rpc of packages
yjinjo Nov 18, 2024
5456933
Merge pull request #32 from yjinjo/v0
yjinjo Nov 18, 2024
92ca9ac
refactor: change directory from ~/.spaceone to ~/.cfctl
yjinjo Nov 18, 2024
855fa25
Merge pull request #33 from yjinjo/v0
yjinjo Nov 18, 2024
ed3c50e
refactor: change available commands to other commands
yjinjo Nov 18, 2024
76852da
Merge pull request #34 from yjinjo/v0
yjinjo Nov 18, 2024
bed52df
refactor: make other directory and specify commmands to Other Commands
yjinjo Nov 18, 2024
de6e993
Merge pull request #35 from yjinjo/v0
yjinjo Nov 18, 2024
aaf28b5
feat: add identity command
yjinjo Nov 18, 2024
efe87de
Merge pull request #36 from yjinjo/v0
yjinjo Nov 18, 2024
a8cb9de
feat: implement identity command, except UTF Encoding
yjinjo Nov 18, 2024
0292c59
Merge pull request #37 from yjinjo/v0
yjinjo Nov 18, 2024
78439a5
refactor: modify config code for ~/.cfctl/config.yaml
yjinjo Nov 19, 2024
c099b8d
Merge pull request #38 from yjinjo/v0
yjinjo Nov 19, 2024
4914ba1
refactor: add JSON Marshaling feature
yjinjo Nov 19, 2024
03eb0ee
feat: add api-resources subcommand of identity command
yjinjo Nov 19, 2024
ea71bb5
refactor: add all verb to subcommand of microservice
yjinjo Nov 19, 2024
b382667
refactor: modify code for identity command
yjinjo Nov 19, 2024
eb038be
Merge pull request #39 from yjinjo/v0
yjinjo Nov 19, 2024
3b37686
refactor: call FetchService directly
yjinjo Nov 21, 2024
46c767c
refactor: add resources of verb
yjinjo Nov 21, 2024
d942df1
refactor: add verb of microservice
yjinjo Nov 21, 2024
91bd2d4
refactor: add verb and resource subcommand of microservice
yjinjo Nov 21, 2024
4d1ab29
Merge pull request #40 from yjinjo/v0
yjinjo Nov 21, 2024
d010663
chore: remove blank line of verbs
yjinjo Nov 21, 2024
e562ae9
refactor: modify api-resources and implement common function
yjinjo Nov 21, 2024
9285839
chore: change from optional command to required command
yjinjo Nov 21, 2024
f57c00d
Merge pull request #41 from yjinjo/v0
yjinjo Nov 21, 2024
8d9197e
feat: add watch option
yjinjo Nov 21, 2024
1f39fec
Merge pull request #42 from yjinjo/v0
yjinjo Nov 21, 2024
5aa88b9
refactor: remove ai, exec command and add doc of root command
yjinjo Nov 21, 2024
8663e81
Merge pull request #43 from yjinjo/v0
yjinjo Nov 21, 2024
2a08f6a
feat: add app, user subcommand of config
yjinjo Nov 22, 2024
9f1fb44
Merge pull request #44 from yjinjo/v0
yjinjo Nov 22, 2024
e2014c5
feat: add url and local subcommand of config init
yjinjo Nov 22, 2024
7138f6a
chore: set globalConfig up
yjinjo Nov 22, 2024
a349ee9
refactor: add user's cache config and integrate environment to config…
yjinjo Nov 22, 2024
dd7c5fa
Merge pull request #45 from yjinjo/v0
yjinjo Nov 22, 2024
b78a918
refactor: add user config and modify show command
yjinjo Nov 25, 2024
0569d0d
Merge pull request #46 from yjinjo/v0
yjinjo Nov 25, 2024
1b4d481
refactor add user config and implement grpc reflection
yjinjo Nov 25, 2024
d3ba88e
Merge pull request #47 from yjinjo/v0
yjinjo Nov 25, 2024
d7bc46b
refactor: modify api-resources command for user config
yjinjo Nov 25, 2024
0fff4e1
Merge pull request #48 from yjinjo/v0
yjinjo Nov 25, 2024
5f12756
refactor: update endpoint when app/user mode
yjinjo Nov 25, 2024
2923a75
refactor: modify code when change the type
yjinjo Nov 25, 2024
0b9ae78
chore: get endpoints using grpc reflection
yjinjo Nov 25, 2024
dee2597
chore: modify api-resources command when not proxy
yjinjo Nov 25, 2024
53bdefd
refactor: load config when user type
yjinjo Nov 25, 2024
c2d8838
refactor: implement pagination of table
yjinjo Nov 25, 2024
40843f4
feat: implement watch mode for list
yjinjo Nov 25, 2024
d412990
refactor: implement table and csv for get verb
yjinjo Nov 25, 2024
9b9a02f
Merge pull request #49 from yjinjo/v0
yjinjo Nov 25, 2024
db3bff7
chore: add proxy to identity service
yjinjo Nov 26, 2024
9916116
chore: remove comments
yjinjo Nov 26, 2024
b80bb2e
refactor: add user config login
yjinjo Nov 26, 2024
f3b5a3c
feat: implement user login
yjinjo Nov 26, 2024
245dd5e
chore: format yaml
yjinjo Nov 26, 2024
e50357a
feat: implement app login
yjinjo Nov 26, 2024
ff83ee4
refactor: modify app login feature
yjinjo Nov 26, 2024
471ae3c
refactor: modify app, user config
yjinjo Nov 26, 2024
cf703c4
refactor: modify user token and encrypt password
yjinjo Nov 26, 2024
a00a6eb
Merge pull request #50 from yjinjo/v0
yjinjo Nov 26, 2024
06d85fd
refactor: modify login code in case of no token
yjinjo Nov 26, 2024
276e18b
Merge pull request #51 from yjinjo/v0
yjinjo Nov 26, 2024
f5f1bcb
feat: implement login pagination feature
yjinjo Nov 26, 2024
f381cda
Merge pull request #52 from yjinjo/v0
yjinjo Nov 26, 2024
7aed298
feat: add local config
yjinjo Nov 27, 2024
fdb08bf
Merge pull request #53 from yjinjo/v0
yjinjo Nov 27, 2024
3436669
refactor: implement login options
yjinjo Nov 27, 2024
9c7fb16
feat: add login feature
yjinjo Nov 27, 2024
f52c42b
Merge pull request #54 from yjinjo/v0
yjinjo Nov 27, 2024
87f8800
refactor: provide domain and workspace scope
yjinjo Nov 27, 2024
e566e3f
Merge pull request #55 from yjinjo/v0
yjinjo Nov 27, 2024
71f4ace
chore: add workspace owner role type
yjinjo Nov 27, 2024
cc1fd86
feat: add multiple user login feature
yjinjo Nov 27, 2024
552d08f
feat: add multi-user login feature of one domain
yjinjo Nov 27, 2024
eb1e6a6
feat: add multi-app login feature
yjinjo Nov 27, 2024
82cf472
refactor: add multi-app login
yjinjo Nov 27, 2024
53d78ed
refactor: implement user login and add token
yjinjo Nov 27, 2024
10c44b0
Merge pull request #56 from yjinjo/v0
yjinjo Nov 27, 2024
41323c3
refactor: get microservices dynamically
yjinjo Nov 28, 2024
6c3dcbf
Merge pull request #57 from yjinjo/v0
yjinjo Nov 28, 2024
97e9a64
refactor: change config command to settings
yjinjo Nov 28, 2024
fff1ffb
Merge pull request #58 from yjinjo/v0
yjinjo Nov 28, 2024
696d023
minor: add notififcation when user didn't set up config
yjinjo Nov 29, 2024
bc710c9
Merge pull request #59 from yjinjo/v0
yjinjo Nov 29, 2024
584325e
minor: modify error statement
yjinjo Nov 29, 2024
df0e7fe
Merge pull request #60 from yjinjo/v0
yjinjo Nov 29, 2024
3e61002
minor: turn off pterm when typing
yjinjo Nov 29, 2024
1c0bb29
Merge pull request #61 from yjinjo/v0
yjinjo Nov 29, 2024
0262547
chore: add settings cmd
yjinjo Nov 29, 2024
633a289
Merge pull request #62 from yjinjo/v0
yjinjo Nov 29, 2024
cea6b3f
chore: add settings cmd
yjinjo Nov 29, 2024
26701e9
Merge pull request #63 from yjinjo/v0
yjinjo Nov 29, 2024
e52b63d
feat: add cache
yjinjo Nov 29, 2024
74000eb
Merge branch 'v0' of https://github.com/cloudforet-io/cfctl into v0
yjinjo Nov 29, 2024
446f65a
chore: remove cfctl executable file
yjinjo Nov 29, 2024
9d9b1f0
Merge pull request #64 from yjinjo/v0
yjinjo Nov 29, 2024
831aa8a
chore: rename config to setting
yjinjo Dec 3, 2024
b13f8ce
Merge branch 'v0' of https://github.com/cloudforet-io/cfctl into v0
yjinjo Dec 3, 2024
22ba541
Merge pull request #65 from yjinjo/v0
yjinjo Dec 3, 2024
1fefbde
refactor: remove cache config.yaml
yjinjo Dec 3, 2024
8f5d6cd
feat: add endpoints to the specific environment of cache directory
yjinjo Dec 3, 2024
526af0d
chore: remove setting.toml of cache directory
yjinjo Dec 3, 2024
5ffd20c
refactor: update api-resources for toml
yjinjo Dec 3, 2024
d39b6cd
refactor: change from config.yaml to setting.toml when login
yjinjo Dec 3, 2024
1771d21
chore: set grant token timeout from a day to 6 hours
yjinjo Dec 3, 2024
b25cc40
chore: remove print
yjinjo Dec 3, 2024
8714938
refactor: save tokens to files
yjinjo Dec 3, 2024
7f31a41
refactor: check expiration date
yjinjo Dec 3, 2024
c83d841
refactor: remove token field when initialize a user
yjinjo Dec 3, 2024
b8d6c08
refactor: add user_id to setting.toml when user log in
yjinjo Dec 3, 2024
2a54a41
refactor: remove multi user log in and use user_id of toml
yjinjo Dec 3, 2024
cba03dd
Merge pull request #66 from yjinjo/v0
yjinjo Dec 3, 2024
78dbaf1
refactor: ask user id when user first log in
yjinjo Dec 5, 2024
04f99e4
refactor: show user id when user login
yjinjo Dec 5, 2024
32baacb
refactor: create cache directory only when a user successfully logged in
yjinjo Dec 5, 2024
cffd5c9
refactor: do not call issue_token api when grant_token is not expired…
yjinjo Dec 5, 2024
e280389
Merge pull request #67 from yjinjo/v0
yjinjo Dec 5, 2024
22f1859
refactor: show available commands only when a user successfully logge…
yjinjo Dec 5, 2024
beea846
refactor: change config path from config.yaml to setting.toml
yjinjo Dec 5, 2024
4850cb6
feat: add search feature
yjinjo Dec 5, 2024
c8c41fe
refactor: speed up when getting services dynamically
yjinjo Dec 5, 2024
687e044
feat: add short names feature
yjinjo Dec 5, 2024
a1e109d
refactor: add short_names dynamically for matching specific verb
yjinjo Dec 5, 2024
d4b46af
feat: complete short_name command
yjinjo Dec 5, 2024
f9157c7
feat: add api_resources subcommand for all microservices
yjinjo Dec 5, 2024
c5efcd0
feat: add interactive mode
yjinjo Dec 5, 2024
c65520c
feat: complete interactive mode
yjinjo Dec 5, 2024
9a399a6
feat: add sort feature
yjinjo Dec 5, 2024
ac2312a
feat: view all fields of list
yjinjo Dec 5, 2024
bd1d930
feat: add minimal flags
yjinjo Dec 5, 2024
53ece85
fix: modify both _ and - cases
yjinjo Dec 5, 2024
774bcb9
Merge pull request #68 from yjinjo/v0
yjinjo Dec 5, 2024
b280edf
fix: remove analyze cmd
yjinjo Dec 5, 2024
1632c81
Merge pull request #69 from yjinjo/v0
yjinjo Dec 5, 2024
3ba20e8
feat: add column and limit feature
yjinjo Dec 5, 2024
eebc98c
Merge pull request #70 from yjinjo/v0
yjinjo Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .github/workflows/dispatch_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
version:
description: 'enter version(x.y.z)'
required: true
default: '2.0.0'
default: '0.0.0'
container_arch:
type: choice
description: 'choose container architecture'
Expand All @@ -15,7 +15,6 @@ on:
- "linux/amd64"
- "linux/amd64,linux/arm64"


env:
ARCH: ${{ github.event.inputs.container_arch }}
VERSION: ${{ github.event.inputs.version }}
Expand Down Expand Up @@ -46,37 +45,38 @@ jobs:
fields: repo,workflow,job
author_name: Github Action Slack

pypi:
needs: tagging
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT_TOKEN }}
- uses: actions/checkout@v3

- name: Set python
uses: actions/setup-python@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
go-version: '1.23.1'

- name: Make all and Packaging
- name: Build for all platforms
run: |
cd src
python setup.py sdist bdist_wheel

- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# macOS (Intel, Apple Silicon)
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o dist/cfctl-darwin-amd64
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o dist/cfctl-darwin-arm64

# Linux (64bit, ARM)
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o dist/cfctl-linux-amd64
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o dist/cfctl-linux-arm64

# Windows (64bit)
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o dist/cfctl-windows-amd64.exe

- name: Create Release
uses: softprops/action-gh-release@v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
packages-dir: src/dist/
files: |
dist/cfctl-darwin-amd64
dist/cfctl-darwin-arm64
dist/cfctl-linux-amd64
dist/cfctl-linux-arm64
dist/cfctl-windows-amd64.exe

- name: Notice when job fails
if: failure()
Expand Down
256 changes: 256 additions & 0 deletions cmd/common/apiResources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
// common/apiResources.go

package common

import (
"context"
"crypto/tls"
"fmt"
"log"
"os"
"path/filepath"
"sort"
"strings"

"github.com/jhump/protoreflect/grpcreflect"
"github.com/pterm/pterm"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"gopkg.in/yaml.v3"
)

func loadShortNames() (map[string]string, error) {
home, err := os.UserHomeDir()
if err != nil {
return nil, fmt.Errorf("unable to find home directory: %v", err)
}
shortNamesFile := filepath.Join(home, ".cfctl", "short_names.yaml")
shortNamesMap := make(map[string]string)
if _, err := os.Stat(shortNamesFile); err == nil {
file, err := os.Open(shortNamesFile)
if err != nil {
return nil, fmt.Errorf("failed to open short_names.yaml file: %v", err)
}
defer file.Close()

err = yaml.NewDecoder(file).Decode(&shortNamesMap)
if err != nil {
return nil, fmt.Errorf("failed to decode short_names.yaml: %v", err)
}
}
return shortNamesMap, nil
}

func ListAPIResources(serviceName string) error {
config, err := loadConfig()
if err != nil {
return fmt.Errorf("failed to load config: %v", err)
}

endpoint, err := getServiceEndpoint(config, serviceName)
if err != nil {
return fmt.Errorf("failed to get endpoint for service %s: %v", serviceName, err)
}

shortNamesMap, err := loadShortNames()
if err != nil {
return fmt.Errorf("failed to load short names: %v", err)
}

data, err := fetchServiceResources(serviceName, endpoint, shortNamesMap, config)
if err != nil {
return fmt.Errorf("failed to fetch resources for service %s: %v", serviceName, err)
}

sort.Slice(data, func(i, j int) bool {
return data[i][0] < data[j][0]
})

renderAPITable(data)

return nil
}

func getServiceEndpoint(config *Config, serviceName string) (string, error) {
var envPrefix string
if strings.HasPrefix(config.Environment, "dev-") {
envPrefix = "dev"
} else if strings.HasPrefix(config.Environment, "stg-") {
envPrefix = "stg"
} else {
return "", fmt.Errorf("unsupported environment prefix")
}
endpoint := fmt.Sprintf("grpc+ssl://%s.api.%s.spaceone.dev:443", serviceName, envPrefix)
return endpoint, nil
}

func fetchServiceResources(serviceName, endpoint string, shortNamesMap map[string]string, config *Config) ([][]string, error) {
parts := strings.Split(endpoint, "://")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid endpoint format: %s", endpoint)
}
scheme := parts[0]
hostPort := parts[1]

var opts []grpc.DialOption
if scheme == "grpc+ssl" {
tlsConfig := &tls.Config{
InsecureSkipVerify: false,
}
creds := credentials.NewTLS(tlsConfig)
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
return nil, fmt.Errorf("unsupported scheme: %s", scheme)
}

conn, err := grpc.Dial(hostPort, opts...)
if err != nil {
return nil, fmt.Errorf("connection failed: unable to connect to %s: %v", endpoint, err)
}
defer conn.Close()

ctx := metadata.AppendToOutgoingContext(context.Background(), "token", config.Environments[config.Environment].Token)

refClient := grpcreflect.NewClient(ctx, grpc_reflection_v1alpha.NewServerReflectionClient(conn))
defer refClient.Reset()

services, err := refClient.ListServices()
if err != nil {
return nil, fmt.Errorf("failed to list services: %v", err)
}

// Load short names from setting.toml
home, err := os.UserHomeDir()
if err != nil {
return nil, fmt.Errorf("failed to get home directory: %v", err)
}

settingPath := filepath.Join(home, ".cfctl", "setting.toml")
v := viper.New()
v.SetConfigFile(settingPath)
v.SetConfigType("toml")

serviceShortNames := make(map[string]string)
if err := v.ReadInConfig(); err == nil {
// Get short names for this service
shortNamesSection := v.GetStringMap(fmt.Sprintf("short_names.%s", serviceName))
for shortName, cmd := range shortNamesSection {
if cmdStr, ok := cmd.(string); ok {
serviceShortNames[shortName] = cmdStr
}
}
}

data := [][]string{}
resourceData := make(map[string][][]string)

for _, s := range services {
if strings.HasPrefix(s, "grpc.reflection.") {
continue
}
if !strings.Contains(s, fmt.Sprintf(".%s.", serviceName)) {
continue
}

serviceDesc, err := refClient.ResolveService(s)
if err != nil {
log.Printf("Failed to resolve service %s: %v", s, err)
continue
}

resourceName := s[strings.LastIndex(s, ".")+1:]
verbs := []string{}
for _, method := range serviceDesc.GetMethods() {
verbs = append(verbs, method.GetName())
}

// Create a map to track which verbs have been used in short names
usedVerbs := make(map[string]bool)
resourceRows := [][]string{}

// First, check for verbs with short names
for shortName, cmdStr := range serviceShortNames {
parts := strings.Fields(cmdStr)
if len(parts) == 2 && parts[1] == resourceName {
verb := parts[0]
usedVerbs[verb] = true
// Add a row for the verb with short name
resourceRows = append(resourceRows, []string{serviceName, verb, resourceName, shortName})
}
}

// Then add remaining verbs
remainingVerbs := []string{}
for _, verb := range verbs {
if !usedVerbs[verb] {
remainingVerbs = append(remainingVerbs, verb)
}
}

if len(remainingVerbs) > 0 {
resourceRows = append([][]string{{serviceName, strings.Join(remainingVerbs, ", "), resourceName, ""}}, resourceRows...)
}

resourceData[resourceName] = resourceRows
}

// Sort resources alphabetically
var resources []string
for resource := range resourceData {
resources = append(resources, resource)
}
sort.Strings(resources)

// Build final data array
for _, resource := range resources {
data = append(data, resourceData[resource]...)
}

return data, nil
}

func renderAPITable(data [][]string) {
// Create table header
table := pterm.TableData{
{"Service", "Verb", "Resource", "Short Names"},
}

// Add data rows
table = append(table, data...)

// Render the table
pterm.DefaultTable.WithHasHeader().WithData(table).Render()
}

// wordWrap function remains the same
func wordWrap(text string, width int) string {
var wrappedText string
var line string
words := strings.Fields(text) // Split on spaces only

for _, word := range words {
if len(line)+len(word)+1 > width {
if wrappedText != "" {
wrappedText += "\n"
}
wrappedText += line
line = word
} else {
if line != "" {
line += " "
}
line += word
}
}
if line != "" {
if wrappedText != "" {
wrappedText += "\n"
}
wrappedText += line
}

return wrappedText
}
20 changes: 20 additions & 0 deletions cmd/common/fetchApiResources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// fetchApiResources.go

package common

import (
"fmt"

"github.com/spf13/cobra"
)

// FetchApiResourcesCmd provides api-resources command for the given service
func FetchApiResourcesCmd(serviceName string) *cobra.Command {
return &cobra.Command{
Use: "api_resources",
Short: fmt.Sprintf("Displays supported API resources for the %s service", serviceName),
RunE: func(cmd *cobra.Command, args []string) error {
return ListAPIResources(serviceName)
},
}
}
Loading
Loading