Beispiel #1
0
func auditStepBeforeShare(pth string) error {
	stepModel, err := stepman.ParseStepYml(pth, false)
	if err != nil {
		return err
	}
	if err := stepModel.AuditBeforeShare(); err != nil {
		return err
	}
	return nil
}
Beispiel #2
0
func auditStepBeforeSharePullRequest(pth string) error {
	stepID, version, err := detectStepIDAndVersionFromPath(pth)
	if err != nil {
		return err
	}

	stepModel, err := stepman.ParseStepYml(pth, false)
	if err != nil {
		return err
	}

	if err := auditStepModelBeforeSharePullRequest(stepModel, stepID, version); err != nil {
		return err
	}
	return nil
}
Beispiel #3
0
func stepInfo(c *cli.Context) error {
	// Input validation
	format := c.String(FormatKey)
	collectionURI := c.String(CollectionKey)
	YMLPath := c.String(StepYMLKey)
	isShort := c.Bool(ShortKey)
	id := c.String(IDKey)
	version := c.String(VersionKey)

	if format == "" {
		format = OutputFormatRaw
	} else if !(format == OutputFormatRaw || format == OutputFormatJSON) {
		return fmt.Errorf("Invalid output format: %s", format)
	}

	if YMLPath == "" && collectionURI == "" {
		return fmt.Errorf("Missing required input: no StepLib, nor step.yml path defined as step info source")
	}

	if YMLPath != "" {
		//
		// Local step info
		step, err := stepman.ParseStepYml(YMLPath, false)
		if err != nil {
			return fmt.Errorf("Failed to parse step.yml (path:%s), err: %s", YMLPath, err)
		}

		inputs, err := getEnvInfos(step.Inputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (path:%s) input infos, err: %s", YMLPath, err)
		}

		outputs, err := getEnvInfos(step.Outputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
		}

		stepInfo := models.StepInfoModel{
			StepLib:     YMLPath,
			Description: *step.Description,
			Source:      *step.SourceCodeURL,
			Inputs:      inputs,
			Outputs:     outputs,
		}

		if err := printStepInfo(stepInfo, format, isShort, true); err != nil {
			return fmt.Errorf("Failed to print step info, err: %s", err)
		}
	} else {
		//
		// StepLib step info

		// Input validation
		if id == "" {
			return errors.New("Missing required input: step id")
		}

		// Check if setup was done for collection
		if exist, err := stepman.RootExistForCollection(collectionURI); err != nil {
			return fmt.Errorf("Failed to check if setup was done for steplib (%s), error: %s", collectionURI, err)
		} else if !exist {
			if err := setupSteplib(collectionURI, format != OutputFormatRaw); err != nil {
				return errors.New("Failed to setup steplib")
			}
		}

		// Check if step exist in collection
		collection, err := stepman.ReadStepSpec(collectionURI)
		if err != nil {
			return fmt.Errorf("Failed to read steps spec (spec.json), err: %s", err)
		}

		step, stepFound := collection.GetStep(id, version)
		if !stepFound {
			if version == "" {
				return fmt.Errorf("Collection doesn't contain any version of step (id:%s)", id)
			}
			return fmt.Errorf("Collection doesn't contain step (id:%s) (version:%s)", id, version)
		}

		latest, err := collection.GetLatestStepVersion(id)
		if err != nil {
			return fmt.Errorf("Failed to get latest version of step (id:%s)", id)
		}

		if version == "" {
			version = latest
		}

		inputs, err := getEnvInfos(step.Inputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (id:%s) input infos, err: %s", id, err)
		}

		outputs, err := getEnvInfos(step.Outputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (id:%s) output infos, err: %s", id, err)
		}

		stepInfo := models.StepInfoModel{
			ID:          id,
			Version:     version,
			Latest:      latest,
			Description: *step.Description,
			StepLib:     collectionURI,
			Source:      *step.SourceCodeURL,
			Inputs:      inputs,
			Outputs:     outputs,
		}

		route, found := stepman.ReadRoute(collectionURI)
		if !found {
			return fmt.Errorf("No route found for collection: %s", collectionURI)
		}
		globalStepInfoPth := stepman.GetStepGlobalInfoPath(route, id)
		if globalStepInfoPth != "" {
			globalInfo, found, err := stepman.ParseGlobalStepInfoYML(globalStepInfoPth)
			if err != nil {
				return fmt.Errorf("Failed to get step (path:%s) output infos, err: %s", globalStepInfoPth, err)
			}

			if found {
				stepInfo.GlobalInfo = globalInfo
			}
		}

		if err := printStepInfo(stepInfo, format, isShort, false); err != nil {
			return fmt.Errorf("Failed to print step info, err: %s", err)
		}
	}

	return nil
}
Beispiel #4
0
func stepInfo(c *cli.Context) error {
	// Input validation
	format := c.String(FormatKey)
	collectionURI := c.String(CollectionKey)
	YMLPath := c.String(StepYMLKey)
	isShort := c.Bool(ShortKey)
	id := c.String(IDKey)
	version := c.String(VersionKey)

	if format == "" {
		format = OutputFormatRaw
	} else if !(format == OutputFormatRaw || format == OutputFormatJSON) {
		return fmt.Errorf("Invalid output format: %s", format)
	}

	if YMLPath == "" && collectionURI == "" {
		return fmt.Errorf("Missing required input: no StepLib, nor step.yml path defined as step info source")
	}

	if YMLPath != "" {
		//
		// Local step info
		step, err := stepman.ParseStepYml(YMLPath, false)
		if err != nil {
			return fmt.Errorf("Failed to parse step.yml (path:%s), err: %s", YMLPath, err)
		}

		inputs, err := getEnvInfos(step.Inputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (path:%s) input infos, err: %s", YMLPath, err)
		}

		outputs, err := getEnvInfos(step.Outputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
		}

		stepInfo := models.StepInfoModel{
			StepLib:     YMLPath,
			Description: *step.Description,
			Source:      *step.SourceCodeURL,
			Inputs:      inputs,
			Outputs:     outputs,
		}

		if err := printStepInfo(stepInfo, format, isShort, true); err != nil {
			return fmt.Errorf("Failed to print step info, err: %s", err)
		}
	} else {
		//
		// StepLib step info

		stepVersion, err := ReadStepInfo(collectionURI, id, version, true, format != OutputFormatRaw)
		if err != nil {
			return fmt.Errorf("Failed to read Step information, error: %s", err)
		}

		if version == "" {
			version = stepVersion.Version
		}
		step := stepVersion.Step

		inputs, err := getEnvInfos(step.Inputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (id:%s) input infos, err: %s", id, err)
		}

		outputs, err := getEnvInfos(step.Outputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (id:%s) output infos, err: %s", id, err)
		}

		stepInfo := models.StepInfoModel{
			ID:          id,
			Version:     version,
			Latest:      stepVersion.LatestAvailableVersion,
			Description: *step.Description,
			StepLib:     collectionURI,
			Source:      *step.SourceCodeURL,
			Inputs:      inputs,
			Outputs:     outputs,
		}

		route, found := stepman.ReadRoute(collectionURI)
		if !found {
			return fmt.Errorf("No route found for collection: %s", collectionURI)
		}
		globalStepInfoPth := stepman.GetStepGlobalInfoPath(route, id)
		if globalStepInfoPth != "" {
			globalInfo, found, err := stepman.ParseGlobalStepInfoYML(globalStepInfoPth)
			if err != nil {
				return fmt.Errorf("Failed to get step (path:%s) output infos, err: %s", globalStepInfoPth, err)
			}

			if found {
				stepInfo.GlobalInfo = globalInfo
			}
		}

		if err := printStepInfo(stepInfo, format, isShort, false); err != nil {
			return fmt.Errorf("Failed to print step info, err: %s", err)
		}
	}

	return nil
}