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

Adding tm1project to the Git service #775

Merged
merged 2 commits into from
Aug 31, 2022
Merged

Adding tm1project to the Git service #775

merged 2 commits into from
Aug 31, 2022

Conversation

nicolasbisurgi
Copy link
Collaborator

In these commits you will find the GitProject.py that has the class, properties and methods to handle the tm1project and the GitService that incorporates the GitProject objects and adds the ability to get, put and delete the tm1project from/to the server.
This is a first draft so we can make changes along the way. I also have some of the tm1project sections defined as classes (like object, task and deployment) but I'm not done with them.

GitProject.py contains the tm1project as a class with its properties and methods
Added the import of the GitProject class
Added functions to get, put and delete a tm1project in the tm1 server.
@MariusWirtz
Copy link
Collaborator

MariusWirtz commented Aug 31, 2022

Hi @nicolasbisurgi,

sorry for the late reply on this subject.
I can confirm that the changes are working! Thank you.

I will merge the change as is and add a few commits on top tonight and over the next days.

  • I want to change a few namings e.g. postpush to post_push
  • I identified a small issue, that if no project is defined in TM1, it raises an error (possibly better to return None instead)
  • In the GitProject class it would be nice to have helper functions to help populate the different properties such as add_task, ignore_process, ignore_cube, ...
  • add a test class for GitProject

Obviously, I would appreciate further support along the way :)

For future reference and other potential contributors here is a sample of how to use this new feature.

from TM1py import TM1Service

# Setup
# 1. create private repo in GitHub
# 2. follow instructions to add ssh key to GitHub profile
# https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
from TM1py.Objects.GitProject import TM1Project

with TM1Service(address="", port=11247, ssl=True, user="admin", password="") as tm1:
    # copy from GitHub repo
    url = 'git@github.com:MariusWirtz-cubewise/tm1-model.git'

    # can be anything
    deployment = 'prod'

    # as specified during creation of ssh key
    with open(r'C:\Users\MariusWirtz\.ssh\id_ecdsa', 'r') as file:
        private_key = file.read()
    with open(r'C:\Users\MariusWirtz\.ssh\id_ecdsa.pub', 'r') as file:
        public_key = file.read()

    # is set when ssh keys are created
    passphrase = ''

    tm1.git.git_init(
        git_url=url,
        deployment=deployment,
        public_key=public_key,
        private_key=private_key,
        passphrase=passphrase)

    project = TM1Project(name="Project Definition", tasks=dict())
    project._tasks["Security Refresh"] = {
        "Process": "Processes('Bedrock.Security.Refresh')",
        "Parameters": []
    }
    tm1.git.tm1project_put(project)

    project = tm1.git.tm1project_get()
    print(project)

    tm1.git.git_push(
        execute=True,
        # on first execution change this to `new_branch="main",`
        branch="main",
        message="Initial Commit",
        author="Marius",
        email="MWirtz@cubewise.com",
        public_key=public_key,
        private_key=private_key,
        passphrase=passphrase)

@MariusWirtz MariusWirtz merged commit d314171 into cubewise-code:master Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants