Skip to content

Commit

Permalink
fix: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
FemiNoviaLina committed Oct 3, 2024
1 parent 7dea742 commit d87fd7a
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 105 deletions.
10 changes: 5 additions & 5 deletions cmd/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ResourceCommand(cliConfig *Config) *cli.Command {
Work with resources.
`),
Example: heredoc.Doc(`
$ shield resource config upsert
$ shield resource config upload
`),
Annotations: map[string]string{
"group": "core",
Expand All @@ -42,7 +42,7 @@ func resourceConfigCommand(cliConfig *Config) *cli.Command {
Work with resources config.
`),
Example: heredoc.Doc(`
$ shield resource config upsert
$ shield resource config upload
`),
Annotations: map[string]string{
"group": "core",
Expand All @@ -59,11 +59,11 @@ func upsertResourcesConfigCommand(cliConfig *Config) *cli.Command {
var name, filePath, header string

cmd := &cli.Command{
Use: "upsert",
Short: "Upsert a resource config",
Use: "upload",
Short: "Upload a resource config",
Args: cli.NoArgs,
Example: heredoc.Doc(`
$ shield resource config upsert --name --file=<resource-config-body> --header=<key>:<value>
$ shield resource config upload --name --file=<resource-config-body> --header=<key>:<value>
`),
Annotations: map[string]string{
"resource:core": "true",
Expand Down
10 changes: 5 additions & 5 deletions cmd/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func RuleCommand(cliConfig *Config) *cli.Command {
Work with rules.
`),
Example: heredoc.Doc(`
$ shield rule config upsert
$ shield rule config upload
`),
Annotations: map[string]string{
"group": "core",
Expand All @@ -42,7 +42,7 @@ func ruleConfigCommand(cliConfig *Config) *cli.Command {
Work with rules config.
`),
Example: heredoc.Doc(`
$ shield rule config upsert
$ shield rule config upload
`),
Annotations: map[string]string{
"group": "core",
Expand All @@ -59,11 +59,11 @@ func upsertRuleConfigCommand(cliConfig *Config) *cli.Command {
var name, filePath, header string

cmd := &cli.Command{
Use: "upsert",
Short: "Upsert a rule config",
Use: "upload",
Short: "Upload a rule config",
Args: cli.NoArgs,
Example: heredoc.Doc(`
$ shield rule config upsert --name --file=<rule-config-body> --header=<key>:<value>
$ shield rule config upload --name --file=<rule-config-body> --header=<key>:<value>
`),
Annotations: map[string]string{
"rule:core": "true",
Expand Down
4 changes: 2 additions & 2 deletions core/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Transactor interface {
}

type SchemaRepository interface {
UpsertResourceConfigs(ctx context.Context, name string, config schema.NamespaceConfigMapType) (ResourceConfig, error)
UpsertConfig(ctx context.Context, name string, config schema.NamespaceConfigMapType) (Config, error)
}

type Resource struct {
Expand Down Expand Up @@ -86,7 +86,7 @@ type PagedResources struct {

type ResourcePermissions = map[string][]string

type ResourceConfig struct {
type Config struct {
ID uint32
Name string
Config string
Expand Down
20 changes: 10 additions & 10 deletions core/resource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,18 @@ func (s Service) listUserResources(ctx context.Context, resourceType string, use
return resPermissionsMap, nil
}

func (s Service) UpsertResourcesConfig(ctx context.Context, name string, config string) (ResourceConfig, error) {
func (s Service) UpsertConfig(ctx context.Context, name string, config string) (Config, error) {
if strings.TrimSpace(name) == "" {
return ResourceConfig{}, ErrInvalidDetail
return Config{}, ErrInvalidDetail
}

if strings.TrimSpace(config) == "" {
return ResourceConfig{}, ErrInvalidDetail
return Config{}, ErrInvalidDetail
}

resourceConfig, err := resourcecfg.ParseConfigYaml([]byte(config))
if err != nil {
return ResourceConfig{}, ErrInvalidDetail
return Config{}, ErrInvalidDetail
}

configMap := make(schema.NamespaceConfigMapType)
Expand All @@ -535,26 +535,26 @@ func (s Service) UpsertResourcesConfig(ctx context.Context, name string, config

ctx = s.repository.WithTransaction(ctx)

res, err := s.schemaRepository.UpsertResourceConfigs(ctx, name, configMap)
res, err := s.schemaRepository.UpsertConfig(ctx, name, configMap)
if err != nil {
if txErr := s.repository.Rollback(ctx, err); txErr != nil {
return ResourceConfig{}, err
return Config{}, err
}
return ResourceConfig{}, err
return Config{}, err
}

if s.appConfig.ConfigStorage == RESOURCES_CONFIG_STORAGE_PG {
if err := s.schemaService.RunMigrations(ctx); err != nil {
if txErr := s.repository.Rollback(ctx, err); txErr != nil {
return ResourceConfig{}, err
return Config{}, err
}
return ResourceConfig{}, err
return Config{}, err
}
}

err = s.repository.Commit(ctx)
if err != nil {
return ResourceConfig{}, err
return Config{}, err
}

return res, nil
Expand Down
4 changes: 2 additions & 2 deletions core/rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

type ConfigRepository interface {
GetAll(ctx context.Context) ([]Ruleset, error)
Upsert(ctx context.Context, name string, config Ruleset) (RuleConfig, error)
Upsert(ctx context.Context, name string, config Ruleset) (Config, error)
}

type Ruleset struct {
Rules []Rule `yaml:"rules"`
}

type RuleConfig struct {
type Config struct {
ID uint32
Name string
Config string
Expand Down
8 changes: 4 additions & 4 deletions core/rule/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ func (s Service) GetAllConfigs(ctx context.Context) ([]Ruleset, error) {
return s.configRepository.GetAll(ctx)
}

func (s Service) UpsertRulesConfigs(ctx context.Context, name string, config string) (RuleConfig, error) {
func (s Service) UpsertRulesConfigs(ctx context.Context, name string, config string) (Config, error) {
if strings.TrimSpace(name) == "" {
return RuleConfig{}, ErrInvalidRuleConfig
return Config{}, ErrInvalidRuleConfig
}

if strings.TrimSpace(config) == "" {
return RuleConfig{}, ErrInvalidRuleConfig
return Config{}, ErrInvalidRuleConfig
}

yamlRuleset, err := rulecfg.ParseRulesetYaml([]byte(config))
if err != nil {
return RuleConfig{}, ErrInvalidRuleConfig
return Config{}, ErrInvalidRuleConfig
}

targetRuleset := YamlRulesetToRuleset(yamlRuleset)
Expand Down
30 changes: 15 additions & 15 deletions internal/api/v1beta1/mocks/resource_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions internal/api/v1beta1/mocks/rule_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/api/v1beta1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ResourceService interface {
BulkCheckAuthz(ctx context.Context, resources []resource.Resource, actions []action.Action) ([]relation.Permission, error)
ListUserResourcesByType(ctx context.Context, userID string, resourceType string, permissions []string) (resource.ResourcePermissions, error)
ListAllUserResources(ctx context.Context, userID string, resourceTypes []string, permissions []string) (map[string]resource.ResourcePermissions, error)
UpsertResourcesConfig(ctx context.Context, name string, config string) (resource.ResourceConfig, error)
UpsertConfig(ctx context.Context, name string, config string) (resource.Config, error)
}

var grpcResourceNotFoundErr = status.Errorf(codes.NotFound, "resource doesn't exist")
Expand Down Expand Up @@ -304,7 +304,7 @@ func (h Handler) ListUserResourcesByType(ctx context.Context, request *shieldv1b
func (h Handler) UpsertResourcesConfig(ctx context.Context, request *shieldv1beta1.UpsertResourcesConfigRequest) (*shieldv1beta1.UpsertResourcesConfigResponse, error) {
logger := grpczap.Extract(ctx)

rc, err := h.resourceService.UpsertResourcesConfig(ctx, request.Name, request.Config)
rc, err := h.resourceService.UpsertConfig(ctx, request.Name, request.Config)
if err != nil {
logger.Error(err.Error())
switch {
Expand All @@ -322,7 +322,7 @@ func (h Handler) UpsertResourcesConfig(ctx context.Context, request *shieldv1bet
return resourceConfigToPB(rc), nil
}

func resourceConfigToPB(from resource.ResourceConfig) *shieldv1beta1.UpsertResourcesConfigResponse {
func resourceConfigToPB(from resource.Config) *shieldv1beta1.UpsertResourcesConfigResponse {
return &shieldv1beta1.UpsertResourcesConfigResponse{
Id: from.ID,
Name: from.Name,
Expand Down
16 changes: 8 additions & 8 deletions internal/api/v1beta1/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,9 @@ func TestHandler_UpsertResourcesConfig(t *testing.T) {
{
name: "should return success if service return nil err",
setup: func(rs *mocks.ResourceService) {
rs.EXPECT().UpsertResourcesConfig(mock.AnythingOfType("context.todoCtx"),
rs.EXPECT().UpsertConfig(mock.AnythingOfType("context.todoCtx"),
"entropy", "entropy:\n type: resource_group\n resource_types:\n - name: firehose").
Return(resource.ResourceConfig{
Return(resource.Config{
ID: 1,
Name: "entropy",
Config: "entropy:\n type: resource_group\n resource_types:\n - name: firehose",
Expand All @@ -994,9 +994,9 @@ func TestHandler_UpsertResourcesConfig(t *testing.T) {
{
name: "should return bad body error if service return invalid detail err",
setup: func(rs *mocks.ResourceService) {
rs.EXPECT().UpsertResourcesConfig(mock.AnythingOfType("context.todoCtx"),
rs.EXPECT().UpsertConfig(mock.AnythingOfType("context.todoCtx"),
"entropy", "entropy:\n type: resource_group\n resource_types:\n - name: firehose").
Return(resource.ResourceConfig{}, resource.ErrInvalidDetail)
Return(resource.Config{}, resource.ErrInvalidDetail)
},
request: &shieldv1beta1.UpsertResourcesConfigRequest{
Name: "entropy",
Expand All @@ -1007,9 +1007,9 @@ func TestHandler_UpsertResourcesConfig(t *testing.T) {
{
name: "should return not supported error if service return not supported err",
setup: func(rs *mocks.ResourceService) {
rs.EXPECT().UpsertResourcesConfig(mock.AnythingOfType("context.todoCtx"),
rs.EXPECT().UpsertConfig(mock.AnythingOfType("context.todoCtx"),
"entropy", "entropy:\n type: resource_group\n resource_types:\n - name: firehose").
Return(resource.ResourceConfig{}, resource.ErrUpsertConfigNotSupported)
Return(resource.Config{}, resource.ErrUpsertConfigNotSupported)
},
request: &shieldv1beta1.UpsertResourcesConfigRequest{
Name: "entropy",
Expand All @@ -1020,9 +1020,9 @@ func TestHandler_UpsertResourcesConfig(t *testing.T) {
{
name: "should return internal error if service return unmarshal err",
setup: func(rs *mocks.ResourceService) {
rs.EXPECT().UpsertResourcesConfig(mock.AnythingOfType("context.todoCtx"),
rs.EXPECT().UpsertConfig(mock.AnythingOfType("context.todoCtx"),
"entropy", "entropy:\n type: resource_group\n resource_types:\n - name: firehose").
Return(resource.ResourceConfig{}, resource.ErrMarshal)
Return(resource.Config{}, resource.ErrMarshal)
},
request: &shieldv1beta1.UpsertResourcesConfigRequest{
Name: "entropy",
Expand Down
4 changes: 2 additions & 2 deletions internal/api/v1beta1/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type RuleService interface {
GetAllConfigs(ctx context.Context) ([]rule.Ruleset, error)
UpsertRulesConfigs(ctx context.Context, name string, config string) (rule.RuleConfig, error)
UpsertRulesConfigs(ctx context.Context, name string, config string) (rule.Config, error)
}

func (h Handler) UpsertRulesConfig(ctx context.Context, request *shieldv1beta1.UpsertRulesConfigRequest) (*shieldv1beta1.UpsertRulesConfigResponse, error) {
Expand All @@ -35,7 +35,7 @@ func (h Handler) UpsertRulesConfig(ctx context.Context, request *shieldv1beta1.U
return ruleConfigToPB(rc), nil
}

func ruleConfigToPB(from rule.RuleConfig) *shieldv1beta1.UpsertRulesConfigResponse {
func ruleConfigToPB(from rule.Config) *shieldv1beta1.UpsertRulesConfigResponse {
return &shieldv1beta1.UpsertRulesConfigResponse{
Id: from.ID,
Name: from.Name,
Expand Down
4 changes: 2 additions & 2 deletions internal/store/blob/rule_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ func (repo *RuleRepository) Close() error {
return repo.bucket.Close()
}

func (repo *RuleRepository) Upsert(ctx context.Context, name string, config rule.Ruleset) (rule.RuleConfig, error) {
func (repo *RuleRepository) Upsert(ctx context.Context, name string, config rule.Ruleset) (rule.Config, error) {
// upsert is currently not supported for BLOB rule config storage type
return rule.RuleConfig{}, rule.ErrUpsertConfigNotSupported
return rule.Config{}, rule.ErrUpsertConfigNotSupported
}

func NewRuleRepository(logger log.Logger, b Bucket) *RuleRepository {
Expand Down
Loading

0 comments on commit d87fd7a

Please sign in to comment.