func()

in internal/provider/apikeys_data_source.go [126:165]


func (d *apiKeysDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
	var state apiKeysDataSourceModel

	apiKeys, err := d.client.GetApiKeys()
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read Devlake ApiKeys",
			err.Error(),
		)
		return
	}

	// Map response body to model
	for _, apiKey := range apiKeys {
		apiKeyState := apiKeysModel{
			ID:           types.Int64Value(int64(apiKey.ID)),
			AllowedPath:  types.StringValue(apiKey.AllowedPath),
			ApiKey:       types.StringValue(apiKey.ApiKey),
			CreatedAt:    types.StringValue(apiKey.CreatedAt),
			Creator:      types.StringValue(apiKey.Creator),
			CreatorEmail: types.StringValue(apiKey.CreatorEmail),
			ExpiredAt:    types.StringValue(apiKey.ExpiredAt),
			Extra:        types.StringValue(apiKey.Extra),
			Name:         types.StringValue(apiKey.Name),
			Type:         types.StringValue(apiKey.Type),
			UpdatedAt:    types.StringValue(apiKey.UpdatedAt),
			Updater:      types.StringValue(apiKey.Updater),
			UpdaterEmail: types.StringValue(apiKey.UpdaterEmail),
		}

		state.ApiKeys = append(state.ApiKeys, apiKeyState)
	}

	// Set state
	diags := resp.State.Set(ctx, &state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}
}