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

Add Authentication & Logging #11

Merged
merged 30 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ venv.bak/
.dmypy.json
dmypy.json

# ruff
.ruff_cache/

# Pyre type checker
.pyre/

Expand All @@ -157,4 +160,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
12 changes: 6 additions & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"recommendations": [
"ms-python.python",
"esbenp.prettier-vscode",
"ms-vscode.powershell",
"charliermarsh.ruff"
]
"recommendations": [
"ms-python.python",
"esbenp.prettier-vscode",
"ms-vscode.powershell",
"charliermarsh.ruff"
]
}
69 changes: 35 additions & 34 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
{
"editor": {
"tabSize": 4,
"trimAutoWhitespace": false,
"defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
"editor": {
"tabSize": 4,
"trimAutoWhitespace": false,
"defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"diffEditor": {
"ignoreTrimWhitespace": false
},
"files": {
"trimTrailingWhitespace": false,
"trimTrailingWhitespaceInRegexAndStrings": false,
"insertFinalNewline": true,
"autoSave": "off"
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"diffEditor": {
"ignoreTrimWhitespace": false
},
"files": {
"trimTrailingWhitespace": false,
"trimTrailingWhitespaceInRegexAndStrings": false,
"insertFinalNewline": true,
"autoSave": "off"
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
}
},
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
},
"git": {
"branchPrefix": "users/",
"enableSmartCommit": true,
"confirmSync": false,
"autofetch": true
},
"ruff" :{
"organizeImports": true,
"fixAll": true,
"editor.formatOnSave": true
}
"editor.formatOnSave": true
},
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell",
"editor.formatOnSave": true
},
"git": {
"branchPrefix": "users/",
"enableSmartCommit": true,
"confirmSync": false,
"autofetch": true
},
"ruff": {
"organizeImports": true,
"fixAll": true
}
}
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.6
19 changes: 14 additions & 5 deletions debug/debug_local.py → devtools/debug_local.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# The following is intended for developers of fabric-cicd to debug locally against the github repo

from pathlib import Path
import sys
from pathlib import Path

from azure.identity import ClientSecretCredential

root_directory = Path(__file__).resolve().parent.parent
sys.path.append(str(root_directory / "src"))
from fabric_cicd import FabricWorkspace, publish_all_items, unpublish_all_orphan_items
sys.path.insert(0, str(root_directory / "src"))
from fabric_cicd import FabricWorkspace, change_log_level, publish_all_items, unpublish_all_orphan_items

# change_log_level()
shirasassoon marked this conversation as resolved.
Show resolved Hide resolved

# The defined environment values should match the names found in the parameter.yml file
workspace_id = "fd844302-8fdd-42c1-b1ff-e35bc8e294e4"
Expand All @@ -17,6 +21,12 @@
# Explicitly define which of the item types we want to deploy
item_type_in_scope = ["DataPipeline", "Notebook", "Environment"]


client_id = "your-client-id"
client_secret = "your-client-secret"
tenant_id = "your-tenant-id"
token_credential = ClientSecretCredential(client_id=client_id, client_secret=client_secret, tenant_id=tenant_id)

# Initialize the FabricWorkspace object with the required parameters
target_workspace = FabricWorkspace(
workspace_id=workspace_id,
Expand All @@ -25,8 +35,7 @@
item_type_in_scope=item_type_in_scope,
# Override base url in rare cases where it's different
base_api_url="https://msitapi.fabric.microsoft.com/",
# Print all api calls to debug what is being passed to fabric
# debug_output=True,
token_credential=token_credential,
)

