def test_auth(): obj = launch_plan.Auth(assumable_iam_role="rollie-pollie") assert obj.assumable_iam_role == "rollie-pollie" assert not obj.kubernetes_service_account obj2 = launch_plan.Auth.from_flyte_idl(obj.to_flyte_idl()) assert obj == obj2 obj = launch_plan.Auth(kubernetes_service_account="service-account-name") assert obj.kubernetes_service_account == "service-account-name" assert not obj.assumable_iam_role obj2 = launch_plan.Auth.from_flyte_idl(obj.to_flyte_idl()) assert obj == obj2
def create_launch_plan(self, default_inputs=None, fixed_inputs=None, schedule=None, role=None, notifications=None, labels=None, annotations=None, assumable_iam_role=None, kubernetes_service_account=None, cls=None): """ This method will create a launch plan object that can execute this workflow. :param dict[Text,flytekit.common.promise.Input] default_inputs: :param dict[Text,T] fixed_inputs: :param flytekit.models.schedule.Schedule schedule: A schedule on which to execute this launch plan. :param Text role: Deprecated. Use assumable_iam_role instead. :param list[flytekit.models.common.Notification] notifications: A list of notifications to enact by default for this launch plan. :param flytekit.models.common.Labels labels: :param flytekit.models.common.Annotations annotations: :param cls: This parameter can be used by users to define an extension of a launch plan to instantiate. The class provided should be a subclass of flytekit.common.launch_plan.SdkLaunchPlan. :param Text assumable_iam_role: The IAM role to execute the workflow with. :param Text kubernetes_service_account: The kubernetes service account to execute the workflow with. :rtype: flytekit.common.launch_plan.SdkRunnableLaunchPlan """ # TODO: Actually ensure the parameters conform. if role and (assumable_iam_role or kubernetes_service_account): raise ValueError( "Cannot set both role and auth. Role is deprecated, use auth instead." ) fixed_inputs = fixed_inputs or {} merged_default_inputs = { v.name: v for v in self._user_inputs if v.name not in fixed_inputs } merged_default_inputs.update(default_inputs or {}) if role: assumable_iam_role = role auth = _launch_plan_models.Auth( assumable_iam_role=assumable_iam_role, kubernetes_service_account=kubernetes_service_account) return (cls or _launch_plan.SdkRunnableLaunchPlan)( sdk_workflow=self, default_inputs={ k: user_input.rename_and_return_reference(k) for k, user_input in _six.iteritems(merged_default_inputs) }, fixed_inputs=fixed_inputs, schedule=schedule, notifications=notifications, labels=labels, annotations=annotations, auth=auth, )
def auth(self): """ :rtype: flytekit.models.LaunchPlan.Auth """ fixed_auth = super(SdkLaunchPlan, self).auth if fixed_auth is not None and\ (fixed_auth.assumable_iam_role is not None or fixed_auth.kubernetes_service_account is not None): return fixed_auth assumable_iam_role = _auth_config.ASSUMABLE_IAM_ROLE.get() kubernetes_service_account = _auth_config.KUBERNETES_SERVICE_ACCOUNT.get( ) if not (assumable_iam_role or kubernetes_service_account): _logging.warning( "Using deprecated `role` from config. " "Please update your config to use `assumable_iam_role` instead" ) assumable_iam_role = _sdk_config.ROLE.get() return _launch_plan_models.Auth( assumable_iam_role=assumable_iam_role, kubernetes_service_account=kubernetes_service_account)
def __init__( self, sdk_workflow, default_inputs=None, fixed_inputs=None, role=None, schedule=None, notifications=None, labels=None, annotations=None, auth=None, ): """ :param flytekit.common.workflow.SdkWorkflow sdk_workflow: :param dict[Text,flytekit.common.promise.Input] default_inputs: :param dict[Text,Any] fixed_inputs: These inputs will be fixed and not need to be set when executing this launch plan. :param Text role: Deprecated. IAM role to execute this launch plan with. :param flytekit.models.schedule.Schedule: Schedule to apply to this workflow. :param list[flytekit.models.common.Notification]: List of notifications to apply to this launch plan. :param flytekit.models.common.Labels labels: Any custom kubernetes labels to apply to workflows executed by this launch plan. :param flytekit.models.common.Annotations annotations: Any custom kubernetes annotations to apply to workflows executed by this launch plan. Any custom kubernetes annotations to apply to workflows executed by this launch plan. :param flytekit.models.launch_plan.Auth auth: The auth method with which to execute the workflow. """ if role and auth: raise ValueError( "Cannot set both role and auth. Role is deprecated, use auth instead." ) fixed_inputs = fixed_inputs or {} default_inputs = default_inputs or {} if role: auth = _launch_plan_models.Auth(assumable_iam_role=role) super(SdkRunnableLaunchPlan, self).__init__( _identifier.Identifier(_identifier_model.ResourceType.WORKFLOW, _internal_config.PROJECT.get(), _internal_config.DOMAIN.get(), _uuid.uuid4().hex, _internal_config.VERSION.get()), _launch_plan_models.LaunchPlanMetadata( schedule=schedule or _schedule_model.Schedule(''), notifications=notifications or []), _interface_models.ParameterMap(default_inputs), _type_helpers.pack_python_std_map_to_literal_map( fixed_inputs, { k: _type_helpers.get_sdk_type_from_literal_type(var.type) for k, var in _six.iteritems(sdk_workflow.interface.inputs) if k in fixed_inputs }), labels or _common_models.Labels({}), annotations or _common_models.Annotations({}), auth, ) self._interface = _interface.TypedInterface( {k: v.var for k, v in _six.iteritems(default_inputs)}, sdk_workflow.interface.outputs) self._upstream_entities = {sdk_workflow} self._sdk_workflow = sdk_workflow
def __init__( self, sdk_workflow, default_inputs=None, fixed_inputs=None, role=None, schedule=None, notifications=None, labels=None, annotations=None, auth=None, ): """ :param flytekit.common.workflow.SdkWorkflow sdk_workflow: :param dict[Text,flytekit.common.promise.Input] default_inputs: :param dict[Text,Any] fixed_inputs: These inputs will be fixed and not need to be set when executing this launch plan. :param Text role: Deprecated. IAM role to execute this launch plan with. :param flytekit.models.schedule.Schedule: Schedule to apply to this workflow. :param list[flytekit.models.common.Notification]: List of notifications to apply to this launch plan. :param flytekit.models.common.Labels labels: Any custom kubernetes labels to apply to workflows executed by this launch plan. :param flytekit.models.common.Annotations annotations: Any custom kubernetes annotations to apply to workflows executed by this launch plan. Any custom kubernetes annotations to apply to workflows executed by this launch plan. :param flytekit.models.launch_plan.Auth auth: The auth method with which to execute the workflow. """ if role and auth: raise ValueError( "Cannot set both role and auth. Role is deprecated, use auth instead." ) fixed_inputs = fixed_inputs or {} default_inputs = default_inputs or {} if role: auth = _launch_plan_models.Auth(assumable_iam_role=role) # The constructor for SdkLaunchPlan sets the id to None anyways so we don't bother passing in an ID. The ID # should be set in one of three places, # 1) When the object is registered (in the code above) # 2) By the dynamic task code after this runnable object has already been __call__'ed. The SdkNode produced # maintains a link to this object and will set the ID according to the configuration variables present. # 3) When SdkLaunchPlan.fetch() is run super(SdkRunnableLaunchPlan, self).__init__( None, _launch_plan_models.LaunchPlanMetadata( schedule=schedule or _schedule_model.Schedule(''), notifications=notifications or []), _interface_models.ParameterMap(default_inputs), _type_helpers.pack_python_std_map_to_literal_map( fixed_inputs, { k: _type_helpers.get_sdk_type_from_literal_type(var.type) for k, var in _six.iteritems(sdk_workflow.interface.inputs) if k in fixed_inputs }), labels or _common_models.Labels({}), annotations or _common_models.Annotations({}), auth, ) self._interface = _interface.TypedInterface( {k: v.var for k, v in _six.iteritems(default_inputs)}, sdk_workflow.interface.outputs) self._upstream_entities = {sdk_workflow} self._sdk_workflow = sdk_workflow