Skip to content

Commit

Permalink
added mock client for when ff patch is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Aug 4, 2022
1 parent dca6eb0 commit 20ca31f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .changes/0.3.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.3.3 - 2022-08-03
### Added
* Added MockFeatureFlagClient which is used when env var DBT_FF_DISABLE is set in environment. This allows users to disable live clients without breaking their projects
* Started using changie for changelog management
6 changes: 6 additions & 0 deletions .changes/header.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).
Empty file added .changes/unreleased/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions .changie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
changesDir: .changes
unreleasedDir: unreleased
headerPath: header.tpl.md
changelogPath: CHANGELOG.md
versionExt: md
versionFormat: '## {{.Version}} - {{.Time.Format "2006-01-02"}}'
kindFormat: '### {{.Kind}}'
changeFormat: '* {{.Body}}'
kinds:
- label: Added
- label: Changed
- label: Deprecated
- label: Removed
- label: Fixed
- label: Security
newlines:
afterChangelogHeader: 1
beforeChangelogVersion: 1
endOfVersion: 1
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).


## 0.3.3 - 2022-08-03
### Added
* Added MockFeatureFlagClient which is used when env var DBT_FF_DISABLE is set in environment. This allows users to disable live clients without breaking their projects
* Started using changie for changelog management
17 changes: 17 additions & 0 deletions dbt_feature_flags/mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Union

from dbt_feature_flags.base import BaseFeatureFlagsClient


class MockFeatureFlagClient(BaseFeatureFlagsClient):
def bool_variation(self, flag: str) -> bool:
return False

def string_variation(self, flag: str) -> str:
return ""

def number_variation(self, flag: str) -> Union[float, int]:
return 0

def json_variation(self, flag: str) -> Union[dict, list]:
return {}
7 changes: 3 additions & 4 deletions dbt_feature_flags/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"""
import os

from dbt_feature_flags import base, harness, launchdarkly
from dbt_feature_flags import base, mock, harness, launchdarkly


def _get_client() -> base.BaseFeatureFlagsClient:
"""Return the user specified client, valid impementations MUST
inherit from BaseFeatureFlagsClient"""
if os.getenv("DBT_FF_DISABLE"):
return mock.MockFeatureFlagClient()
ff_provider = os.getenv("FF_PROVIDER", "harness")
ff_client = None
if ff_provider == "harness":
Expand All @@ -24,9 +26,6 @@ def _get_client() -> base.BaseFeatureFlagsClient:


def patch_dbt_environment() -> None:
if os.getenv("DBT_FF_DISABLE"):
return

import functools

from dbt.clients import jinja
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dbt-feature-flags"
version = "0.3.2"
version = "0.3.3"
description = "Use feature flags in dbt models"
authors = ["z3z1ma <[email protected]>"]
include = ["zzz_dbt_feature_flags.pth"]
Expand Down

0 comments on commit 20ca31f

Please sign in to comment.