# Publish all items defined in item_type_in_scope
Expand Down
7 changes: 7 additions & 0 deletions devtools/pypi_build_release_dev.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Remove-Item -Recurse -Force dist/*

python -m build

python -m twine upload --repository testpypi dist/*

pip install --upgrade --index-url https://test.pypi.org/simple/ fabric-cicd[dev]
15 changes: 7 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ name = "fabric-cicd"
authors = [
{ name = "Microsoft Corporation" }
]
version = "0.1.5"
dynamic = ["version", "dependencies", "optional-dependencies"]

description = "Microsoft Fabric CI/CD"
readme = "README.md"
requires-python = ">=3.9"
Expand All @@ -17,12 +18,10 @@ classifiers = [
]
license = { text = "MIT License" }

# Define dependencies here
dependencies = [
"requests>=2.32.3",
"pyyaml>=6.0.2",
"azure-identity>=1.19.0"
]
[tool.setuptools.dynamic]
version = {file = "VERSION"}
dependencies = {file = "requirements.txt"}
optional-dependencies.dev = {file = "requirements-dev.txt"}

[tool.setuptools.packages.find]
where = ["src"]
Expand All @@ -32,7 +31,7 @@ Repository = "https://github.com/microsoft/fabric-cicd.git"

[tool.ruff]
line-length = 120
exclude = ["debug", "sample"]
exclude = ["sample/workspace"]

[tool.ruff.lint]
preview=true
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ruff
gitpython
build
twine
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
requests>=2.32.3
pyyaml>=6.0.2
azure-identity>=1.19.0
colorlog>=6.9.0
27 changes: 27 additions & 0 deletions sample/auth_default_credential.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Example of leveraging default authentication flows
Refer to the authentication section in the README for details:
https://github.com/microsoft/fabric-cicd/tree/main?tab=readme-ov-file#authentication
"""

from fabric_cicd import FabricWorkspace, publish_all_items, unpublish_all_orphan_items

# Sample values for FabricWorkspace parameters
workspace_id = "your-workspace-id"
environment = "your-environment"
repository_directory = "your-repository-directory"
item_type_in_scope = ["Notebook", "DataPipeline", "Environment"]

# Initialize the FabricWorkspace object with the required parameters
target_workspace = FabricWorkspace(
workspace_id=workspace_id,
environment=environment,
repository_directory=repository_directory,
item_type_in_scope=item_type_in_scope,
)

# Publish all items defined in item_type_in_scope
publish_all_items(target_workspace)

# Unpublish all items defined in item_type_in_scope not found in repository
unpublish_all_orphan_items(target_workspace)
34 changes: 34 additions & 0 deletions sample/auth_spn_secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Example of authenticating with SPN + Secret
Can be expanded to retrieve values from Key Vault or other sources
"""

from azure.identity import ClientSecretCredential

from fabric_cicd import FabricWorkspace, publish_all_items, unpublish_all_orphan_items

client_id = "your-client-id"
client_secret = "your-client-secret"
tenant_id = "your-tenant-id"
token_credential = ClientSecretCredential(client_id=client_id, client_secret=client_secret, tenant_id=tenant_id)

# Sample values for FabricWorkspace parameters
workspace_id = "your-workspace-id"
environment = "your-environment"
repository_directory = "your-repository-directory"
item_type_in_scope = ["Notebook", "DataPipeline", "Environment"]

# Initialize the FabricWorkspace object with the required parameters
target_workspace = FabricWorkspace(
workspace_id=workspace_id,
environment=environment,
repository_directory=repository_directory,
item_type_in_scope=item_type_in_scope,
token_credential=token_credential,
)

# Publish all items defined in item_type_in_scope
publish_all_items(target_workspace)

# Unpublish all items defined in item_type_in_scope not found in repository
unpublish_all_orphan_items(target_workspace)
4 changes: 0 additions & 4 deletions sample/deploy.ps1

This file was deleted.

68 changes: 0 additions & 68 deletions sample/deploy.py

This file was deleted.

2 changes: 0 additions & 2 deletions sample/install_requirements.sh

This file was deleted.

38 changes: 38 additions & 0 deletions sample/optional_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Example of optional parameters for FabricWorkspace and publish functions.
"""

from fabric_cicd import FabricWorkspace, change_log_level, publish_all_items, unpublish_all_orphan_items

# Sample values for FabricWorkspace parameters
workspace_id = "your-workspace-id"
environment = "your-environment"
repository_directory = "your-repository-directory"
item_type_in_scope = ["Notebook", "DataPipeline", "Environment"]
base_api_url = "https://msitapi.fabric.microsoft.com/"
token_credential = TokenCredential

# Optional: Print all API calls to log file
change_log_level("DEBUG")

# Initialize the FabricWorkspace object with the required and optional parameters
target_workspace = FabricWorkspace(
workspace_id=workspace_id,
environment=environment,
repository_directory=repository_directory,
item_type_in_scope=item_type_in_scope,
# Optional: Override base URL in rare cases where it's different
base_api_url=base_api_url,
# Optional: Override token credential to use a different authentication
token_credential=token_credential,
)

# Publish all items defined in item_type_in_scope
publish_all_items(target_workspace)

# Unpublish all items defined in item_type_in_scope not found in repository
unpublish_all_orphan_items(
target_workspace,
# Optional: Exclude item names matching the regex pattern
item_name_exclude_regex=r"^DEBUG.*",
)
Loading
Loading