Skip to content

🚀[Feature]: Add a context validator, so we can add condition into highlevel functions #186

@MariusStorhaug

Description

@MariusStorhaug

Description

Want to be able so say that a certain type of functions can only be called with JWT (App) some can only be called as a user, functions requires specific permissions... etc. Many things to be able to check... !

  • Assert-GitHubContext -AuthType 'APP','IAT','UAT','PAT'
  • Implement in Invoke-GitHubAPI
function Invoke-GitHubAPI {
    param(

        # The requirements for the function call. This is used to determine if the context is valid for the API call.
        # Keys:
        # - name: AuthType
        #   description:  The type of token required for the command.
        #   type: [string[]]
        #   allowedValues: ['UAT', 'PAT', 'App', 'IAT']
        [Parameter()]
        [hashtable] $Requires,

    )

    # Validate if the requirements for the API call are met
    $callingFunction = (Get-PSCallStack)[1].Command
    if ($callingFunction -ne '<ScriptBlock>' -and $PSBoundParameters.ContainsKey('Requires')) {
        $check = @{
            Command  = $callingFunction
            Requires = $Requires
            Context  = $Context
        }
        Assert-GitHubContext @check
    }
}
  • Implement in functions
  • Implement in functiontemplate

For functions:

    $inputObject = @{
        Context     = $Context
        APIEndpoint = '/app/installations'
        Method      = 'GET'
        Requires    = @{
            AuthType = 'App'
        }
    }

Metadata

Metadata

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions